2016-04-06 5 views
0

すべてのデータセットが小さいサイズのためにRAMにロードされたすべてのテンソルフローチュートリアルをスキミングしました。しかし、私自身のデータ(〜30Gbの画像)はメモリにロードできないため、さらなる処理のために画像を読み取る有効な方法を探しています。どのように私はそれを行うことができますの例を教えてくれますか?テンソルフローで自分のイメージを効果的に読む

P.S. udacity上

<path/to/img> <label>

+0

使用方法1または2、ここから:https://www.tensorflow.org/バージョン/ r0.7/how_tos/reading_data/index.html#reading-data –

答えて

2

これは、あなたが探しているものです:Tensorflow read images with labels

正確なコードスニペットは、このようなものです:

def read_labeled_image_list(image_list_file): 
    """Reads a .txt file containing pathes and labeles 
    Args: 
     image_list_file: a .txt file with one /path/to/image per line 
     label: optionally, if set label will be pasted after each line 
    Returns: 
     List with all filenames in file image_list_file 
    """ 
    f = open(image_list_file, 'r') 
    filenames = [] 
    labels = [] 
    for line in f: 
     filename, label = line[:-1].split(' ') 
     filenames.append(filename) 
     labels.append(int(label)) 
    return filenames, labels 

def read_images_from_disk(input_queue): 
    """Consumes a single filename and label as a ' '-delimited string. 
    Args: 
     filename_and_label_tensor: A scalar string tensor. 
    Returns: 
     Two tensors: the decoded image, and the string label. 
    """ 
    label = input_queue[1] 
    file_contents = tf.read_file(input_queue[0]) 
    example = tf.image.decode_png(file_contents, channels=3) 
    return example, label 

# Reads pfathes of images together with their labels 
image_list, label_list = read_labeled_image_list(filename) 

images = ops.convert_to_tensor(image_list, dtype=dtypes.string) 
labels = ops.convert_to_tensor(label_list, dtype=dtypes.int32) 

# Makes an input queue 
input_queue = tf.train.slice_input_producer([images, labels], 
              num_epochs=num_epochs, 
              shuffle=True) 

image, label = read_images_from_disk(input_queue, num_labels=num_labels) 

# Optional Preprocessing or Data Augmentation 
# tf.image implements most of the standard image augmentation 
image = preprocess_image(image) 
label = preprocess_label(label) 

# Optional Image and Label Batching 
image_batch, label_batch = tf.train.batch([image, label], 
              batch_size=batch_size) 
0

チュートリアルはhttps://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/udacity/4_convolutions.ipynbに確率論的方法を説明している、あなたは代わりに、単一の漬物ファイル内のすべての画像を保存するので、1つの変更と同じように使用することができ、それらを保存します。私は含む2つのファイルtrain_imagesvalidation_imagesを持っていますあなたが使用しているbatch_sizeの塊になります。これにより、一度に1つのバッチで使用されているデータだけをロードすることができます。

0

推奨される方法は、エンコードされたjpegとラベルがtf.Exampleの機能であるsharded protobufファイルに入れることです。 tensorflow/modelsリポジトリのbuild_image_data.pyでは、ディレクトリ構造からイメージ/ラベルペアのデータベースを作成する方法を示しています。これを少し変更する必要があります(簡単です)。練習時間はimage_processing.pyで、tf.Example protoから画像/ラベルテンソル(デコードされたjpgとラベルをサンプルレコードから抽出し、jpgをデコードし、サイズを変更し、必要に応じて拡張を適用してからエンキューする方法を示しています)をご覧ください。

関連する問題