我正在尝试在训练步骤结束时使用 model.save(而不是仅检查点)保存完整的模型,同时使用官方的视网膜对象检测 API。但是,调用 model.save 时出现以下错误:
I0414 17:18:52.661234 140283524683584 distributed_executor.py:49] Saving model as TF checkpoint: /home/ubuntu/ankur/models/official/vision/detection/ModelDIr/ctl_step_5.ckpt-1
WARNING:tensorflow:From /home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/ops/resource_variable_ops.py:1786: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
W0414 17:19:26.865248 140283524683584 deprecation.py:506] From /home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/ops/resource_variable_ops.py:1786: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
INFO:tensorflow:Assets written to: /home/ubuntu/ankur/models/official/vision/detection/saved_model/test_model/assets
I0414 17:19:33.264274 140283524683584 builder_impl.py:775] Assets written to: /home/ubuntu/ankur/models/official/vision/detection/saved_model/test_model/assets
Traceback (most recent call last):
File "main.py", line 235, in <module>
app.run(main)
File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/absl/app.py", line 299, in run
_run_main(main, args)
File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/absl/app.py", line 250, in _run_main
sys.exit(main(argv))
File "main.py", line 230, in main
run()
File "main.py", line 224, in run
callbacks=callbacks)
File "main.py", line 117, in run_executor
save_config=True)
File "/home/ubuntu/ankur/models/official/modeling/training/distributed_executor.py", line 480, in train
model.save('/home/ubuntu/ankur/models/official/vision/detection/saved_model/test_model')
File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/network.py", line 1008, in save
signatures, options)
File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/saving/save.py", line 115, in save_model
signatures, options)
File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/keras/saving/saved_model/save.py", line 78, in save
save_lib.save(model, filepath, signatures, options)
File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/saved_model/save.py", line 923, in save
saveable_view, asset_info.asset_index)
File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/saved_model/save.py", line 647, in _serialize_object_graph
concrete_function, saveable_view.captured_tensor_node_ids, coder)
File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/saved_model/function_serialization.py", line 70, in serialize_concrete_function
coder.encode_structure(structured_outputs))
File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/saved_model/nested_structure_coder.py", line 95, in encode_structure
return self._map_structure(nested_structure, self._get_encoders())
File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/saved_model/nested_structure_coder.py", line 79, in _map_structure
return do(pyobj, recursion_fn)
File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/saved_model/nested_structure_coder.py", line 203, in do_encode
encoded_dict.dict_value.fields[key].CopyFrom(encode_fn(value))
File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/saved_model/nested_structure_coder.py", line 79, in _map_structure
return do(pyobj, recursion_fn)
File "/home/ubuntu/anaconda3/envs/tensorflow2_p36/lib/python3.6/site-packages/tensorflow_core/python/saved_model/nested_structure_coder.py", line 203, in do_encode
encoded_dict.dict_value.fields[key].CopyFrom(encode_fn(value))
TypeError: 3 has type int, but expected one of: bytes, unicode
为了保存完整模型,我所做的唯一更改是在分布式执行器的训练结束时添加命令 model.save('/home/ubuntu/ankur/models/official/vision/detection/saved_model/test_model') .py 在路径 ~/models/official/modeling/training 中找到。请提出可能是什么问题。
TensorFlow 版本 - 2.1 GIThub链接