2016-07-14 10 views
2

私はconvnetを訓練するために非常に基本的な画像拡大を行っていますが、それは非常に遅いです。私は、誰かがPythonで画像を開いたり、反転したり、画像を閉じるより速い方法についてアドバイスを持っているのだろうかと思っていました。それには約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() 

答えて

0

私はPILまたはPillowパッケージに試してみます。

PILのドキュメント:http://www.pythonware.com/products/pil/

枕のドキュメント:https://pillow.readthedocs.io/en/3.3.x/

あなたはnumpyの配列にあなたの画像を変換し、それらをここでよりそのように処理したい場合はそれを行うためのいくつかの例は以下のとおりです。 http://code.activestate.com/recipes/577591-conversion-of-pil-image-and-numpy-array/

1

Keras(TheanoまたはTensorFlowの上にある深い学習抽象レイヤー)を使用することをお勧めします。すでにImageDataGeneratorが内蔵されています。基本的には、データセットからさまざまなイメージ(回転、拡大、パディング)を生成するために使用できます。

+0

私は代わりにcv2.imwriteを使用しましたが、はるかに高速でした。それは私の問題を修正するようだ。私は将来の使用のためにケラスを見ていきます。 –

関連する問題