keras_to_tensorflow icon indicating copy to clipboard operation
keras_to_tensorflow copied to clipboard

NameError: name 'yolo_head' is not defined

Open Zengdongxu opened this issue 5 years ago • 14 comments

I trained yolov3 on my own dataset and I got an .h5 file by using model.save() function. Now I wanna use keras_to_tensorflow.py to convert this .h5 file to .pb file, and the error occors like this: Traceback (most recent call last): File "C:/Users/75401/Desktop/python/keras-yolo3-master/model_data/convert.py", line 50, in net_model = load_model(weight_file_path) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\saving.py", line 419, in load_model model = _deserialize_model(f, custom_objects, compile) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\saving.py", line 225, in deserialize_model model = model_from_config(model_config, custom_objects=custom_objects) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\saving.py", line 458, in model_from_config return deserialize(config, custom_objects=custom_objects) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\layers_init.py", line 55, in deserialize printable_module_name='layer') File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\generic_utils.py", line 145, in deserialize_keras_object list(custom_objects.items()))) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\network.py", line 1032, in from_config process_node(layer, node_data) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\network.py", line 991, in process_node layer(unpack_singleton(input_tensors), **kwargs) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\base_layer.py", line 457, in call output = self.call(inputs, **kwargs) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\layers\core.py", line 687, in call return self.function(inputs, **arguments) File "C:\Users\kewin\Desktop\dongxu\keras-yolo3-master\yolo3\model.py", line 375, in yolo_loss grid, raw_pred, pred_xy, pred_wh = yolo_head(yolo_outputs[l], NameError: name 'yolo_head' is not defined

I am sure that the "yolo_head" function is right there in model.py. I got the same error even if I annotate the sentence! That's really absurd!

Zengdongxu avatar Feb 28 '19 05:02 Zengdongxu

遇到同样的问题了,,,,,

nicolesunh avatar May 22 '19 07:05 nicolesunh

me too,have you solved this problem?

tanghaoran666 avatar Dec 01 '19 08:12 tanghaoran666

we also have this a problem

AadeIT avatar Dec 24 '19 08:12 AadeIT

I trained yolov3 on my own dataset and I got an .h5 file by using model.save() function. Now I wanna use keras_to_tensorflow.py to convert this .h5 file to .pb file, and the error occors like this: Traceback (most recent call last): File "C:/Users/75401/Desktop/python/keras-yolo3-master/model_data/convert.py", line 50, in net_model = load_model(weight_file_path) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\saving.py", line 419, in load_model model = deserialize_model(f, custom_objects, compile) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\saving.py", line 225, in deserialize_model model = model_from_config(model_config, custom_objects=custom_objects) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\saving.py", line 458, in model_from_config return deserialize(config, custom_objects=custom_objects) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\layers__init.py", line 55, in deserialize printable_module_name='layer') File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\generic_utils.py", line 145, in deserialize_keras_object list(custom_objects.items()))) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\network.py", line 1032, in from_config process_node(layer, node_data) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\network.py", line 991, in process_node layer(unpack_singleton(input_tensors), **kwargs) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\base_layer.py", line 457, in call output = self.call(inputs, **kwargs) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\layers\core.py", line 687, in call return self.function(inputs, **arguments) File "C:\Users\kewin\Desktop\dongxu\keras-yolo3-master\yolo3\model.py", line 375, in yolo_loss grid, raw_pred, pred_xy, pred_wh = yolo_head(yolo_outputs[l], NameError: name 'yolo_head' is not defined

I am sure that the "yolo_head" function is right there in model.py. I got the same error even if I annotate the sentence! That's really absurd!

have you solved this question?

chenyao96 avatar Jan 17 '20 07:01 chenyao96

The problem is not finding the network structure of yolov3, 

Import py files with network structure

`try: from yolo3.model import yolo_body,yolo_head #######yolo3 is file ,model is py ,yolo_body is function ,this is my network structure from keras.layers import Input #model = keras.models.load_model(input_model_path,compile = False) model = yolo_body(Input(shape = {None,None,3)),9 // 3,10) model.load_weights(input_model_path)#model  = keras。 models.load_model(input_model_path) ------------------ 原始邮件 ------------------ 发件人: "chenyao96"<[email protected]>; 发送时间: 2020年1月17日(星期五) 下午3:28 收件人: "amir-abdi/keras_to_tensorflow"<[email protected]>; 抄送: "1342868324"<[email protected]>;"Comment"<[email protected]>; 主题: Re: [amir-abdi/keras_to_tensorflow] NameError: name 'yolo_head' is not defined (#73)

I trained yolov3 on my own dataset and I got an .h5 file by using model.save() function. Now I wanna use keras_to_tensorflow.py to convert this .h5 file to .pb file, and the error occors like this: Traceback (most recent call last): File "C:/Users/75401/Desktop/python/keras-yolo3-master/model_data/convert.py", line 50, in net_model = load_model(weight_file_path) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\saving.py", line 419, in load_model model = deserialize_model(f, custom_objects, compile) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\saving.py", line 225, in deserialize_model model = model_from_config(model_config, custom_objects=custom_objects) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\saving.py", line 458, in model_from_config return deserialize(config, custom_objects=custom_objects) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\layers__init.py", line 55, in deserialize printable_module_name='layer') File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\generic_utils.py", line 145, in deserialize_keras_object list(custom_objects.items()))) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\network.py", line 1032, in from_config process_node(layer, node_data) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\network.py", line 991, in process_node layer(unpack_singleton(input_tensors), **kwargs) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\base_layer.py", line 457, in call output = self.call(inputs, **kwargs) File "C:\Users\75401\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\layers\core.py", line 687, in call return self.function(inputs, **arguments) File "C:\Users\kewin\Desktop\dongxu\keras-yolo3-master\yolo3\model.py", line 375, in yolo_loss grid, raw_pred, pred_xy, pred_wh = yolo_head(yolo_outputs[l], NameError: name 'yolo_head' is not defined

I am sure that the "yolo_head" function is right there in model.py. I got the same error even if I annotate the sentence! That's really absurd!

have you solved this question?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

AadeIT avatar Jan 17 '20 08:01 AadeIT

请问这个问题解决了吗?

Gannyn avatar Feb 21 '20 16:02 Gannyn

please help me to solve this problem

Using TensorFlow backend. WARNING:tensorflow:From C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Colocations handled automatically by placer. W0311 16:36:04.171489 9120 deprecation.py:323] From C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Colocations handled automatically by placer. 2020-03-11 16:36:04.228873: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 Traceback (most recent call last): File "keras_to_tensorflow.py", line 182, in app.run(main) File "C:\ProgramData\Anaconda3\lib\site-packages\absl\app.py", line 299, in run _run_main(main, args) File "C:\ProgramData\Anaconda3\lib\site-packages\absl\app.py", line 250, in run_main sys.exit(main(argv)) File "keras_to_tensorflow.py", line 128, in main model = load_model(FLAGS.input_model, FLAGS.input_model_json, FLAGS.input_model_yaml) File "keras_to_tensorflow.py", line 63, in load_model model = keras.models.load_model(input_model_path) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\models.py", line 243, in load_model model = model_from_config(model_config, custom_objects=custom_objects) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\models.py", line 317, in model_from_config return layer_module.deserialize(config, custom_objects=custom_objects) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\layers_init.py", line 55, in deserialize printable_module_name='layer') File "C:\ProgramData\Anaconda3\lib\site-packages\keras\utils\generic_utils.py", line 143, in deserialize_keras_object list(custom_objects.items()))) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2517, in from_config process_node(layer, node_data) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2476, in process_node layer(input_tensors, **kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 617, in call output = self.call(inputs, **kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\keras\layers\core.py", line 663, in call return self.function(inputs, **arguments) File "C:\Users\a.kumar2\Desktop\TrainYourOwnYOLO-hiiiiii\TrainYourOwnYOLO\2_Training\src\keras_yolo3\yolo3\model.py", line 440, in yolo_loss grid, raw_pred, pred_xy, pred_wh = yolo_head( NameError: name 'yolo_head' is not defined

birth2507 avatar Mar 11 '20 11:03 birth2507

please help "tf_model.pb", as_text=False) Traceback (most recent call last):

File "", line 10, in model = load_model("keras_model.h5")

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\models.py", line 243, in load_model model = model_from_config(model_config, custom_objects=custom_objects)

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\models.py", line 317, in model_from_config return layer_module.deserialize(config, custom_objects=custom_objects)

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\layers_init_.py", line 55, in deserialize printable_module_name='layer')

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\utils\generic_utils.py", line 143, in deserialize_keras_object list(custom_objects.items())))

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2517, in from_config process_node(layer, node_data)

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2476, in process_node layer(input_tensors, **kwargs)

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 617, in call output = self.call(inputs, **kwargs)

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\layers\core.py", line 663, in call return self.function(inputs, **arguments)

File "C:\Users\a.kumar2\Desktop\TrainYourOwnYOLO-hiiiiii\TrainYourOwnYOLO\2_Training\src\keras_yolo3\yolo3\model.py", line 440, in yolo_loss grid, raw_pred, pred_xy, pred_wh = yolo_head(

NameError: name 'yolo_head' is not defined

import os

from keras import backend as K

This line must be executed before loading Keras model.

K.set_learning_phase(0)

from keras.models import load_model

model = load_model("keras_model.h5") Traceback (most recent call last):

File "", line 1, in model = load_model("keras_model.h5")

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\models.py", line 243, in load_model model = model_from_config(model_config, custom_objects=custom_objects)

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\models.py", line 317, in model_from_config return layer_module.deserialize(config, custom_objects=custom_objects)

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\layers_init_.py", line 55, in deserialize printable_module_name='layer')

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\utils\generic_utils.py", line 143, in deserialize_keras_object list(custom_objects.items())))

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2517, in from_config process_node(layer, node_data)

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 2476, in process_node layer(input_tensors, **kwargs)

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\engine\topology.py", line 617, in call output = self.call(inputs, **kwargs)

File "C:\ProgramData\Anaconda3\lib\site-packages\keras\layers\core.py", line 663, in call return self.function(inputs, **arguments)

File "C:\Users\a.kumar2\Desktop\TrainYourOwnYOLO-hiiiiii\TrainYourOwnYOLO\2_Training\src\keras_yolo3\yolo3\model.py", line 440, in yolo_loss grid, raw_pred, pred_xy, pred_wh = yolo_head(

NameError: name 'yolo_head' is not defined

birth2507 avatar Mar 11 '20 11:03 birth2507

keras_to_tensorflow.py

add: from yolo3.model import yolo_head,yolo_body

around 60 lines:

def load_model(input_model_path, input_json_path=None, input_yaml_path=None):     if not Path(input_model_path).exists():         raise FileNotFoundError(             'Model file {} does not exist.'.format(input_model_path))     try:         print("input_model_path")         try:             model = keras.models.load_model(input_model_path,compile=False)         except:             model = yolo_body(Input(shape=(None, None, 3)), 3, 1)             model.load_weights("ep054-loss16.461-val_loss16.501.h5")         return model     except FileNotFoundError as err:         logging.error('Input mode file (%s) does not exist.', FLAGS.input_model)         raise err

    .......

------------------ 原始邮件 ------------------ 发件人: "birth2507"<[email protected]>; 发送时间: 2020年3月11日(星期三) 晚上7:22 收件人: "amir-abdi/keras_to_tensorflow"<[email protected]>; 抄送: "1342868324"<[email protected]>; "Comment"<[email protected]>; 主题: Re: [amir-abdi/keras_to_tensorflow] NameError: name 'yolo_head' is not defined (#73)

请帮我解决这个问题

使用TensorFlow后端 警告:tensorflow:来自C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ framework \ op_def_library.py:263:colocate_with(来自tensorflow.python.framework.ops)已被弃用,以后将被删除版。 更新说明: 托管服务器自动处理的托管。 W0311 16:36:04.171489 9120 deprecation.py:323]来自C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ tensorflow \ python \ framework \ op_def_library.py:263:colocate_with(来自tensorflow.python.framework.ops)已不推荐使用,并将在以后的版本中删除。 更新说明: 托管服务器自动处理的托管。 2020-03-1116:36:04.228873:我tensorflow / core / platform / cpu_feature_guard.cc:141]您的CPU支持该TensorFlow二进制文件未编译为使用的指令:AVX2 Traceback(最近一次调用): 文件“ keras_to_tensorflow.py”,行182,在 app.run(主) 文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ absl \ app.py”中,行299,在运行 run_main(main,args) 文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ absl \ app.py“,第250行,位于run_main sys.exit(main(argv)) 文件“ keras_to_tensorflow.py”,第128行,在主 模型中= load_model(FLAGS.input_model,FLAGS。 input_model_json,FLAGS.input_model_yaml) 文件“ keras_to_tensorflow.py”,第63行,在load_model中 模型= keras.models.load_model(input_model_path) 文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ keras \ models.py”,第243行,在load_model中, 模型= model_from_config(model_config,custom_objects = custom_objects) 文件“ C :\ ProgramData \ Anaconda3 \ lib \ site-packages \ keras \ models.py“,行317,在model_from_config中 返回layer_module.deserialize(config,custom_objects = custom_objects) 文件” C:\ ProgramData \ Anaconda3 \ lib \ site \ packages \ keras \ layers init .py“,反序列化 printable_module_name ='layer'中的第55行) 文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ keras \ utils \ generic_utils.py”,反序列化,第143行,在deserialize_keras_object 列表中( custom_objects.items())) 在from_config进程节点 (层,node_data)中的 文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ keras \ engine \ topology.py”,第2517行,文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ keras \ engine \ topology.py”,行2476,在process_node 层(input_tensors,** kwargs)中, 文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ keras \ engine \ topology.py”,行617,在呼叫 输出= self.call(输入,** kwargs) 文件“ C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ keras \ layers \ core.py”,呼叫 返回self.function(输入,* *参数) 文件“ C:\ Users \ a.kumar2 \ Desktop \ TrainYourOwnYOLO-hiiiiii \ TrainYourOwnYOLO \ 2_Training \ src \ keras_yolo3 \ yolo3 \ model.py”,第440行,位于yolo_loss 网格中,raw_pred,pred_xy,pred_wh = yolo_head( NameError:名称“ yolo_head”未定义

— 因为评论,您收到此消息。 直接回复此电子邮件,在GitHub上查看,或取消订阅。

AadeIT avatar Mar 11 '20 11:03 AadeIT

keras_to_tensorflow.py

add: from yolo3.model import yolo_head,yolo_body

around 60 lines:

def load_model(input_model_path, input_json_path=None, input_yaml_path=None):     if not Path(input_model_path).exists():         raise FileNotFoundError(             'Model file {} does not exist.'.format(input_model_path))     try:         print("input_model_path")         try:             model = keras.models.load_model(input_model_path,compile=False)         except:             model = yolo_body(Input(shape=(None, None, 3)), 3, 1)             model.load_weights("ep054-loss16.461-val_loss16.501.h5")         return model     except FileNotFoundError as err:         logging.error('Input mode file (%s) does not exist.', FLAGS.input_model)         raise err

    .......

------------------ 原始邮件 ------------------ 发件人: "Gannyn"<[email protected]>; 发送时间: 2020年2月22日(星期六) 凌晨0:55 收件人: "amir-abdi/keras_to_tensorflow"<[email protected]>; 抄送: "1342868324"<[email protected]>; "Comment"<[email protected]>; 主题: Re: [amir-abdi/keras_to_tensorflow] NameError: name 'yolo_head' is not defined (#73)

请问这个问题解决了吗?

— 因为评论,您收到此消息。 直接回复此电子邮件,在GitHub上查看,或取消订阅。

AadeIT avatar Mar 11 '20 11:03 AadeIT

keras_to_tensorflow.py

add: from yolo3.model import yolo_head,yolo_body

around 60 lines:

def load_model(input_model_path, input_json_path=None, input_yaml_path=None):     if not Path(input_model_path).exists():         raise FileNotFoundError(             'Model file {} does not exist.'.format(input_model_path))     try:         print("input_model_path")         try:             model = keras.models.load_model(input_model_path,compile=False)         except:             model = yolo_body(Input(shape=(None, None, 3)), 3, 1)             model.load_weights("ep054-loss16.461-val_loss16.501.h5")         return model     except FileNotFoundError as err:         logging.error('Input mode file (%s) does not exist.', FLAGS.input_model)         raise err

    .......

------------------ 原始邮件 ------------------ 发件人: "Gannyn"<[email protected]>; 发送时间: 2020年2月22日(星期六) 凌晨0:55 收件人: "amir-abdi/keras_to_tensorflow"<[email protected]>; 抄送: "1342868324"<[email protected]>; "Comment"<[email protected]>; 主题: Re: [amir-abdi/keras_to_tensorflow] NameError: name 'yolo_head' is not defined (#73)

请问这个问题解决了吗?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

AadeIT avatar Mar 11 '20 11:03 AadeIT

here, yolo_head method is already defined in model.py file, still this error is coming. please help me out from this.

birth2507 avatar Mar 11 '20 13:03 birth2507

请问你们解决了 还是遇到了这个问题。

zlszhonglongshen avatar Jun 10 '20 07:06 zlszhonglongshen

遇到同样的问题了,,,,,

解决了吗

caoyuanjie1996 avatar Oct 20 '20 11:10 caoyuanjie1996