(argv=None)
print("Setting up image reader...")
    train_records, valid_records = scene_parsing.read_dataset(FLAGS.data_dir)
    print(len(train_records))
    print(len(valid_records))

    print("Setting up dataset reader")
    image_options = {'resize': True, 'resize_size': IMAGE_SIZE}
    if FLAGS.mode == 'train':
        train_dataset_reader = dataset.BatchDatset(train_records, image_options)
    validation_dataset_reader = dataset.BatchDatset(valid_records, image_options)
print("Setting up image reader...")
    train_records, valid_records = scene_parsing.read_dataset(FLAGS.data_dir)
    print(len(train_records))
    print(len(valid_records))
print ( Setting up image reader ... ) train_records valid_records = scene_parsing . read_dataset ( FLAGS . data_dir ) print ( len ( train_records )) print ( len ( valid_records ))
def main(argv=None):
    keep_probability = tf.placeholder(tf.float32, name="keep_probabilty")
    image = tf.placeholder(tf.float32, shape=[None, IMAGE_HEIGHT, IMAGE_WIDTH, 6], name="input_image")
    annotation = tf.placeholder(tf.int32, shape=[None, IMAGE_HEIGHT, IMAGE_WIDTH, 1], name="annotation")

    pred_annotation, logits = inference(image, keep_probability)
    #tf.image_summary("input_image", image, max_images=2)
    #tf.image_summary("ground_truth", tf.cast(annotation, tf.uint8), max_images=2)
    #tf.image_summary("pred_annotation", tf.cast(pred_annotation, tf.uint8), max_images=2)
    loss = tf.reduce_mean((tf.nn.sparse_softmax_cross_entropy_with_logits(logits,
                                                                          tf.squeeze(annotation, squeeze_dims=[3]),
                                                                          name="entropy")))
    #tf.scalar_summary("entropy", loss)

    trainable_var = tf.trainable_variables()
    train_op = train(loss, trainable_var)

    #print("Setting up summary op...")
    #summary_op = tf.merge_all_summaries()

    '''
    print("Setting up image reader...")
    train_records, valid_records = scene_parsing.read_dataset(FLAGS.data_dir)
    print(len(train_records))
    print(len(valid_records))

    print("Setting up dataset reader")
    image_options = {'resize': True, 'resize_size': IMAGE_SIZE}
    if FLAGS.mode == 'train':
        train_dataset_reader = dataset.BatchDatset(train_records, image_options)
    validation_dataset_reader = dataset.BatchDatset(valid_records, image_options)
    '''
    train_dataset_reader = BatchDatset('data/trainlist.mat')

    sess = tf.Session()

    print("Setting up Saver...")
    saver = tf.train.Saver()
    #summary_writer = tf.train.SummaryWriter(FLAGS.logs_dir, sess.graph)

    sess.run(tf.initialize_all_variables())
    ckpt = tf.train.get_checkpoint_state(FLAGS.logs_dir)
    if ckpt and ckpt.model_checkpoint_path:
        saver.restore(sess, ckpt.model_checkpoint_path)
        print("Model restored...")

    #if FLAGS.mode == "train":
    itr = 0
    train_images, train_annotations = train_dataset_reader.next_batch()
    trloss = 0.0
    while len(train_annotations) > 0:
        #train_images, train_annotations = train_dataset_reader.next_batch(FLAGS.batch_size)
        #print('==> batch data: ', train_images[0][100][100], '===', train_annotations[0][100][100])
        feed_dict = {image: train_images, annotation: train_annotations, keep_probability: 0.5}
        _, rloss =  sess.run([train_op, loss], feed_dict=feed_dict)
        trloss += rloss

        if itr % 100 == 0:
            #train_loss, rpred = sess.run([loss, pred_annotation], feed_dict=feed_dict)
            print("Step: %d, Train_loss:%f" % (itr, trloss / 100))
            trloss = 0.0
            #summary_writer.add_summary(summary_str, itr)

        #if itr % 10000 == 0 and itr > 0:
        '''
        valid_images, valid_annotations = validation_dataset_reader.next_batch(FLAGS.batch_size)
        valid_loss = sess.run(loss, feed_dict={image: valid_images, annotation: valid_annotations,
                                                       keep_probability: 1.0})
        print("%s ---> Validation_loss: %g" % (datetime.datetime.now(), valid_loss))'''
        itr += 1

        train_images, train_annotations = train_dataset_reader.next_batch()
    saver.save(sess, FLAGS.logs_dir + "plus_model.ckpt", itr)

    '''elif FLAGS.mode == "visualize":
        valid_images, valid_annotations = validation_dataset_reader.get_random_batch(FLAGS.batch_size)
        pred = sess.run(pred_annotation, feed_dict={image: valid_images, annotation: valid_annotations,
                                                    keep_probability: 1.0})
        valid_annotations = np.squeeze(valid_annotations, axis=3)
        pred = np.squeeze(pred, axis=3)

        for itr in range(FLAGS.batch_size):
            utils.save_image(valid_images[itr].astype(np.uint8), FLAGS.logs_dir, name="inp_" + str(5+itr))
            utils.save_image(valid_annotations[itr].astype(np.uint8), FLAGS.logs_dir, name="gt_" + str(5+itr))
            utils.save_image(pred[itr].astype(np.uint8), FLAGS.logs_dir, name="pred_" + str(5+itr))
            print("Saved image: %d" % itr)'''
def main ( argv = None ) : keep_probability = tf . placeholder ( tf . float32 , name = "keep_probabilty" ) image = tf . placeholder ( tf . float32 , shape = [ None , IMAGE_HEIGHT , IMAGE_WIDTH , 6 ] , name = "input_image" ) annotation = tf . placeholder ( tf . int32 , shape = [ None , IMAGE_HEIGHT , IMAGE_WIDTH , 1 ] , name = "annotation" ) pred_annotation , logits = inference ( image , keep_probability ) #tf.image_summary("input_image", image, max_images=2) #tf.image_summary("ground_truth", tf.cast(annotation, tf.uint8), max_images=2) #tf.image_summary("pred_annotation", tf.cast(pred_annotation, tf.uint8), max_images=2) loss = tf . reduce_mean ( ( tf . nn . sparse_softmax_cross_entropy_with_logits ( logits , tf . squeeze ( annotation , squeeze_dims = [ 3 ] ) , name = "entropy" ) ) ) #tf.scalar_summary("entropy", loss) trainable_var = tf . trainable_variables ( ) train_op = train ( loss , trainable_var ) #print("Setting up summary op...") #summary_op = tf.merge_all_summaries() train_dataset_reader = BatchDatset ( 'data/trainlist.mat' ) sess = tf . Session ( ) print ( "Setting up Saver..." ) saver = tf . train . Saver ( ) #summary_writer = tf.train.SummaryWriter(FLAGS.logs_dir, sess.graph) sess . run ( tf . initialize_all_variables ( ) ) ckpt = tf . train . get_checkpoint_state ( FLAGS . logs_dir ) if ckpt and ckpt . model_checkpoint_path : saver . restore ( sess , ckpt . model_checkpoint_path ) print ( "Model restored..." ) #if FLAGS.mode == "train": itr = 0 train_images , train_annotations = train_dataset_reader . next_batch ( ) trloss = 0.0 while len ( train_annotations ) > 0 : #train_images, train_annotations = train_dataset_reader.next_batch(FLAGS.batch_size) #print('==> batch data: ', train_images[0][100][100], '===', train_annotations[0][100][100]) feed_dict = { image : train_images , annotation : train_annotations , keep_probability : 0.5 } _ , rloss = sess . run ( [ train_op , loss ] , feed_dict = feed_dict ) trloss += rloss if itr % 100 == 0 : #train_loss, rpred = sess.run([loss, pred_annotation], feed_dict=feed_dict) print ( "Step: %d, Train_loss:%f" % ( itr , trloss / 100 ) ) trloss = 0.0 #summary_writer.add_summary(summary_str, itr) #if itr % 10000 == 0 and itr > 0: '''
        valid_images, valid_annotations = validation_dataset_reader.next_batch(FLAGS.batch_size)
        valid_loss = sess.run(loss, feed_dict={image: valid_images, annotation: valid_annotations,
                                                       keep_probability: 1.0})
        print("%s ---> Validation_loss: %g" % (datetime.datetime.now(), valid_loss))''' itr += 1 train_images , train_annotations = train_dataset_reader . next_batch ( ) saver . save ( sess , FLAGS . logs_dir + "plus_model.ckpt" , itr ) '''elif FLAGS.mode == "visualize":
        valid_images, valid_annotations = validation_dataset_reader.get_random_batch(FLAGS.batch_size)
        pred = sess.run(pred_annotation, feed_dict={image: valid_images, annotation: valid_annotations,
                                                    keep_probability: 1.0})
        valid_annotations = np.squeeze(valid_annotations, axis=3)
        pred = np.squeeze(pred, axis=3)

        for itr in range(FLAGS.batch_size):
            utils.save_image(valid_images[itr].astype(np.uint8), FLAGS.logs_dir, name="inp_" + str(5+itr))
            utils.save_image(valid_annotations[itr].astype(np.uint8), FLAGS.logs_dir, name="gt_" + str(5+itr))
            utils.save_image(pred[itr].astype(np.uint8), FLAGS.logs_dir, name="pred_" + str(5+itr))
            print("Saved image: %d" % itr)'''