我想使用多处理程序加载3个keras模型,但无法从函数中得到任何结果。
我的代码
import tensorflow as tf
import multiprocessing
from multiprocessing import Process, Queue
def import_model_0(ModelPath, queue):
model = tf.keras.models.load_model(ModelPath)
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
print('model 0 is ' ,model)
queue.put([model, '0'])
if __name__ == "__main__":
queue = Queue()
model_0 = Process(target=import_model_0, args=(model_path_set[0], queue, ))
model_1 = Process(target=import_model_1, args=(model_path_set[1], queue, ))
model_2 = Process(target=import_model_2, args=(model_path_set[2], queue, ))
model_0.start()
model_1.start()
model_2.start()
model_0.join()
model_1.join()
model_2.join()
print('Using time ', time.time()-ts, 'sec')
if queue.empty() is False:
get_model = queue.get()
print('recieve')
if get_model[1] == '0':
get_model_0 = get_model[0]
print(get_model_0)
elif get_model[1] == '1':
get_model_1 = get_model[0]
print(get_model_1)
elif get_model[1] == '2':
get_model_2 = get_model[0]
print(get_model_2)
当我的代码显示get_model_0,get_model_1,get_model_2时,它什么也不显示