如何训练输出大小可变的目标检测模型?
How to train an object detection model with variable output size?
假设我们正在处理以下数据集:https://www.kaggle.com/jutrera/stanford-car-dataset-by-classes-folder.
我想创建目标检测模型,输入为不同形状的图像,输出也为可变形状的图像,但输出图像是从相应的输入图像(因此可变形状)中裁剪的汽车。如何使用 Keras 实现此目的。我知道图像分割和自动编码器的过程,但由于输入和输出的大小是可变的,确切的过程似乎很遥远。请帮助我。谢谢。
您可以使用 Tensorflow 对象检测 API 并使用输出边界框裁剪输入图像。请注意,输入图像将调整大小,但您可以使用输出边界框裁剪原始图像。
detections = detect(input_tensor)
bounding_boxes = detections['detection_boxes'].numpy()
confidences = detections['detection_scores'].numpy()
for bbox, conf, path in zip(bounding_boxes, confidences, image_path):
if len(bbox):
image_orig = load_orig(path) # load original size image
height, width, channels = image_orig.shape
y_min, x_min, y_max, x_max = bbox
y_min_absolute = int(y_min * height)
x_min_absolute = int(x_min * width)
y_max_absolute = int(y_max * height)
x_max_absolute = int(x_max * width)
cropped_image = tf.image.crop_to_bounding_box(
image=image_orig,
offset_height=y_min_absolute,
offset_width=x_min_absolute,
target_height=y_max_absolute - y_min_absolute,
target_width=x_max_absolute - x_min_absolute)
cropped_images.append(tf.cast(cropped_image, tf.uint8))
假设我们正在处理以下数据集:https://www.kaggle.com/jutrera/stanford-car-dataset-by-classes-folder.
我想创建目标检测模型,输入为不同形状的图像,输出也为可变形状的图像,但输出图像是从相应的输入图像(因此可变形状)中裁剪的汽车。如何使用 Keras 实现此目的。我知道图像分割和自动编码器的过程,但由于输入和输出的大小是可变的,确切的过程似乎很遥远。请帮助我。谢谢。
您可以使用 Tensorflow 对象检测 API 并使用输出边界框裁剪输入图像。请注意,输入图像将调整大小,但您可以使用输出边界框裁剪原始图像。
detections = detect(input_tensor)
bounding_boxes = detections['detection_boxes'].numpy()
confidences = detections['detection_scores'].numpy()
for bbox, conf, path in zip(bounding_boxes, confidences, image_path):
if len(bbox):
image_orig = load_orig(path) # load original size image
height, width, channels = image_orig.shape
y_min, x_min, y_max, x_max = bbox
y_min_absolute = int(y_min * height)
x_min_absolute = int(x_min * width)
y_max_absolute = int(y_max * height)
x_max_absolute = int(x_max * width)
cropped_image = tf.image.crop_to_bounding_box(
image=image_orig,
offset_height=y_min_absolute,
offset_width=x_min_absolute,
target_height=y_max_absolute - y_min_absolute,
target_width=x_max_absolute - x_min_absolute)
cropped_images.append(tf.cast(cropped_image, tf.uint8))