bojone / bert4keras

keras implement of transformers for humans
https://kexue.fm/archives/6915
Apache License 2.0
5.36k stars 927 forks source link

flask 部署运行生成句向量时,多进程报错,单进程没问题 #153

Open tianshangwuyun opened 4 years ago

tianshangwuyun commented 4 years ago

tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'Transformer-11-MultiHeadSelfAttention-Norm/mul/ReadVariableOp/resource' with dtype resource [[node Transformer-11-MultiHeadSelfAttention-Norm/mul/ReadVariableOp/resource (defined at /opt/python_virtualenv/.env/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py:1751) ]] [Op:__inference_keras_scratch_graph_17335]

liprais commented 4 years ago

hitter this problem also, googled a bit, saw a few solutions like this : https://stackoverflow.com/questions/47115946/tensor-is-not-an-element-of-this-graph wonder how to apply it to bert4keras here

liprais commented 4 years ago

I think I've figured it out. First you need to call model.save to save the model ,then load it using Keras.load_model,then solutions in https://stackoverflow.com/questions/47115946/tensor-is-not-an-element-of-this-graph can be applied.

bojone commented 4 years ago

说明常规的多进程不能直接用于深度学习模型的部署。至于不常规的方法是怎样,我也不清楚。