TF2对象检测微调-更改输入图像大小?

问题描述

我正在尝试从TensorFlow 2 Model Zoo中微调经过训练的模型,例如“ EfficientDet D0 512x512”,该模型将输出同一图像中多个对象的边界框。

但是我的KITTI数据集图像约为1200x400。 因此,将1200x400调整为512x512的大小非常尴尬,并且会导致大量信息丢失。由于正方形的纵横比,使用其他尺寸(例如800x800或1024x1024)同样存在问题。

还没有那么有用的issue线程。

每个人都告诉您在pipeline.config文件中将图像调整为较小的尺寸,如下所示:

image_resizer {
  fixed_shape_resizer {
    height: 300
    width: 300
  }
}

image_resizer {
  keep_aspect_ratio_resizer {
    min_dimension: 300
    max_dimension: 300
  }
}

但这不是我想要做的事。

在这种情况下,Keras非常方便,因为您可以在加载预训练模型和模型时简单地提及输入张量大小。

model = VGG16(weights="imagenet",include_top=False,input_tensor=Input(shape=(224,224,3)))

那么,有没有办法改变TF2模型Zoo文件的输入张量形状?

谢谢!

解决方法

您是否尝试过在TFHub上使用网络版本?该版本没有指定的输入大小(它拍摄的图像大小为(1,None,None,3))。然后,您可以在自己的图像数据集上使用经过预训练的网络,无论它们的大小如何。

image = tf.io.decode_jpeg(tf.io.read_file(path))
image = tf.reshape(image,shape=(1,1200,400,3))
detector = hub.load("https://tfhub.dev/tensorflow/efficientdet/d0/1")
detector_output = detector(image)

EfficientDet D0在TF集线器的https://tfhub.dev/tensorflow/efficientdet/d0/1上可用。