2017-06-27 19 views
0

私はラベルを付けたいくつかの画像でcnnモデルを訓練しようとしています。私はTensorFlowを初めて使う人です。`.fit()`で引数として使用する `input_fn`を作成する方法は?

def read_labeled_image_list(image_list_file): 
    f = open(image_list_file, 'r') 
    filenames = [] 
    labels = [] 
    for line in f: 
     filename, label = line[:-1].split(' ') 
     filenames.append(filename) 
     index0 = 1 if int(label) == 0 else 0 
     index1 = 1 if int(label) == 1 else 0 
     labels.append([index0, index1]) 
    return filenames, labels 

def read_images_from_disk(input_queue): 
    label = input_queue[1] 
    file_contents = tf.read_file(input_queue[0]) 
    example = tf.image.decode_jpeg(file_contents, channels=1) 
    return example, label 

私input_fnとして "read_images_from_disk" の使用:

image_list, label_list = 
      read_labeled_image_list("./images_training/training_list.txt") 

images = tf.constant(image_list, dtype=tf.string) 
labels = tf.constant(label_list, dtype=tf.int32) 

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

image, label = read_images_from_disk(input_queue) 

# Train the model 
graph_classifier.fit(
    input_fn=read_images_from_disk(input_queue), 
    steps=20000, 
    monitors=[logging_hook]) 

を私は次のエラーを取得する:

features, labels = input_fn() 
TypeError: 'tuple' object is not callable 

答えて

0

の理由と、ここで私がやったものですエラーはfitメソッドのinput_fn引数が呼び出し可能であると想定されています。その後、試みることができる:

def read_images_from_disk(input_queue): 
    label = input_queue[1] 
    file_contents = tf.read_file(input_queue[0]) 
    example = tf.image.decode_jpeg(file_contents, channels=1) 
    return example, label 

def my_input_func(): 
return read_images_from_disk(input_queue) 

# Train the model 
graph_classifier.fit(
    input_fn=my_input_func, 
    steps=20000, 
    monitors=[logging_hook]) 

私もinput_funcに慎重 the official docを読むことをお勧めします。

関連する問題