def restore(ae):
    restore_path = os.path.join(FLAGS.LOG_DIR, FLAGS.CHECKPOINT_DIR)
    latest_checkpoint = tf.train.latest_checkpoint(restore_path)
    log_string(
        tf_util.toYellow("----#-> Model restoring from: %s..." % restore_path))
    ae.saver.restore(ae.sess, latest_checkpoint)
    log_string(tf_util.toYellow("----- Restored from %s." % latest_checkpoint))
Esempio n. 2
0
def restore(ae):
    restore_path = get_restore_path()
    latest_checkpoint = tf.train.latest_checkpoint(restore_path)
    log_string(
        tf_util.toYellow("----#-> Model restoring from: %s..." % restore_path))
    ae.saver.restore(ae.sess, latest_checkpoint)
    log_string(tf_util.toYellow("----- Restored from %s." % latest_checkpoint))
def restore_from_iter(ae, iter):
    restore_path = os.path.join(FLAGS.LOG_DIR, FLAGS.CHECKPOINT_DIR)
    ckpt_path = os.path.join(restore_path, 'model.ckpt-{0}'.format(iter))
    print(
        tf_util.toYellow(
            "----#-> Model restoring from: {} using {} iterations...".format(
                restore_path, iter)))
    ae.saver.restore(ae.sess, ckpt_path)
    print(tf_util.toYellow("----- Restored from %s." % ckpt_path))
    ####### log writing
    FLAGS.LOG_DIR = FLAGS.LOG_DIR + '/' + FLAGS.task_name
    #FLAGS.CHECKPOINT_DIR = os.path.join(FLAGS.CHECKPOINT_DIR, FLAGS.task_name)
    #tf_util.mkdir(FLAGS.CHECKPOINT_DIR)

    if not FLAGS.is_training:
        agent = ActiveAgent(FLAGS)
        restore_from_iter(agent, FLAGS.test_iter)
        test(agent, FLAGS.test_episode_num, FLAGS.test_iter)

        sys.exit()

    if not os.path.exists(FLAGS.LOG_DIR):
        os.mkdir(FLAGS.LOG_DIR)
        print tf_util.toYellow('===== Created %s.' % FLAGS.LOG_DIR)
    else:
        # os.system('rm -rf %s/*'%FLAGS.LOG_DIR)
        if not (FLAGS.restore):

            def check_delete():
                if FLAGS.force_delete:
                    return True
                delete_key = raw_input(
                    tf_util.toRed(
                        '===== %s exists. Delete? [y (or enter)/N] ' %
                        FLAGS.LOG_DIR))
                return delete_key == 'y' or delete_key == ''

            if check_delete():
                os.system('rm -rf %s/*' % FLAGS.LOG_DIR)
Esempio n. 5
0
def restore_pretrain(ae):
    restore_path = FLAGS.pretrain_restore_path
    log_string(
        tf_util.toYellow("----#-> Model restoring from: %s..." % restore_path))
    ae.saver.restore(ae.sess, restore_path)
    log_string(tf_util.toYellow("----- Restored from %s." % restore_path))
    #MODEL_FILE = os.path.join(BASE_DIR, 'models', FLAGS.model_file+'.py')

    FLAGS.LOG_DIR = FLAGS.LOG_DIR + '/' + FLAGS.task_name
    #FLAGS.CHECKPOINT_DIR = os.path.join(FLAGS.CHECKPOINT_DIR, FLAGS.task_name)
    #tf_util.mkdir(FLAGS.CHECKPOINT_DIR)
    if not FLAGS.is_training:
        FLAGS.batch_size = 1
        ae = AE_vox2vox(FLAGS)
        restore_from_iter(ae, FLAGS.test_iter)
        test(ae, FLAGS.test_iter)

        sys.exit()

    if not os.path.exists(FLAGS.LOG_DIR):
        os.mkdir(FLAGS.LOG_DIR)
        print tf_util.toYellow('===== Created %s.' % FLAGS.LOG_DIR)
    else:
        # os.system('rm -rf %s/*'%FLAGS.LOG_DIR)
        if not (FLAGS.restore):

            def check_delete():
                if FLAGS.force_delete:
                    return True
                delete_key = raw_input(
                    tf_util.toRed(
                        '===== %s exists. Delete? [y (or enter)/N] ' %
                        FLAGS.LOG_DIR))
                return delete_key == 'y' or delete_key == ''

            if check_delete():
                os.system('rm -rf %s/*' % FLAGS.LOG_DIR)
    #                return True
    #            delete_key = raw_input(tf_util.toRed('===== %s exists. Delete? [y (or enter)/N] '%FLAGS.LOG_DIR))
    #            return delete_key == 'y' or delete_key == ''
    #
    #        if check_delete():
    #            os.system('rm -rf %s/*'%FLAGS.LOG_DIR)
    #            #os.system('rm -rf %s/*'%FLAGS.CHECKPOINT_DIR)
    #            print tf_util.toRed('Deleted.'+FLAGS.LOG_DIR)
    #        else:
    #            print tf_util.toRed('Overwrite.')
    #    else:
    #        print tf_util.toRed('To Be Restored...')

    #tf_util.mkdir(os.path.join(FLAGS.LOG_DIR, 'saved_images'))
    #os.system('cp %s %s' % (MODEL_FILE, FLAGS.LOG_DIR)) # bkp of model def
    #os.system('cp train.py %s' % (FLAGS.LOG_DIR)) # bkp of train procedure

    #prepare_plot()
    log_string(
        tf_util.toYellow('<<<<' + FLAGS.task_name + '>>>> ' +
                         str(tf.flags.FLAGS.__flags)))

    ae = AE_rgb2d(FLAGS)
    restore(ae)
    test(ae, FLAGS.test_list_path)

    # z_list = []
    # test_demo_render_z(ae, z_list)

    #FLAGS.LOG_FOUT.close()