【问题标题】:How to train an object detection model with variable output size?如何训练具有可变输出大小的对象检测模型?
【发布时间】:2021-09-05 03:48:52
【问题描述】:

假设我们正在处理以下数据集:https://www.kaggle.com/jutrera/stanford-car-dataset-by-classes-folder

我想创建对象检测模型,输入为不同形状的图像,输出也为可变形状的图像,但输出图像是从相应的输入图像中裁剪出来的汽车(因此是可变形状的)。如何使用 Keras 实现这一点。我知道图像分割和自动编码器的过程,但由于输入和输出的大小是可变的,确切的过程似乎很遥远。请帮助我。谢谢。

【问题讨论】:

    标签: image tensorflow keras deep-learning computer-vision


    【解决方案1】:

    您可以使用 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))
    

    【讨论】:

      猜你喜欢
      • 2018-02-20
      • 2017-10-25
      • 2020-12-22
      • 1970-01-01
      • 2019-06-21
      • 2019-04-05
      • 1970-01-01
      • 2020-01-15
      • 2021-11-27
      相关资源
      最近更新 更多