Ejemplo n.º 1
0
        img = imageio.imread(file)
        new_file_name = os.path.join(tile_dir, 'rs_'+os.path.basename(file))
        img = scipy.misc.imresize(img, (2541, 2541))
        imageio.imsave(new_file_name, img)
    reshape_files = glob(os.path.join(tile_dir, 'rs_*.tif'))

tile_ids = [os.path.basename(a)[3:].split('.')[0] for a in reshape_files]
#gamma_list = np.arange(0.1, 5.1, 0.1) #[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.2, 1.5, 1.8, 2, 2.5, 3]
gamma_list = [1.8]
gt_target_pixels = np.zeros((len(tile_ids), len(gamma_list)))
pred_target_pixels = np.zeros((len(tile_ids), len(gamma_list)))
gt_target_num = np.zeros((len(tile_ids), len(gamma_list)))
pred_target_num = np.zeros((len(tile_ids), len(gamma_list)))
for cnt_1, gamma in enumerate(gamma_list):
    path = os.path.join(uabRepoPaths.evalPath, 'sp_gamma', 'UnetCrop_inria_aug_grid_0_PS(572, 572)_BS5_EP100_LR0.0001_DS60_DR0.1_SFN32',
                                       'building_ct{}'.format(util_functions.d2s(gamma)))

    # make new imgs
    invGamma = 1.0 / gamma
    table = np.array([((i / 255.0) ** invGamma) * 255 for i in np.arange(0, 256)]).astype('uint8')
    for rs_file, tile_id in zip(reshape_files, tile_ids):
        img_rs = imageio.imread(rs_file)
        img_adjust = cv2.LUT(img_rs, table)
        img_name = os.path.basename(rs_file)[3:].split('.')[0].replace('_', '-') + '_RGB.jpg'
        imageio.imsave(os.path.join(adjust_save_dir, img_name), img_adjust)

    if not os.path.exists(path):
        print(path)
        tf.reset_default_graph()
        img_mean = np.zeros(3)
        n = len(reshape_files) * 2541 ** 2
Ejemplo n.º 2
0
 def getName(self):
     return '%s_rF%s_rB%s' % (self.defaultName,
                              util_functions.d2s(self.rescFact, 3),
                              util_functions.d2s(self.rescBias, 3))
Ejemplo n.º 3
0
                       shape=[None, input_size[0], input_size[1], 3],
                       name='X')
    y = tf.placeholder(tf.int32,
                       shape=[None, input_size[0], input_size[1], 1],
                       name='y')
    mode = tf.placeholder(tf.bool, name='mode')
    model = uabMakeNetwork_UNet.UnetModelCrop({
        'X': X,
        'Y': y
    },
                                              trainable=mode,
                                              input_size=input_size,
                                              batch_size=5,
                                              start_filter_num=32)
    # create graph
    model.create_graph('X', class_num=2)

    # evaluate on tiles
    model.evaluate(file_list_valid,
                   file_list_valid_truth,
                   adjust_save_dir,
                   file_dir,
                   input_size,
                   tile_size,
                   batch_size,
                   img_mean,
                   model_dir,
                   gpu,
                   save_result_parent_dir='ct_gamma',
                   ds_name='ct{}'.format(util_functions.d2s(gamma)))
Ejemplo n.º 4
0
import sis_utils
import util_functions

img_dir, task_dir = sis_utils.get_task_img_folder()
base_dir = r'/hdd/Results/inria_gamma/UnetCrop_inria_aug_grid_0_PS(572, 572)_BS5_EP100_LR0.0001_DS60_DR0.1_SFN32'
ft_dir1 = r'/hdd/Results/inria_gamma/UnetCrop_inria_aug_gamma_0_PS(572, 572)_BS5_EP40_LR1e-05_DS20_DR0.1_SFN32'
ft_dir2 = r'/hdd/Results/inria_gamma/UnetCrop_inria_aug_gamma_0_PS(572, 572)_BS5_EP40_LR1e-06_DS20_DR0.1_SFN32'
ts_dir = r'/hdd/Results/inria_gamma/UnetCrop_inria_aug_gamma_0_PS(572, 572)_BS5_EP100_LR0.0001_DS40_DR0.1_SFN32'

model_name = ['base', 'finetune-5', 'finetune-6', 'scratch']
model_dir = [base_dir, ft_dir1, ft_dir2, ts_dir]
gamma_list = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.5, 2]

plt.rcParams.update({'font.size': 12})
plt.rc('grid', linestyle='--')
for name, directory in zip(model_name, model_dir):
    iou_record = np.zeros(len(gamma_list))
    for cnt, gamma in enumerate(gamma_list):
        result_file = os.path.join(directory, 'ct{}'.format(util_functions.d2s(gamma)), 'result.txt')
        with open(result_file, 'r') as f:
            results = f.readlines()
            iou_record[cnt] = float(results[-1])
    plt.plot(gamma_list, iou_record, '-o', label=name)
plt.title('IoU Vs Gamma')
plt.grid()
plt.xlabel('Gamma')
plt.ylabel('IoU')
plt.legend()
plt.savefig(os.path.join(img_dir, 'iou_vs_gamma_ft_ts.png'))
plt.show()
Ejemplo n.º 5
0
 def getName(self):
     return '{}_dF{}'.format(self.defaultName, util_functions.d2s(self.rescFact, 3))
Ejemplo n.º 6
0
import sis_utils
import util_functions

img_dir, task_dir = sis_utils.get_task_img_folder()
deeplab_dir = r'/hdd/Results/ct_gamma/DeeplabV3_spca_aug_grid_0_PS(321, 321)_BS5_EP100_LR1e-05_DS40_DR0.1_SFN32'
unet_dir = r'/hdd/Results/ct_gamma/UnetCropCV_(FixedRes)CTFinetune+nlayer9_PS(572, 572)_BS5_EP100_LR1e-05_DS50_DR0.1_SFN32'

model_name = ['deeplab', 'unet']
model_dir = [deeplab_dir, unet_dir]
gamma_list = [0.2, 0.5, 1, 1.5, 2, 2.5, 3]

plt.rcParams.update({'font.size': 14})
plt.rc('grid', linestyle='--')
for name, directory in zip(model_name, model_dir):
    iou_record = np.zeros(len(gamma_list))
    for cnt, gamma in enumerate(gamma_list):
        result_file = os.path.join(directory,
                                   'ct{}'.format(util_functions.d2s(gamma)),
                                   'result.txt')
        with open(result_file, 'r') as f:
            results = f.readlines()
            iou_record[cnt] = float(results[-1])
    plt.plot(gamma_list, iou_record, '-o', label=name)
plt.title('IoU Vs Gamma')
plt.grid()
plt.xlabel('Gamma')
plt.ylabel('IoU')
plt.legend()
plt.savefig(os.path.join(img_dir, 'iou_vs_gamma.png'))
plt.show()
Ejemplo n.º 7
0
        gt = imageio.imread(file[:-8] + '_GT.tif')
        img_adjust = cv2.LUT(img, table)
        img_mean += get_sum_of_channel(img_adjust)
        img_name = os.path.basename(file)
        gt_name = os.path.basename(file[:-8] + '_GT.tif')
        imageio.imsave(os.path.join(adjust_save_dir, img_name), img_adjust)
        imageio.imsave(os.path.join(adjust_save_dir, gt_name), gt/255)

    img_mean = img_mean / n
    print(img_mean)

    file_list_valid = [[os.path.basename(x)] for x in sorted(glob(os.path.join(adjust_save_dir, '*_RGB.tif')))]
    file_list_valid_truth = [os.path.basename(x) for x in sorted(glob(os.path.join(adjust_save_dir, '*_GT.tif')))]

    # make the model
    # define place holder
    X = tf.placeholder(tf.float32, shape=[None, input_size[0], input_size[1], 3], name='X')
    y = tf.placeholder(tf.int32, shape=[None, input_size[0], input_size[1], 1], name='y')
    mode = tf.placeholder(tf.bool, name='mode')
    model = uabMakeNetwork_UNet.UnetModelCrop({'X':X, 'Y':y},
                                              trainable=mode,
                                              input_size=input_size,
                                              batch_size=5, start_filter_num=32)
    # create graph
    model.create_graph('X', class_num=2)

    # evaluate on tiles
    model.evaluate(file_list_valid, file_list_valid_truth, adjust_save_dir, adjust_save_dir,
                   input_size, tile_size, batch_size, img_mean, model_dir, gpu,
                   save_result_parent_dir='inria_gamma', ds_name='ct{}'.format(util_functions.d2s(gamma)))