machine learning - Tensorflow Training and Validation Input Queue Separation -
i tried replicate convolutional network results using tensorflow. used marvin teichmann's implementation github. need write training wrapper. create 2 graphs share variables , 2 input queues, 1 training , 1 validation. test training wrapper, used 2 short lists of training , validation files , validation after every training epoch. printed out shape of every image input queue check whether correct input. however, after started training, seems images training queue being dequeued. both training , validation graphs take input training queue , validation queue never accessed. can explain , solve problem?
here's part of relevant code:
def get_data(image_name_list, num_epochs, scope_name, num_class = num_class): tf.variable_scope(scope_name) scope: images_path = [os.path.join(dataset_dir, i+'.jpg') in image_name_list] gts_path = [os.path.join(gt_dir, i+'.png') in image_name_list] seed = random.randint(0, 2147483647) image_name_queue = tf.train.string_input_producer(images_path, num_epochs=num_epochs, shuffle=false, seed = seed) gt_name_queue = tf.train.string_input_producer(gts_path, num_epochs=num_epochs, shuffle=false, seed = seed) reader = tf.wholefilereader() image_key, image_value = reader.read(image_name_queue) my_image = tf.image.decode_jpeg(image_value) my_image = tf.cast(my_image, tf.float32) my_image = tf.expand_dims(my_image, 0) gt_key, gt_value = reader.read(gt_name_queue) # gt stands ground truth my_gt = tf.cast(tf.image.decode_png(gt_value, channels = 1), tf.float32) my_gt = tf.one_hot(tf.cast(my_gt, tf.int32), num_class) return my_image, my_gt train_image, train_gt = get_data(train_files, num_epoch, 'training') val_image, val_gt = get_data(val_files, num_epoch, 'validation') tf.variable_scope('fcn16') scope: train_vgg16_fcn = fcn16_vgg.fcn16vgg() train_vgg16_fcn.build(train_image, train=true, num_classes=num_class, keep_prob = keep_prob) scope.reuse_variables() val_vgg16_fcn = fcn16_vgg.fcn16vgg() val_vgg16_fcn.build(val_image, train=false, num_classes=num_class, keep_prob = 1) """ define loss, evaluation metric, summary, saver in computation graph. initialize variables , start session. """ epoch in range(starting_epoch, num_epoch): in range(train_num): _, loss_value, shape = sess.run([train_op, train_entropy_loss, tf.shape(train_image)]) print shape in range(val_num): loss_value, shape = sess.run([val_entropy_loss, tf.shape(val_image)]) print shape
to make sure reading different images run:
[train_image_np, val_image_np] = sess.run([train_image, val_image])
to reuse variables better , safer:
with tf.variable_scope('fcn16') scope: train_vgg16_fcn = fcn16_vgg.fcn16vgg() train_vgg16_fcn.build(train_image, train=true, num_classes=num_class, keep_prob = keep_prob) tf.variable_scope(scope, reuse=true): val_vgg16_fcn = fcn16_vgg.fcn16vgg() val_vgg16_fcn.build(val_image, train=false, num_classes=num_class, keep_prob = 1)
Comments
Post a Comment