如何在进程之间共享模型参数?有两个过程,一个用于训练模型,另一个用于预测。
import tensorflow as tf
import multiprocessing
# Process used for training of model
def train_run(model_variables):
model_variables[:] = model.variables
# Process used for predicting
def predict_run(model_variables):
print(model_variables[:])
model = tf.keras.applications.MobileNet()
model_variables = multiprocessing.Array(tf.Variable, model.variables)
p1 = multiprocessing.Process(target=train_run, args=(model_variables,))
p2 = multiprocessing.Process(target=predict_run, args=(model_variables,))
暂无答案!
目前还没有任何答案,快来回答吧!