2016-07-14 2 views
2

나는 convnet을 훈련하기 위해 아주 기본적인 이미지 확대를하고 있는데, 매우 느리다. 파이썬에서 이미지를 열고, 뒤집고, 닫는 더 빠른 방법에 대한 조언을 누군가가 가지고 있는지 궁금합니다. 통과 할 이미지는 약 100,000 개이며 몇 시간이 걸립니다.느린 이미지 열기 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() 

답변

1

: https://pillow.readthedocs.io/en/3.3.x/

당신이 NumPy와 배열로 이미지를 변환하고 그들에게 여기보다 그런 식으로 처리하고 싶다면 그렇게 할 수있는 몇 가지 예입니다 나는 Keras (Theano 또는 TensorFlow의 위에 깊은 학습 추상화 레이어)을 사용하는 것이 좋습니다. 이미 ImageDataGenerator이 내장되어 있습니다. 당신은 기본적으로 그것을 사용하여 데이터 세트에서 다른 이미지 (회전, 확장, 패딩)를 생성 할 수 있습니다.

+0

대신에 cv2.imwrite를 사용했는데 훨씬 빨랐습니다. 내 문제를 해결 한 것 같았다. 나는 나중에 사용을 위해 케라를 볼 것이다. –