我有一个在 tensorflow 1.15 中训练过的预训练 tensorflow 模型,现在我正试图用预训练的 ms-coco 对象检测模型替换它,ms-coco 运行没有任何问题,但只要我尝试替换所需的模型(我确实更新了标签映射字典)但我仍然面临以下错误。
File "Object_Detector.py", line 43, in __init__
od_graph_def.ParseFromString(serialized_graph)
File "C:\Python\lib\site-packages\google\protobuf\message.py", line 185, in ParseFromString
self.MergeFromString(serialized)
File "C:\Python\lib\site-packages\google\protobuf\internal\python_message.py", line 1083, in MergeFromString
if self._InternalParse(serialized, 0, length) != length:
File "C:\Python\lib\site-packages\google\protobuf\internal\python_message.py", line 1120, in InternalParse
pos = field_decoder(buffer, new_pos, end, self, field_dict)
File "C:\Python\lib\site-packages\google\protobuf\internal\decoder.py", line 633, in DecodeField
if value._InternalParse(buffer, pos, new_pos) != new_pos:
File "C:\Python\lib\site-packages\google\protobuf\internal\python_message.py", line 1120, in InternalParse
pos = field_decoder(buffer, new_pos, end, self, field_dict)
File "C:\Python\lib\site-packages\google\protobuf\internal\decoder.py", line 612, in DecodeRepeatedField
if value.add()._InternalParse(buffer, pos, new_pos) != new_pos:
File "C:\Python\lib\site-packages\google\protobuf\internal\python_message.py", line 1120, in InternalParse
pos = field_decoder(buffer, new_pos, end, self, field_dict)
File "C:\Python\lib\site-packages\google\protobuf\internal\decoder.py", line 743, in DecodeMap
if submsg._InternalParse(buffer, pos, new_pos) != new_pos:
File "C:\Python\lib\site-packages\google\protobuf\internal\python_message.py", line 1109, in InternalParse
new_pos = local_SkipField(buffer, new_pos, end, tag_bytes)
File "C:\Python\lib\site-packages\google\protobuf\internal\decoder.py", line 850, in SkipField
return WIRETYPE_TO_SKIPPER[wire_type](buffer, pos, end)
File "C:\Python\lib\site-packages\google\protobuf\internal\decoder.py", line 799, in _SkipGroup
new_pos = SkipField(buffer, pos, end, tag_bytes)
File "C:\Python\lib\site-packages\google\protobuf\internal\decoder.py", line 850, in SkipField
return WIRETYPE_TO_SKIPPER[wire_type](buffer, pos, end)
File "C:\Python\lib\site-packages\google\protobuf\internal\decoder.py", line 814, in _SkipFixed32
raise _DecodeError('Truncated message.')
google.protobuf.message.DecodeError: Truncated message.
这是代码
def __init__(self):
self.Objkt_boxes = []
os.chdir(cwd)
detect_model_name = 'Pretrained_Model_SSD'
PATH_TO_CKPT = detect_model_name + '/saved_model.pb' # saved_model.pb is to be replaced with frozen_inference_graph.pb
self.detection_graph = tf.Graph()
with self.detection_graph.as_default():
od_graph_def = tf.compat.v1.GraphDef()
with tf.compat.v2.io.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')
self.sess = tf.Session(graph=self.detection_graph)
self.image_tensor = self.detection_graph.get_tensor_by_name('image_tensor:0')
self.boxes = self.detection_graph.get_tensor_by_name('detection_boxes:0')
self.scores =self.detection_graph.get_tensor_by_name('detection_scores:0')
self.classes = self.detection_graph.get_tensor_by_name('detection_classes:0')
self.num_detections =self.detection_graph.get_tensor_by_name('num_detections:0')
saved_model.pb 的 label_map 文件
item {
id: 1
name: 'car'
}
item {
id: 2
name: 'pedestrian'
}
item {
id: 3
name: 'trafficLight-GreenLeft'
}
item {
id: 4
name: 'trafficLight-Green'
}
item {
id: 5
name: 'trafficLight-Red'
}
item {
id: 6
name: 'trafficLight-RedLeft'
}
item {
id: 7
name: 'trafficLight'
}
item {
id: 8
name: 'truck'
}
item {
id: 9
name: 'biker'
}
item {
id: 10
name: 'trafficLight-Yellow'
}
item {
id: 11
name: 'trafficLight-YellowLeft'
}
我怎样才能让这个模型与 tf2.7 一起工作?