我正在做一些非常基本的圖像增強訓練一個convnet,它是非常緩慢的。我想知道是否有人有關於以更快的方式打開,翻轉和關閉python圖像的建議?它有大約10萬張圖片,需要花費幾個小時。慢圖像打開python,建議增加速度?
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()
我改用cv2.imwrite,速度要快得多。它似乎解決了我的問題。儘管如此,我會考慮keras以備將來使用。 –