//  [python]
def test(params):
    """Test function."""
    
    dataloader = BtsDataloader(args.data_path, None, args.filenames_file, params, 'test', do_kb_crop=args.do_kb_crop)

    dataloader_iter = dataloader.loader.make_initializable_iterator()
    iter_init_op = dataloader_iter.initializer
    image, focal = dataloader_iter.get_next()

    model = BtsModel(params, 'test', image, None, focal=focal, bn_training=False)

    # SESSION
    config = tf.ConfigProto(allow_soft_placement=True)
    sess = tf.Session(config=config)

    # INIT
    sess.run(tf.global_variables_initializer())
    sess.run(tf.local_variables_initializer())

    # SAVER
    train_saver = tf.train.Saver()
    
    with tf.device('/cpu:0'):
        restore_path = args.checkpoint_path

        # RESTORE
        train_saver.restore(sess, restore_path)

        num_test_samples = get_num_lines(args.filenames_file)

        with open(args.filenames_file) as f:
            lines = f.readlines()

        print('Now testing {} files with {}'.format(num_test_samples, args.checkpoint_path))
        sess.run(iter_init_op)

        pred_depths = []
        pred_8x8s = []
        pred_4x4s = []
        pred_2x2s = []

        start_time = time.time()
        print('Processing images..')
        for s in tqdm(range(num_test_samples)):
            depth, pred_8x8, pred_4x4, pred_2x2 = sess.run([model.depth_est, model.lpg8x8, model.lpg4x4, model.lpg2x2])
            pred_depths.append(depth[0].squeeze())

            pred_8x8s.append(pred_8x8[0].squeeze())
            pred_4x4s.append(pred_4x4[0].squeeze())
            pred_2x2s.append(pred_2x2[0].squeeze())

        print('Done.')

        save_name = 'result_' + args.model_name

        print('Saving result pngs..')
        if not os.path.exists(os.path.dirname(save_name)):
            try:
                os.mkdir(save_name)
                os.mkdir(save_name + '/raw')
                os.mkdir(save_name + '/cmap')
                os.mkdir(save_name + '/rgb')
                os.mkdir(save_name + '/gt')
            except OSError as e:
                if e.errno != errno.EEXIST:
                    raise

        for s in tqdm(range(num_test_samples)):
            if args.dataset == 'kitti':
                date_drive = lines[s].split('/')[1]
                filename_pred_png = save_name + '/raw/' + date_drive + '_' + lines[s].split()[0].split('/')[-1].replace('.jpg', '.png')
                filename_cmap_png = save_name + '/cmap/' + date_drive + '_' + lines[s].split()[0].split('/')[-1].replace('.jpg', '.png')
                filename_image_png = save_name + '/rgb/' + date_drive + '_' + lines[s].split()[0].split('/')[-1]
            elif args.dataset == 'kitti_benchmark':
                filename_pred_png = save_name + '/raw/' + lines[s].split()[0].split('/')[-1].replace('.jpg', '.png')
                filename_cmap_png = save_name + '/cmap/' + lines[s].split()[0].split('/')[-1].replace('.jpg', '.png')
                filename_image_png = save_name + '/rgb/' + lines[s].split()[0].split('/')[-1]
            else:
                scene_name = lines[s].split()[0].split('/')[0]
                filename_pred_png = save_name + '/raw/' + scene_name + '_' + lines[s].split()[0].split('/')[1].replace('.jpg', '.png')
                filename_cmap_png = save_name + '/cmap/' + scene_name + '_' + lines[s].split()[0].split('/')[1].replace('.jpg', '.png')
                filename_gt_png = save_name + '/gt/' + scene_name + '_' + lines[s].split()[0].split('/')[1].replace('.jpg', '.png')
                filename_image_png = save_name + '/rgb/' + scene_name + '_' + lines[s].split()[0].split('/')[1]

            rgb_path = os.path.join(args.data_path, lines[s].split()[0])
            image = cv2.imread(rgb_path)
            if args.dataset == 'nyu':
                gt_path = os.path.join(args.data_path, lines[s].split()[1])
                gt = cv2.imread(gt_path, -1).astype(np.float32) / 1000.0 # Visualization purpose only
                gt[gt == 0] = np.amax(gt)

            pred_depth = pred_depths[s]
            pred_8x8 = pred_8x8s[s]
            pred_4x4 = pred_4x4s[s]
            pred_2x2 = pred_2x2s[s]

            if args.dataset == 'kitti' or args.dataset == 'kitti_benchmark':
                pred_depth_scaled = pred_depth * 256.0
            else:
                pred_depth_scaled = pred_depth * 1000.0
            
            pred_depth_scaled = pred_depth_scaled.astype(np.uint16)
            cv2.imwrite(filename_pred_png, pred_depth_scaled, [cv2.IMWRITE_PNG_COMPRESSION, 0])

            if args.save_lpg:
                cv2.imwrite(filename_image_png, image[10:-1 - 9, 10:-1 - 9, :])
                if args.dataset == 'nyu':
                    plt.imsave(filename_gt_png, np.log10(gt[10:-1 - 9, 10:-1 - 9]), cmap='Greys')
                    pred_depth_cropped = pred_depth[10:-1 - 9, 10:-1 - 9]
                    plt.imsave(filename_cmap_png, np.log10(pred_depth_cropped), cmap='Greys')
                    pred_8x8_cropped = pred_8x8[10:-1 - 9, 10:-1 - 9]
                    filename_lpg_cmap_png = filename_cmap_png.replace('.png', '_8x8.png')
                    plt.imsave(filename_lpg_cmap_png, np.log10(pred_8x8_cropped), cmap='Greys')
                    pred_4x4_cropped = pred_4x4[10:-1 - 9, 10:-1 - 9]
                    filename_lpg_cmap_png = filename_cmap_png.replace('.png', '_4x4.png')
                    plt.imsave(filename_lpg_cmap_png, np.log10(pred_4x4_cropped), cmap='Greys')
                    pred_2x2_cropped = pred_2x2[10:-1 - 9, 10:-1 - 9]
                    filename_lpg_cmap_png = filename_cmap_png.replace('.png', '_2x2.png')
                    plt.imsave(filename_lpg_cmap_png, np.log10(pred_2x2_cropped), cmap='Greys')
                else:
                    plt.imsave(filename_cmap_png, np.log10(pred_depth), cmap='Greys')
                    filename_lpg_cmap_png = filename_cmap_png.replace('.png', '_8x8.png')
                    plt.imsave(filename_lpg_cmap_png, np.log10(pred_8x8), cmap='Greys')
                    filename_lpg_cmap_png = filename_cmap_png.replace('.png', '_4x4.png')
                    plt.imsave(filename_lpg_cmap_png, np.log10(pred_4x4), cmap='Greys')
                    filename_lpg_cmap_png = filename_cmap_png.replace('.png', '_2x2.png')
                    plt.imsave(filename_lpg_cmap_png, np.log10(pred_2x2), cmap='Greys')

        return