Open hitxuhao opened 4 years ago
you need to follow model-dump and tensorflow-model-convert for .pb model convert
s1:
python yolo.py --model_type=yolo3_mobilenet_lite --weights_path=logs/000/trained_final.h5 --anchors_path=configs/yolo3_anchors.txt --classes_path=configs/deepfashion2_classes.txt --model_image_size=416x416 --dump_model --output_model_file=model.h5
i got model.h5
s2:
python tools/keras_to_tensorflow.py --input_model=./model.h5 --output_model=./mymodel.pb
error:
E0612 02:51:55.137194 140572317226816 keras_to_tensorflow.py:98] Input file specified only holds the weights, and not the model definition. Save the model using model.save(filename.h5) which will contain the network architecture as well as its weights. If the model is saved using the model.save_weights(filename) function, either input_model_json or input_model_yaml flags should be set to to import the network architecture prior to loading the weights.
Check the keras documentation for more details (https://keras.io/getting-started/faq/)
Traceback (most recent call last):
File "tools/keras_to_tensorflow.py", line 187, in
my tf is 2.X
@david8862
this my model.h5 it is not empty
.pb convert function could only be used under TF 1.x since pb format has been deprecated in TF 2... PS. seems all your model.save() only save weights but not include model structure. What's your TF version? I haven't met such case before
2.0.0
@david8862
What's your TF version? @david8862
I've ever used 1.14/1.15/2.2 and all of them works fine. Maybe you can try netron to visualize the .h5 content and check with tensorflow/keras teams if it's really a problem
@david8862
Hi i change my tf version to 2.2.0
oppoer@falcon:keras-YOLOv3-model_std$ python tools/keras_to_tensorflow.py --input_model=./model.h5 --output_model=./mymodel.pb
.......................................
Traceback (most recent call last):
File "tools/keras_to_tensorflow.py", line 188, in
@hitxuhao When changing TF version, it's better for you to use model-dump to re-generate inference model again, and then do the pb convert
i train my data ,and get the result "trained_final.h5" .i use tools/keras_to_tensorflow.py to translate h5 to pb . failed errer is followed: Traceback (most recent call last): File "tools/keras_to_tensorflow.py", line 187, in
app.run(main)
File "/opt/conda/lib/python3.7/site-packages/absl/app.py", line 299, in run
_run_main(main, args)
File "/opt/conda/lib/python3.7/site-packages/absl/app.py", line 250, in _run_main
sys.exit(main(argv))
File "tools/keras_to_tensorflow.py", line 133, in main
model = load_input_model(FLAGS.input_model, FLAGS.input_model_json, FLAGS.input_model_yaml, custom_objects=custom_object_dict)
File "tools/keras_to_tensorflow.py", line 66, in load_input_model
model = load_model(input_model_path, custom_objects=custom_objects)
File "/opt/conda/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/save.py", line 146, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
File "/opt/conda/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/hdf5_format.py", line 168, in load_model_from_hdf5
custom_objects=custom_objects)
File "/opt/conda/lib/python3.7/site-packages/tensorflow_core/python/keras/saving/model_config.py", line 55, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File "/opt/conda/lib/python3.7/site-packages/tensorflow_core/python/keras/layers/serialization.py", line 102, in deserialize
printable_module_name='layer')
File "/opt/conda/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/generic_utils.py", line 191, in deserialize_keras_object
list(custom_objects.items())))
File "/opt/conda/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/network.py", line 906, in from_config
config, custom_objects)
File "/opt/conda/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/network.py", line 1852, in reconstruct_from_config
process_node(layer, node_data)
File "/opt/conda/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/network.py", line 1799, in process_node
output_tensors = layer(input_tensors, *kwargs)
File "/opt/conda/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 842, in call
outputs = call_fn(cast_inputs, args, kwargs)
File "/opt/conda/lib/python3.7/site-packages/tensorflow_core/python/keras/layers/core.py", line 795, in call
return self.function(inputs, arguments)
File "/home/notebook/data/personal/keras-YOLOv3-model-set-master/yolo3/loss.py", line 284, in yolo3_loss
grid, raw_pred, pred_xy, pred_wh = yolo3_head(yolo_outputs[l],
NameError: name 'yolo3_head' is not defined