1.图像增强copy_paste:
输入原图JPEGImages+对应掩码图SegmentationClass

可以提前可视化一下,看是否有问题(可能出在图像标注的时候出现别的未知类别)
import matplotlib.pyplot as plt
from matplotlib import gridspec
import numpy as np
import cv2
import os
import warnings
warnings.filterwarnings("ignore")
import shutil
#
#
def create_pascal_label_colormap():
colormap = np.zeros((256, 3), dtype=int)
ind = np.arange(256, dtype=int)
for shift in reversed(range(8)):
for channel in range(3):
colormap[:, channel] |= ((ind >> channel) & 1) << shift
ind >>= 3
return colormap
def label_to_color_image(label):
if label.ndim != 2:
raise ValueError('Expect 2-D input label')
colormap = create_pascal_label_colormap()
if np.max(label) >= len(colormap):
raise ValueError('label value too large.')
return colormap[label]
def vis_segmentation(image, seg_map):
"""
输入图片和分割 mask 的可视化.
"""
plt.figure(figsize=(15, 5))
grid_spec = gridspec.GridSpec(1, 4, width_ratios=[6, 6, 6, 1])
plt.subplot(grid_spec[0])
plt.imshow(image)
plt.axis('off')
plt.title('input image')
plt.subplot(grid_spec[1])
seg_image = label_to_color_image(seg_map).astype(np.uint8)
plt.imshow(seg_image)
plt.axis('off')
plt.title('segmentation map')
plt.subplot(grid_spec[2])
plt.imshow(image)
plt.imshow(seg_image, alpha=0.5)
plt.axis('off')
plt.title('segmentation overlay')
unique_labels = np.unique(seg_map)
ax = plt.subplot(grid_spec[3])
plt.imshow(FULL_COLOR_MAP[unique_labels].astype(np.uint8), interpolation='nearest')
ax.yaxis.tick_right()
plt.yticks(range(len(unique_labels)), LABEL_NAMES[unique_labels])
plt.xticks([], [])
ax.tick_params(width=0.0)
plt.grid('off')
# plt.imsave('G:\\1\\' + image)
# plt.show()
LABEL_NAMES = np.asarray(['background0', 'paper1','pe2','pet3','glass4','metal5','foam6','battery7','lamp8','textile9','plant10','kitchen11']) # 假设只有两类
FULL_LABEL_MAP = np.arange(len(LABEL_NAMES)).reshape(len(LABEL_NAMES),

本文介绍了深度学习中图像分割的数据增强技术,包括copy_paste和mosaic方法。通过copy_paste,将多张图像的掩码目标物体随机合并,以增加训练样本的多样性。同时,展示了使用mosaic技术进行数据增强后的效果,并提供了代码实现和可视化结果的展示,以确保数据增强过程中无错误。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



