david8862 / keras-YOLOv3-model-set

end-to-end YOLOv4/v3/v2 object detection pipeline, implemented on tf.keras with different technologies
MIT License
639 stars 220 forks source link

NameError: name 'yolo3_head' is not defined #65

Open hitxuhao opened 4 years ago

hitxuhao commented 4 years ago

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

david8862 commented 4 years ago

you need to follow model-dump and tensorflow-model-convert for .pb model convert

hitxuhao commented 4 years ago

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 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 109, in load_input_model raise wrong_file_err 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 165, in load_model_from_hdf5 raise ValueError('No model found in config file.') ValueError: No model found in config file.

my tf is 2.X

hitxuhao commented 4 years ago

@david8862

hitxuhao commented 4 years ago

image

hitxuhao commented 4 years ago

this my model.h5 it is not empty

david8862 commented 4 years ago

.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

hitxuhao commented 4 years ago

image 2.0.0

hitxuhao commented 4 years ago

@david8862

hitxuhao commented 4 years ago

What's your TF version? @david8862

david8862 commented 4 years ago

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

hitxuhao commented 4 years ago

@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 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 179, in main converted_output_node_names) File "/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py", line 324, in new_func return func(*args, *kwargs) File "/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/graph_util_impl.py", line 359, in convert_variables_to_constants inference_graph = extract_sub_graph(input_graph_def, output_node_names) File "/opt/conda/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py", line 324, in new_func return func(args, **kwargs) File "/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/graph_util_impl.py", line 205, in extract_sub_graph _assert_nodes_are_present(name_to_node, dest_nodes) File "/opt/conda/lib/python3.7/site-packages/tensorflow/python/framework/graph_util_impl.py", line 160, in _assert_nodes_are_present assert d in name_to_node, "%s is not in graph" % d AssertionError: conv2d_3/Identity is not in graph

david8862 commented 4 years ago

@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