我已经为keras编写了一个自定义生成器 并且有这个功能: 它运行了一到两次迭代,但不再说 此行上的数组索引太多
label = label[y:(y + dy), x:(x + dx)]
请注意,所有图像和形状都具有相同的尺寸!
def random_crop(image, edge, label, random_crop_size=(800, 1600)):
# Note: image_data_format is 'channel_last'
assert image.shape[2] == 3
height, width = image.shape[0], image.shape[1]
dy, dx = random_crop_size
x = np.random.randint(0, width - dx + 1)
y = np.random.randint(0, height - dy + 1)
image = image[y:(y + dy), x:(x + dx), :]
print(label.shape)
print(y,y+dy)
print(x,x+dx)
label = label[y:(y + dy), x:(x + dx)]
if edge is not None:
edge = edge[y:(y + dy), x:(x + dx)]
imagePlusEdge = np.zeros((random_crop_size[0], random_crop_size[1], 4))
imagePlusEdge[:, :, :3] = image
imagePlusEdge[:, :, -1] = edge[:, :]
return imagePlusEdge, label
return image, label
答案 0 :(得分:0)
如果您的label
是2D(即标签的形状不允许您通过第三条索引)或尺寸/形状小于image
,则会出现该错误。