diff --git a/modules/deeplearning/srcnn_l1b_l2.py b/modules/deeplearning/srcnn_l1b_l2.py index 01030518744693e25700b6ebcceba2c0693fb963..9309bca3adafb8fd3cf0ab7b46bd586f2be30d68 100644 --- a/modules/deeplearning/srcnn_l1b_l2.py +++ b/modules/deeplearning/srcnn_l1b_l2.py @@ -1,5 +1,7 @@ import glob import tensorflow as tf + +import util.util from util.setup import logdir, modeldir, cachepath, now, ancillary_path from util.util import EarlyStop, normalize, denormalize, resample, resample_2d_linear, resample_one,\ resample_2d_linear_one, get_grid_values_all, add_noise, smooth_2d, smooth_2d_single @@ -766,6 +768,82 @@ def run_evaluate_static(in_file, out_file, ckpt_dir): return out_sr, hr_grd_a, hr_grd_c +def analyze(file='/Users/tomrink/cld_opd_out.npy'): + # Save this: + # nn.test_data_files = glob.glob('/Users/tomrink/data/clavrx_opd_valid_DAY/data_valid*.npy') + # idxs = np.arange(50) + # dat, lbl = nn.get_in_mem_data_batch(idxs, False) + # tmp = dat[:, 1:128, 1:128, 1] + # tmp = dat[:, 1:129, 1:129, 1] + + tup = np.load(file, allow_pickle=True) + lbls = tup[0] + pred = tup[1] + + lbls = lbls[:, :, :, 0] + pred = pred[:, :, :, 0] + + diff = pred - lbls + + mae = (np.sum(np.abs(diff))) / diff.size + print('MAE: ', mae) + + bin_ranges = util.util.get_bin_ranges(0.0, 160.0, 20.0) + + bin_edges = [] + bin_ranges = [] + + bin_ranges.append([0.0, 5.0]) + bin_edges.append(0.0) + + bin_ranges.append([5.0, 10.0]) + bin_edges.append(5.0) + + bin_ranges.append([10.0, 15.0]) + bin_edges.append(10.0) + + bin_ranges.append([15.0, 20.0]) + bin_edges.append(15.0) + + bin_ranges.append([20.0, 30.0]) + bin_edges.append(20.0) + + bin_ranges.append([30.0, 40.0]) + bin_edges.append(30.0) + + bin_ranges.append([40.0, 60.0]) + bin_edges.append(40.0) + + bin_ranges.append([60.0, 80.0]) + bin_edges.append(60.0) + + bin_ranges.append([80.0, 100.0]) + bin_edges.append(80.0) + + bin_ranges.append([100.0, 120.0]) + bin_edges.append(100.0) + + bin_ranges.append([120.0, 140.0]) + bin_edges.append(120.0) + + bin_ranges.append([140.0, 160.0]) + bin_edges.append(140.0) + + bin_edges.append(160.0) + + diff_by_value_bins = util.util.bin_data_by(diff.flatten(), lbls.flatten(), bin_ranges) + + values = [] + for k in range(len(bin_ranges)): + diff_k = diff_by_value_bins[k] + mae_k = (np.sum(np.abs(diff_k)) / diff_k.size) + values.append(int(mae_k/bin_ranges[k][1] * 100.0)) + + print('MAE: ', diff_k.size, bin_ranges[k], mae_k) + + return np.array(values), bin_edges + + if __name__ == "__main__": nn = SRCNN() nn.run('matchup_filename')