Exemple #1
0
def test3d(config):
    prepare_dirs_and_logger(config)
    tf.set_random_seed(config.random_seed)

    batch_manager = BatchManager(config)

    # batch test
    sess_config = tf.ConfigProto()
    sess_config.gpu_options.allow_growth = True
    sess_config.allow_soft_placement = True
    sess_config.log_device_placement = False
    sess = tf.Session(config=sess_config)

    batch_manager.start_thread(sess)
    x, y = batch_manager.batch()
    x_ = x.eval(session=sess)
    batch_manager.stop_thread()

    x_ = (x_ + 1) * 127.5  # [0, 255]
    x_ = np.mean(x_, axis=1)  # yx
    save_image(x_, '{}/x_fixed.png'.format(config.model_dir))

    # random pick from parameter space
    sample = batch_manager.random_list(config.batch_size)
    save_image(sample['xy'], '{}/xy.png'.format(config.model_dir))
    save_image(sample['zy'], '{}/zy.png'.format(config.model_dir))
    save_image(sample['xym'], '{}/xym.png'.format(config.model_dir))
    save_image(sample['zym'], '{}/zym.png'.format(config.model_dir))
    with open('{}/sample.txt'.format(config.model_dir), 'w') as f:
        f.write(str(sample['p']))
        f.write(str(sample['z']))
Exemple #2
0
def main(config):
    prepare_dirs_and_logger(config)
    batch_manager = BatchManager(config)

    # test
    sess_config = tf.ConfigProto()
    sess_config.gpu_options.allow_growth = True
    sess_config.allow_soft_placement = True
    sess_config.log_device_placement = False
    sess = tf.Session(config=sess_config)

    batch_manager.init_it(sess)
    x, y = batch_manager.batch()
    x_, y_ = sess.run([x, y])
    print(x_.shape, y_.shape)

    x, y = batch_manager.batch(is_window=True)
    x_, y_ = sess.run([x, y])
    print(x_.shape, y_.shape)

    batch_manager.init_test_it()
    x, y = batch_manager.test_batch()
    x_, y_ = sess.run([x, y])
    print(x_.shape, y_.shape)

    x, y = batch_manager.test_batch(is_window=True)
    x_, y_ = sess.run([x, y])
    print(x_.shape, y_.shape)

    print('batch manager test done')
Exemple #3
0
def main(config):
    prepare_dirs_and_logger(config)
    tf.compat.v1.set_random_seed(config.random_seed)

    if 'nn' in config.arch:
        from data_nn import BatchManager
    else:
        from data import BatchManager
    batch_manager = BatchManager(config)

    if config.is_3d:
        trainer = Trainer3(config, batch_manager)
    else:
        trainer = Trainer(config, batch_manager)

    print("---------------------------------")
    print("|                               |")
    print("|                               |")
    print("|       prepare trainer         |")
    print("|           is done             |")
    print("|                               |")
    print("|                               |")
    print("---------------------------------")

    if config.is_train:
        save_config(config)
        trainer.train()
    else:
        if not config.load_path:
            raise Exception(
                "[!] You should specify `load_path` to load a pretrained model"
            )
        trainer.test()
Exemple #4
0
def main(config):
    prepare_dirs_and_logger(config)
    tf.set_random_seed(config.random_seed)

    from data import BatchManager
    batch_manager = BatchManager(config)

    trainer = Trainer_tumor(config, batch_manager)

    if config.is_train:
        save_config(config)
        trainer.train()
    else:
        if not config.load_path:
            raise Exception(
                "[!] You shou/home/tudorld specify `load_path` to load a pretrained model"
            )
        trainer.test()
Exemple #5
0
def test2d(config):
    prepare_dirs_and_logger(config)
    tf.set_random_seed(config.random_seed)

    batch_manager = BatchManager(config)

    # thread test
    sess_config = tf.ConfigProto()
    sess_config.gpu_options.allow_growth = True
    sess_config.allow_soft_placement = True
    sess_config.log_device_placement = False
    sess = tf.Session(config=sess_config)
    batch_manager.start_thread(sess)

    x, y = batch_manager.batch()  # [-1, 1]
    x_ = x.eval(session=sess)
    # y_ = y.eval(session=sess)
    batch_manager.stop_thread()

    x_w = vort_np(x_)
    x_w /= np.abs(x_w).max()
    x_w = (x_w + 1) * 0.5
    x_w = np.uint8(plt.cm.RdBu(x_w[..., 0]) * 255)[..., :3]
    x_ = (x_ + 1) * 127.5  # [0, 255]
    b_ch = np.ones([config.batch_size, config.res_y, config.res_x, 1]) * 127.5
    x_ = np.concatenate((x_, b_ch), axis=-1)
    x_ = np.concatenate((x_, x_w), axis=0)
    save_image(x_, '{}/x_fixed.png'.format(config.model_dir))

    # random pick from parameter space
    x, pi, zi = batch_manager.random_list(config.batch_size)
    x_w = vort_np(x / 127.5 - 1)
    x_w /= np.abs(x_w).max()
    x_w = (x_w + 1) * 0.5
    x_w = np.uint8(plt.cm.RdBu(x_w[..., 0]) * 255)[..., :3]
    x = np.concatenate((x, x_w), axis=0)
    save_image(x, '{}/x.png'.format(config.model_dir))
    with open('{}/x_p.txt'.format(config.model_dir), 'w') as f:
        f.write(str(pi))
        f.write(str(zi))