print("Restoring latest model from {}".format(CHECKPOINTS_PATH_SRM))
    saver = tf.train.Saver()
    latest_checkpoint = tf.train.latest_checkpoint(CHECKPOINTS_PATH_SRM)
    print("Latest checkpoint: {}\n".format(latest_checkpoint))
    saver.restore(srm_sess, latest_checkpoint)
    
#sys.exit(0)

if USE_SCORER and SCORER == "DCGAN_Scorer":
    scorer_graph = tf.Graph()
    scorer_sess = tf.Session(graph=scorer_graph, config=config)
    with scorer_graph.as_default():

        # data
        galaxy_im, _, nb_galaxies, _ = create_dataloader_train_labeled(data_root=DATA_ROOT, batch_size=1, batches_to_prefetch=2, all_data=False)
        
        # DCGAN Scorer model
        print("Building DCGAN Scorer model ...")
        sys.stdout.flush()
        im_pl = tf.placeholder(dtype=tf.float32, shape=[BATCH_SIZE, 1, 1000, 1000])
        model1 = DCGAN()
        _, ops = model1.discriminator_model(inp=im_pl, training=False, resize=True) # get discriminator output

        flat = ops["flat"]
        model2 = Scorer_head()
        scores_pred = model2.scorer_head_model(features=flat, training=False)
        
        print("Restoring latest model from {}".format(CHECKPOINTS_PATH_SCORER))
        saver = tf.train.Saver()
        latest_checkpoint = tf.train.latest_checkpoint(CHECKPOINTS_PATH_SCORER)
    create_zip_code_files(os.path.join(LOG_DIR, "code.zip"), files)

#sys.exit(0)
# remove warning messages
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
tf.logging.set_verbosity(tf.logging.ERROR)

config = tf.ConfigProto()
config.gpu_options.allow_growth = True
config.gpu_options.visible_device_list = "0"
with tf.Session(config=config) as sess:

    # data
    real_im, _, nb_reals, _ = create_dataloader_train_labeled(
        data_root=DATA_ROOT,
        batch_size=BATCH_SIZE,
        batches_to_prefetch=BATCHES_TO_PREFETCH,
        all_data=False)

    training_pl = tf.placeholder(dtype=tf.bool, shape=[])
    im_pl = tf.placeholder(dtype=tf.float32, shape=[BATCH_SIZE, C, H, W])

    real_im = (real_im +
               1) / 2.0  # denormalize images to the range [0.0, 255.0]

    #model
    print("Building model ...")
    sys.stdout.flush()
    model = CVAE(batch_size=BATCH_SIZE, latent_dim=NOISE_DIM)
    max_pooled, mean, logvar, _ = model.inference_model(inp=im_pl,
                                                        training=training_pl)
Beispiel #3
0
print("    LOG_DIR: {}".format(LOG_DIR))
print("    CONTINUE_TRAINING: {}".format(CONTINUE_TRAINING))
print("\n")
sys.stdout.flush()

# remove warning messages
os.environ["TF_CPP_MIN_LOG_LEVEL"]="2"
tf.logging.set_verbosity(tf.logging.ERROR)

config = tf.ConfigProto()
config.gpu_options.allow_growth = True
config.gpu_options.visible_device_list = "0"
with tf.Session(config=config) as sess:

    # data
    train_ds, nb_images = create_dataloader_train_labeled(data_root=DATA_ROOT, batch_size=BATCH_SIZE, batches_to_prefetch=BATCHES_TO_PREFETCH, all_data=True)
    real_im, label = train_ds # unzip
    
    # define noise and test data
    noise = tf.random.normal([BATCH_SIZE, NOISE_DIM], seed=global_seed, name="random_noise") # noise fed to generator
    y_G = tf.random.uniform( shape=[BATCH_SIZE, 1], minval=0, maxval=2, dtype=tf.int32, seed=global_seed) # labels fed to generator
    
    noise_test = np.random.normal(0, 1, [BATCH_SIZE, NOISE_DIM]).astype("float32") # constant noise to see its evolution over time
    y_test = np.random.randint(2, size=[BATCH_SIZE, 1]) # constant list of labels for testing
    
    # define placeholders
    im_pl = tf.placeholder(dtype=tf.float32, shape=[BATCH_SIZE, C, H, W]) # placeholder for real images fed to discriminator
    noise_pl = tf.placeholder(dtype=tf.float32, shape=[BATCH_SIZE, NOISE_DIM]) # placeholder for noise fed to generator
    
    y_pl_G = tf.placeholder(dtype=tf.float32, shape=[BATCH_SIZE, 1]) # placeholder for label fed to generator
    y_pl_D = tf.placeholder(dtype=tf.float32, shape=[BATCH_SIZE, 1]) # placeholder for label fed to discriminator