如何从对象检测API内置的模型中提取简单的对象检测Keras模型

时间:2019-11-03 13:33:10

标签: python tensorflow keras object-detection-api

在TensorFlow的对象检测API中,可以在配置文件中指定一个keras模型(例如'ssd_mobilenet_v2_keras'),这样,构建的feature extractorbox predictor将是tf。 keras模型。我想做的就是使用这些创建一个简单的OD Keras模型。这意味着我将能够定义特征提取器,框预测器,然后执行以下操作:

def keras_model(model, shape):
    input = tf.keras.Input(shape=shape)
    feature_maps = model._feature_extractor(input)
    predictions = model._box_predictor(feature_maps)
    return tf.keras.Model(inputs=input, outputs=predictions)

使用model构建model_builder.build(model_config)时(将调用this)。

但是,当我尝试这样做时,在功能提取命令上出现以下异常:

    feature_maps = model._feature_extractor(input)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/engine/base_layer.py", line 584, in __call__
    inputs, outputs, args, kwargs)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/engine/base_layer.py", line 1416, in _set_connectivity_metadata_
    input_tensors=inputs, output_tensors=outputs, arguments=kwargs)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/engine/base_layer.py", line 1524, in _add_inbound_node
    arguments=arguments)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/engine/base_layer.py", line 1732, in __init__
    self.output_shapes = [backend.int_shape(x) for x in output_tensors]
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/engine/base_layer.py", line 1732, in <listcomp>
    self.output_shapes = [backend.int_shape(x) for x in output_tensors]
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/keras/backend.py", line 951, in int_shape
    shape = x.shape
AttributeError: 'odict_values' object has no attribute 'shape'

任何想法是什么问题,或者是否有更简单的方法来提取对象检测Keras模型?

谢谢!

0 个答案:

没有答案