【发布时间】:2016-07-14 16:21:22
【问题描述】:
我正在做一些非常基本的图像增强来训练卷积网络,而且速度非常慢。我想知道是否有人对在 python 中打开、翻转和关闭图像的更快方法有建议?它有大约 100,000 张图像要处理,需要几个小时。
print 'Example of image in train.txt: ' + image_file[0]
print 'Example of annotation in train.txt: ' + annot_file[0]
train_file.close()
for i in range(len(image_file)):
temp_image = imread(image_file[i])
temp_annot = imread(annot_file[i])
temp_image_name = image_file[i][:-4] + '_augmented_lrflip.png'
temp_annot_name = annot_file[i][:-4] + '_augmented_lrflip.png'
imsave(temp_image_name,np.fliplr(temp_image))
imsave(temp_annot_name,np.fliplr(temp_annot))
image_file.append(temp_image_name)
annot_file.append(temp_annot_name)
temp_image_name = image_file[i][:-4] + '_augmented_lr_ud_flip.png'
temp_annot_name = annot_file[i][:-4] + '_augmented_lr_ud_flip.png'
imsave(temp_image_name,np.fliplr(np.flipud(temp_image)))
imsave(temp_annot_name,np.fliplr(np.flipud(temp_annot)))
image_file.append(temp_image_name)
annot_file.append(temp_annot_name)
temp_image_name = image_file[i][:-4] + '_augmented_udflip.png'
temp_annot_name = annot_file[i][:-4] + '_augmented_udflip.png'
imsave(temp_image_name,np.flipud(temp_image))
imsave(temp_annot_name,np.flipud(temp_annot))
image_file.append(temp_image_name)
annot_file.append(temp_annot_name)
train_file_mod = open('train_augmented.txt', 'wb')
for i in range(len(image_file)):
train_file_mod.write(image_file[i] + ' ' + annot_file[i] + '\n')
train_file_mod.close()
【问题讨论】:
标签: python numpy python-imaging-library