google.protobuf.message.DecodeError: Error parsing message with type 'tensorflow.GraphDef'

google.protobuf.message.DecodeError: Error parsing message with type 'tensorflow.GraphDef'

我正在训练模型并保存它,现在我正在尝试加载但无法加载。我在之前的post中也看到过,但是有些参考链接不起作用或者我尝试了一些方法,仍然无法解决问题。

代码片段:

#load model

with tf.io.gfile.GFile(args.model, "rb") as f:
    graph_def = tf.compat.v1.GraphDef()
    graph_def.ParseFromString(f.read())

# with tf.Graph().as_default() as graph:
generated_image_1, generated_image_2, generated_image_3, = tf.graph_util.import_graph_def(
        graph_def, 
        input_map={'input_image' : input_tensor, 'short_edge_1' : short_edge_1, 'short_edge_2' : short_edge_2, 'short_edge_3' : short_edge_3}, 
        return_elements=['style_subnet/conv-block/resize_conv_1/output:0', 'enhance_subnet/resize_conv_1/output:0', 'refine_subnet/resize_conv_1/output:0'],  
        producer_op_list=None
    )

错误

Traceback (most recent call last):

  File "stylize.py", line 97, in <module>
    main()
  File "stylize.py", line 57, in main
    graph_def.ParseFromString(f.read())
google.protobuf.message.DecodeError: Error parsing message with type 'tensorflow.GraphDef'

注意:如果需要有关此的更多信息,一定会 post 将其添加到此处。让我知道

BG:我在测试代码时遇到错误。 就我而言,它是在 freeze.py 的帮助下解决的,并在培训文件中进行了一些修改。 我在搜索查询时发现了一些其他有用的链接。

Link 2