首页 > 解决方案 > tensorflow TypeError:ParseFromString() 缺少 1 个必需的位置参数:“序列化”

问题描述

这是我第一次使用张量流我想尝试我在互联网上找到的验证码求解器但我收到了一个错误链接教程https://pylessons.com/TensorFlow-CAPTCHA-final-detection/

TypeError:ParseFromString() 缺少 1 个必需的位置参数:“序列化”

这是我的代码

# Load a (frozen) Tensorflow model into memory.
label_map = label_map_util.load_labelmap(PATH_TO_LABELS)
categories = label_map_util.convert_label_map_to_categories(label_map, max_num_classes=NUM_CLASSES, use_display_name=True)
category_index = label_map_util.create_category_index(categories)

detection_graph = tf.Graph()
with detection_graph.as_default():
    od_graph_def = tf.GraphDef
    with tf.gfile.GFile(PATH_TO_FROZEN_GRAPH, 'rb') as fid:
        serialized_graph = fid.read()
        od_graph_def.ParseFromString(serialized_graph)
        tf.import_graph_def(od_graph_def, name='')

标签: tensorflow

解决方案


如果您使用的是 tensorflow 版本 >= 2.0,那么上面的代码将不起作用。以下是适用于 tensorflow 版本 > 2.0 的更新代码

 with detection_graph.as_default():
        od_graph_def = tf.compat.v1.GraphDef()
        with tf.compat.v1.gfile.GFile(PATH_TO_FROZEN_GRAPH, 'rb') as fid:
            serialized_graph = fid.read()
            od_graph_def.ParseFromString(serialized_graph)
            tf.compat.v1.import_graph_def(od_graph_def, name='')

推荐阅读