image - 如何训练具有可变输出大小的对象检测模型?
问题描述
假设我们正在处理以下数据集: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))
推荐阅读
- mongodb - Mongoose 模式可选,带验证
- c# - Dependencies of packages conflicts with Newtonsoft.Json
- boto3 - errorMessage“: ”“海王星”对象没有属性“stop_db_cluster”
- javascript - node js webpack对重建后未在chrome中显示的页面所做的更改
- jquery - Codeigniter 上的 PayPal 付款
- javascript - Failed to execute 'addEventListener' on 'EventTarget'
- java - Getting StackOverflow in OneToMany and ManyToMany mappings
- html - 相对位置使 div 重叠
- python - Mypy fails to infer enums being created from a list variable
- r - 在 Cypress 中使用 js 闪亮事件