Skip to content
Snippets Groups Projects
Commit d0bd87c6 authored by tomrink's avatar tomrink
Browse files

snapshot...

parent 7808fbd8
No related branches found
No related tags found
No related merge requests found
......@@ -799,7 +799,7 @@ def run_restore_static(directory, ckpt_dir, out_file=None):
nn = SRCNN()
labels, preds = nn.run_restore(directory, ckpt_dir)
if out_file is not None:
np.save(out_file, [np.squeeze(labels), preds.argmax(axis=3)])
np.save(out_file, [np.squeeze(labels), preds.argmax(axis=3), preds[:,:,:,0], preds[:,:,:,1], preds[:,:,:,2]])
def run_evaluate_static(in_file, out_file, ckpt_dir):
......@@ -874,82 +874,58 @@ def run_evaluate_static(in_file, out_file, ckpt_dir):
return out_sr, hr_grd_a, hr_grd_b, 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]
from util.plot_cm import confusion_matrix_values
def analyze(file='/Users/tomrink/cld_opd_frac.npy'):
tup = np.load(file, allow_pickle=True)
lbls = tup[0]
pred = tup[1]
prob_0 = tup[2]
prob_1 = tup[3]
prob_2 = tup[4]
lbls = lbls[:, :, :, 0]
pred = pred[:, :, :, 0]
print('Total num pixels: ', lbls.size)
pred = pred.flatten()
pred = np.where(pred < 0.0, 0.0, pred)
lbls = lbls.flatten()
diff = pred - lbls
mae = (np.sum(np.abs(diff))) / diff.size
print('MAE: ', mae)
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)
pred = pred.flatten()
bin_ranges.append([30.0, 40.0])
bin_edges.append(30.0)
msk_0_1 = lbls != 2
msk_1_2 = lbls != 0
msk_0_2 = lbls != 1
bin_ranges.append([40.0, 60.0])
bin_edges.append(40.0)
lbls_0_1 = lbls[msk_0_1]
bin_ranges.append([60.0, 80.0])
bin_edges.append(60.0)
pred_0_1 = pred[msk_0_1]
pred_0_1 = np.where(pred_0_1 == 2, 1, pred_0_1)
bin_ranges.append([80.0, 100.0])
bin_edges.append(80.0)
# ----
lbls_1_2 = lbls[msk_1_2]
lbls_1_2 = np.where(lbls_1_2 == 1, 0, lbls_1_2)
lbls_1_2 = np.where(lbls_1_2 == 2, 1, lbls_1_2)
bin_ranges.append([100.0, 120.0])
bin_edges.append(100.0)
pred_1_2 = pred[msk_1_2]
pred_1_2 = np.where(pred_1_2 == 0, 1, pred_1_2)
pred_1_2 = np.where(pred_1_2 == 1, 0, pred_1_2)
pred_1_2 = np.where(pred_1_2 == 2, 1, pred_1_2)
bin_ranges.append([120.0, 140.0])
bin_edges.append(120.0)
# ----
lbls_0_2 = lbls[msk_0_2]
lbls_0_2 = np.where(lbls_0_2 == 0, 0, lbls_0_2)
lbls_0_2 = np.where(lbls_0_2 == 2, 1, lbls_0_2)
bin_ranges.append([140.0, 160.0])
bin_edges.append(140.0)
pred_0_2 = pred[msk_0_2]
pred_0_2 = np.where(pred_0_2 == 0, 0, pred_0_2)
pred_0_2 = np.where(pred_0_2 == 1, 1, pred_0_2)
pred_0_2 = np.where(pred_0_2 == 2, 1, pred_0_2)
bin_edges.append(160.0)
cm_0_1 = confusion_matrix_values(lbls_0_1, pred_0_1)
cm_1_2 = confusion_matrix_values(lbls_1_2, pred_1_2)
cm_0_2 = confusion_matrix_values(lbls_0_2, pred_0_2)
diff_by_value_bins = util.util.bin_data_by(diff, lbls, bin_ranges)
return cm_0_1, cm_1_2, cm_0_2
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__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment