Пример #1
0
def predict_and_visualize_by_data_file_one_output(data_file_path,
                                                  target_file_path,
                                                  pred_img,
                                                  which=0,
                                                  result_dir=None,
                                                  model=None):
    example = get_data_test(data_file_path, which)
    time_steps = example.shape[0]
    groundtruth = get_target_test(target_file_path, which)

    plt.figure(figsize=(10, 10))
    if model is not None and pred is None:
        pred = model.predict(example[np.newaxis, :, :, :, np.newaxis])

    G = gridspec.GridSpec(2, time_steps)
    pred_img

    for i, img in enumerate(example):
        axe = plt.subplot(G[0, i])
        axe.imshow(img)

    ax_groundtruth = plt.subplot(G[1, :time_steps // 2])
    ax_groundtruth.imshow(groundtruth)
    ax_groundtruth.set_title('groundtruth')

    ax_pred = plt.subplot(G[1, time_steps // 2:2 * (time_steps // 2)])
    ax_pred.imshow(pred_img)
    ax_pred.set_title('predict')

    if result_dir is not None:
        if not os.path.exists(result_dir):
            os.makedirs(result_dir)
        plt.savefig(os.path.join(result_dir, '{}.png'.format(which)))

    return (groundtruth, pred_img)
Пример #2
0
 def inference(modis_utils_obj, data_type, idx):
     file_path = modis_utils_obj._data_files[data_type]['data']
     data_test = get_data_test(file_path, idx)
     data_test = np.expand_dims(np.expand_dims(data_test, axis=0), axis=-1)
     output = modis_utils_obj.inference_model.predict(data_test)
     output = np.squeeze(np.squeeze(output, axis=0), axis=-1)
     return output
Пример #3
0
def predict_and_visualize_by_data_file_one_output_and_gridding(
        data_file_path, target_file_path, model, which=0, result_dir=None):
    input_seq = get_data_test(data_file_path, which)
    if real_time_steps is not None:
        time_steps = real_time_steps
        input_seq = input_seq[input_seq.shape[0] - real_time_steps:, :, :]
    else:
        time_steps = input_seq.shape[0]
    groundtruth = get_target_test(target_file_path, which)
    if mask_file_path is not None:
        mask_groundtruth = get_target_test(mask_file_path, which)
        mask_groundtruth[mask_groundtruth == -1] = 0
    groundtruth = scale_normalized_data(groundtruth, groundtruth_range)

    plt.figure(figsize=(10, 10))

    offset_x = input_seq.shape[1] % crop_size
    offset_y = input_seq.shape[2] % crop_size
    input_seq = input_seq[:, offset_x//2:-(offset_x - offset_x//2), \
                          offset_y//2:-(offset_y - offset_y//2)]
    groundtruth = groundtruth[offset_x//2:-(offset_x - offset_x//2), \
                              offset_y//2:-(offset_y - offset_y//2)]

    pred_img = np.zeros_like(groundtruth)

    for i in range(input_seq.shape[1] // crop_size):
        for j in range(input_seq.shape[2] // crop_size):
            pred = model.predict(input_seq[np.newaxis, :, \
                                 i*crop_size:(i+1)*crop_size, \
                                 j*crop_size:(j+1)*crop_size, np.newaxis])
            pred_img[i*crop_size:(i+1)*crop_size, \
                     j*crop_size:(j+1)*crop_size] = pred[1][0,:,:,0]

    G = gridspec.GridSpec(2, time_steps)

    for i, img in enumerate(input_seq):
        axe = plt.subplot(G[0, i])
        axe.imshow(img)

    ax_groundtruth = plt.subplot(G[1, :time_steps // 2])
    ax_groundtruth.imshow(groundtruth)
    ax_groundtruth.set_title('groundtruth')

    ax_pred = plt.subplot(G[1, time_steps // 2:2 * (time_steps // 2)])
    ax_pred.imshow(pred_img)
    ax_pred.set_title('predict')

    if result_dir is not None:
        if not os.path.exists(result_dir):
            os.makedirs(result_dir)
        plt.savefig(os.path.join(result_dir, '{}.png'.format(which)))
    return (groundtruth, pred_img)
Пример #4
0
 def inference(modis_utils_obj, data_type, idx):
     file_path = modis_utils_obj._data_files[data_type]['data']
     data_test = get_data_test(file_path, idx)
     data_test = np.expand_dims(np.expand_dims(data_test, axis=0), axis=-1)
     if modis_utils_obj._pretrained:
         data_test = np.tile(data_test, 3)
     pred_img = np.zeros(data_test.shape[2:4])
     model = modis_utils_obj.inference_model
     crop_size = modis_utils_obj._crop_size
     for i in range(data_test.shape[2] // crop_size):
         for j in range(data_test.shape[3] // crop_size):
             pred = model.predict(data_test[:, :, \
                                  i*crop_size:(i+1)*crop_size, \
                                  j*crop_size:(j+1)*crop_size, :])
             pred_img[i*crop_size:(i+1)*crop_size, \
                      j*crop_size:(j+1)*crop_size] = pred[0,:,:,0]
     return pred_img