Loading explore_data15.py +14 −3 Original line number Diff line number Diff line Loading @@ -1755,7 +1755,7 @@ if __name__ == "__main__": test_corrs = [] #1527257933_150165-ML_DATA-32B-O-FZ0.05-MAIN-RND2.00000.tiff #/home/eyesis/x3d_data/data_sets/test_mlr32_18a/1527257933_150165/v04/mlr32_18c/1527257933_150165-ML_DATA-32B-O-FZ0.05-MAIN.tiff ''' test_sets = [ "/data_ssd/lwir_sets/lwir_test2/1562390202_933097/v01/ml32", # andrey /empty "/data_ssd/lwir_sets/lwir_test2/1562390225_269784/v01/ml32", # andrey /empty Loading @@ -1777,7 +1777,18 @@ if __name__ == "__main__": "/data_ssd/lwir_sets/lwir_test3/1562390409_661607/v01/ml32", # lena, 2 far moving cars "/data_ssd/lwir_sets/lwir_test3/1562390435_873048/v01/ml32", # 2 parked cars, lena "/data_ssd/lwir_sets/lwir_test3/1562390456_842237/v01/ml32", # near trees "/data_ssd/lwir_sets/lwir_test3/1562390460_261151/v01/ml32"] # near trees, olga "/data_ssd/lwir_sets/lwir_test3/1562390460_261151/v01/ml32", # near trees, olga ] ''' test_sets = [ "/data_ssd/lwir_sets/lwir_test6/1562390317_693673/v01/ml32", # andrey + olga "/data_ssd/lwir_sets/lwir_test6/1562390318_833313/v01/ml32", # andrey + olga "/data_ssd/lwir_sets/lwir_test6/1562390326_354823/v01/ml32", # andrey + olga "/data_ssd/lwir_sets/lwir_test6/1562390331_483132/v01/ml32", # andrey + olga "/data_ssd/lwir_sets/lwir_test6/1562390333_192523/v01/ml32", # lena ] #Parameters to generate neighbors data. Set radius to 0 to generate single-tile TEST_SAME_LENGTH_AS_TRAIN = False # True # make test to have same number of entries as train ones Loading explore_data16.py +20 −19 Original line number Diff line number Diff line Loading @@ -1657,14 +1657,15 @@ if __name__ == "__main__": test_corrs = [] test_sets = [ "/data_ssd/lwir_sets/lwir_test2/1562390202_933097/v01/ml32", # andrey /empty "/data_ssd/lwir_sets/lwir_test2/1562390225_269784/v01/ml32", # andrey /empty "/data_ssd/lwir_sets/lwir_test2/1562390225_839538/v01/ml32", # andrey /empty "/data_ssd/lwir_sets/lwir_test2/1562390243_047919/v01/ml32", # 2 trees "/data_ssd/lwir_sets/lwir_test2/1562390251_025390/v01/ml32", # empty space "/data_ssd/lwir_sets/lwir_test2/1562390257_977146/v01/ml32", # first 3 "/data_ssd/lwir_sets/lwir_test2/1562390260_370347/v01/ml32", # all 3 "/data_ssd/lwir_sets/lwir_test2/1562390260_940102/v01/ml32", # all 3 "/data_ssd/lwir_sets/lwir_test2/1562390202_933097/v01/ml32b", # andrey /empty "/data_ssd/lwir_sets/lwir_test2/1562390225_269784/v01/ml32b", # andrey /empty "/data_ssd/lwir_sets/lwir_test2/1562390225_839538/v01/ml32b", # andrey /empty "/data_ssd/lwir_sets/lwir_test2/1562390243_047919/v01/ml32b", # 2 trees "/data_ssd/lwir_sets/lwir_test6/1562390251_025390/v01/ml32b", # empty space "/data_ssd/lwir_sets/lwir_test6/1562390257_977146/v01/ml32b", # first 3 "/data_ssd/lwir_sets/lwir_test6/1562390260_370347/v01/ml32b", # all 3 "/data_ssd/lwir_sets/lwir_test2/1562390260_940102/v01/ml32b", # all 3 "/data_ssd/lwir_sets/lwir_test6/1562390317_693673/v01/ml32", # andrey + olga "/data_ssd/lwir_sets/lwir_test6/1562390318_833313/v01/ml32", # andrey + olga Loading @@ -1672,12 +1673,12 @@ if __name__ == "__main__": "/data_ssd/lwir_sets/lwir_test6/1562390331_483132/v01/ml32", # andrey + olga "/data_ssd/lwir_sets/lwir_test6/1562390333_192523/v01/ml32", # lena "/data_ssd/lwir_sets/lwir_test3/1562390402_254007/v01/ml32", # near moving car "/data_ssd/lwir_sets/lwir_test3/1562390407_382326/v01/ml32", # near moving car "/data_ssd/lwir_sets/lwir_test3/1562390409_661607/v01/ml32", # lena, 2 far moving cars "/data_ssd/lwir_sets/lwir_test3/1562390435_873048/v01/ml32", # 2 parked cars, lena "/data_ssd/lwir_sets/lwir_test3/1562390456_842237/v01/ml32", # near trees "/data_ssd/lwir_sets/lwir_test3/1562390460_261151/v01/ml32"] # near trees, olga "/data_ssd/lwir_sets/lwir_test6/1562390402_254007/v01/ml32b", # near moving car "/data_ssd/lwir_sets/lwir_test6/1562390407_382326/v01/ml32b", # near moving car "/data_ssd/lwir_sets/lwir_test6/1562390409_661607/v01/ml32b", # lena, 2 far moving cars "/data_ssd/lwir_sets/lwir_test6/1562390435_873048/v01/ml32b", # 2 parked cars, lena "/data_ssd/lwir_sets/lwir_test6/1562390456_842237/v01/ml32b", # near trees "/data_ssd/lwir_sets/lwir_test6/1562390460_261151/v01/ml32b"] # near trees, olga #Parameters to generate neighbors data. Set radius to 0 to generate single-tile TEST_SAME_LENGTH_AS_TRAIN = False # True # make test to have same number of entries as train ones Loading nn_ds_neibs31.py +1 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ __copyright__ = "Copyright 2018-2019, Elphel, Inc." __license__ = "GPL-3.0+" __email__ = "andrey@elphel.com" #python3 nn_ds_neibs31.py /data_ssd/lwir_sets/conf/qcstereo_lwir05.xml /data_ssd/lwir_sets/ #python3 nn_ds_neibs31.py /data_ssd/lwir_sets/conf/qcstereo_lwir21.xml /data_ssd/lwir_sets/ #tensorboard --logdir="nn_ds_neibs30_graph13-9RNSWLAM0.5SLAM0.1SCLP0.2_nG_nI_HF_CP0.3_S0.03" --port=7001 import os Loading nn_eval_lwir.py +140 −212 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ import sys import imagej_tiffwriter import time import imagej_tiff as ijt import matplotlib.pyplot as plt from matplotlib.backends.backend_pdf import PdfPages import qcstereo_functions as qsf Loading @@ -27,7 +27,8 @@ import numpy as np qsf.TIME_START = time.time() qsf.TIME_LAST = qsf.TIME_START IMG_WIDTH = 20 # 324 # tiles per image row Defined in config #IMG_WIDTH = 20 # 324 # tiles per image row Defined in config #IMG_HEIGHT = 15 # 324 # tiles per image row Defined in config DEBUG_LEVEL= 1 Loading @@ -41,6 +42,12 @@ try: except IndexError: root_dir = os.path.dirname(conf_file) try: modes = [sys.argv[3]] # train, infer except IndexError: modes = ['train'] print ("Configuration file: " + conf_file) parameters, dirs, files, dbg_parameters = qsf.parseXmlConfig(conf_file, root_dir) """ Loading @@ -53,6 +60,8 @@ if not "SLOSS_CLIP" in parameters: """ Defined in config file """ IMG_WIDTH = None # 20 # 324 # tiles per image row Defined in config IMG_HEIGHT = None # 15 # 324 # tiles per image row Defined in config TILE_SIDE, TILE_LAYERS, TWO_TRAINS, NET_ARCH1, NET_ARCH2 = [None]*5 ABSOLUTE_DISPARITY,SYM8_SUB, WLOSS_LAMBDA, SLOSS_LAMBDA, SLOSS_CLIP = [None]*5 SPREAD_CONVERGENCE, INTER_CONVERGENCE, HOR_FLIP, DISP_DIFF_CAP, DISP_DIFF_SLOPE = [None]*5 Loading Loading @@ -111,14 +120,19 @@ qsf.prepareFiles(dirs, files, suffix = SUFFIX) CONF_MAX = 0.7 ERR_AMPL = 0.3 ERR_AMPL = 0.4 # 0.3 TIGHT_TOP = 0.95 TIGHT_HPAD = 1.0 TIGHT_WPAD = 1.0 FIGSIZE = [8.5,11.0] WOI_COLOR = "red" X_COLOR = "grey" X_NEIBS = False TRANSPARENT = True # for export #dbg_parameters def get_fig_params(disparity_ranges): fig_params = [] Loading @@ -138,7 +152,14 @@ def get_fig_params(disparity_ranges): return fig_params #try: fig_params = get_fig_params(dbg_parameters['disparity_ranges']) #fig_params = get_fig_params(dbg_parameters['disparity_ranges']) extra_path = os.path.join(root_dir, dbg_parameters['extra']) eo_width = dbg_parameters['eo_params']['width'] eo_height = dbg_parameters['eo_params']['height'] eo_woi = dbg_parameters['eo_params']['woi'] # (x,y,width, height) eo_disparity_scale = 1.0/dbg_parameters['eo_params']['disparity_scale'] # 14.2 image_sets = dbg_parameters['extra_paths'] # list of dictionaries pass Loading @@ -162,10 +183,15 @@ index_gt = 2 index_gt_weight = 3 index_heur_err = 7 index_nn_err = 6 index_mm = 8 # max-min index_log = 9 index_bad = 10 index_num_neibs = 11 index_fgbg_sngl = 10 index_fgbg_neib = 11 index_mm = 23 # 8 # max-min index_log = 24 # 9 index_bad = 25 # 10 index_num_neibs = 26 # 11 index_fgbg = [index_fgbg_sngl,index_fgbg_neib][X_NEIBS] """ Debugging high 9-tile variations, removing error for all tiles with lower difference between max and min """ Loading @@ -181,7 +207,21 @@ if not 'show' in FIGS_SAVESHOW: #for mode in ['train','infer']: #for mode in ['infer']: for mode in ['train']: def cross_out( plt, cross_out_mask): height = cross_out_mask.shape[0] width = cross_out_mask.shape[1] for row in range (height): for col in range(width): if cross_out_mask[row,col]: xdata = [col-0.3, col+0.3] ydata = [row-0.3, row+0.3] plt.plot(xdata,ydata,color=X_COLOR) ydata = [row+0.3, row-0.3] plt.plot(xdata,ydata,color=X_COLOR) for mode in modes: # ['train']: figs = [] ffiles = [] # no ext def setlimsxy(lim_xy): Loading @@ -189,218 +229,106 @@ for mode in ['train']: plt.xlim(min(lim_xy[:2]),max(lim_xy[:2])) plt.ylim(max(lim_xy[2:]),min(lim_xy[2:])) cumul_weights = None for nfile, fpars in enumerate(fig_params): if not fpars is None: cmap_disp=plt.get_cmap('viridis') # ('cividis') cmap_diff=plt.get_cmap('coolwarm') #('seismic') # ('viridis') for nfile, img_pars in enumerate(image_sets): if not img_pars is None: img_file = files['result'][nfile] if mode == 'infer': img_file = img_file.replace('.npy','-infer.npy') """ try: # data,_ = qsf.result_npy_prepare(img_file, ABSOLUTE_DISPARITY, fix_nan=True, insert_deltas=True) # data,_ = qsf.result_npy_prepare(img_file, ABSOLUTE_DISPARITY, fix_nan=True, insert_deltas=3) data,labels = qsf.result_npy_prepare(img_file, ABSOLUTE_DISPARITY, fix_nan=True, insert_deltas=3) except: print ("Image file does not exist:", img_file) continue """ pass data,labels = qsf.result_npy_prepare(img_file, ABSOLUTE_DISPARITY, fix_nan=True, insert_deltas=3) if True: #TIFF_ONLY: print ("Processing image set: "+img_file) data,labels = qsf.result_npy_prepare(img_file, ABSOLUTE_DISPARITY, fix_nan=True, insert_deltas=3) cross_out_mask = data[...,index_fgbg] < 0.5 #data.shape = (15,20,27) # for subindex, rng in enumerate(fpars['ranges']): tiff_path = img_file.replace('.npy','-test.tiff') lim_val = img_pars['range'] # rng['lim_val'] lim_val[0] -= ERR_AMPL lim_xy = [-0.5, IMG_WIDTH - 0.5, -0.5, IMG_HEIGHT - 0.5] # rng['lim_xy'] data = data.transpose(2,0,1) print("Saving results to TIFF: "+tiff_path) imagej_tiffwriter.save(tiff_path,data,labels=labels) """ Calculate histograms """ err_heur2 = data[index_heur_err]*data[index_heur_err] err_nn2 = data[index_nn_err]* data[index_nn_err] diff_log2 = data[index_log]* data[index_log] weights = ( (data[index_gt] < max_disp) & (err_heur2 < max_target_err2) & (data[index_bad] < max_bad) & (data[index_gt_weight] >= min_strength) & (data[index_num_neibs] >= min_neibs)& #max_log_to_mm = 0.5 # difference between center average and center should be under this fraction of max-min (0 - disables feature) (data[index_log] < max_log_to_mm * np.sqrt(data[index_mm]) ) ).astype(data.dtype) # 0.0/1.1 #max_disp #max_target_err if use_gt_weights: weights *= data[index_gt_weight] mm = data[index_mm] weh = np.nan_to_num(weights*err_heur2) wen = np.nan_to_num(weights*err_nn2) wel = np.nan_to_num(weights*diff_log2) hist_weights,bin_vals = np.histogram(a=mm, bins = num_bins, range = (0.0, max_diff), weights = weights, density = False) hist_err_heur2,_ = np.histogram(a=mm, bins = num_bins, range = (0.0, max_diff), weights = weh, density = False) hist_err_nn2,_ = np.histogram(a=mm, bins = num_bins, range = (0.0, max_diff), weights = wen, density = False) hist_diff_log2,_ = np.histogram(a=mm, bins = num_bins, range = (0.0, max_diff), weights = wel, density = False) if cumul_weights is None: cumul_weights = hist_weights cumul_err_heur2 = hist_err_heur2 cumul_err_nn2 = hist_err_nn2 cumul_diff_log2 = hist_diff_log2 else: cumul_weights += hist_weights cumul_err_heur2 += hist_err_heur2 cumul_err_nn2 += hist_err_nn2 cumul_diff_log2 += hist_diff_log2 hist_err_heur2 = np.nan_to_num(hist_err_heur2/hist_weights) hist_err_nn2 = np.nan_to_num(hist_err_nn2/hist_weights) hist_gain2 = np.nan_to_num(hist_err_heur2/hist_err_nn2) hist_gain = np.sqrt(hist_gain2) hist_diff_log2 = np.nan_to_num(hist_diff_log2/hist_weights) print("hist_err_heur2", end = " ") print(np.sqrt(hist_err_heur2)) print("hist_err_nn2", end = " ") print(np.sqrt(hist_err_nn2)) print("hist_gain", end = " ") print(hist_gain) print("hist_diff_log2", end = " ") print(np.sqrt(hist_diff_log2)) if min_diff> 0.0: pass good = (mm > min_diff).astype(mm.dtype) good /= good # good - 1, bad - nan data[index_heur_err] *= good data[index_nn_err] *= good data = data.transpose(1,2,0) #start new image page fig = plt.figure(figsize=FIGSIZE) fig.canvas.set_window_title(img_pars['title']) fig.suptitle(img_pars['title']) if TIFF_ONLY: continue # Create EO DSI image # load tiff image img_ds_main = ijt.imagej_tiff(os.path.join(extra_path,img_pars['dsi_path'] )) ds_main = img_ds_main.image[...,img_pars['dsi_slice']] * eo_disparity_scale ds_main = np.maximum(ds_main, lim_val[0]) ds_main = np.minimum(ds_main, lim_val[1]) ax_conf=plt.subplot(322) ax_conf.set_title("Hi-res camera disparity map") plt.imshow(ds_main, vmin=lim_val[0], vmax=lim_val[1], cmap=cmap_disp) setlimsxy([-0.5, eo_width-0.5, -0.5, eo_height - 0.5]) if not eo_woi is None: pass # show frame xdata=[eo_woi['x'], eo_woi['x'] + eo_woi['width'], eo_woi['x'] + eo_woi['width'], eo_woi['x'], eo_woi['x']] ydata=[eo_woi['y'], eo_woi['y'], eo_woi['y'] + eo_woi['height'], eo_woi['y'] + eo_woi['height'], eo_woi['y']] plt.plot(xdata,ydata,color=WOI_COLOR) for subindex, rng in enumerate(fpars['ranges']): lim_val = rng['lim_val'] lim_xy = rng['lim_xy'] fig = plt.figure(figsize=FIGSIZE) fig.canvas.set_window_title(fpars['name']) fig.suptitle(fpars['name']) plt.colorbar(orientation='vertical') # location='bottom') ''' # Ground truth confidence - to be replaced ax_conf=plt.subplot(322) ax_conf.set_title("Ground truth confidence") # fig.suptitle("Groud truth confidence") plt.imshow(data[...,qsf.GT_CONF], vmin=0, vmax=CONF_MAX, cmap='gray') if not lim_xy is None: pass # show frame xdata=[min(lim_xy[:2]),max(lim_xy[:2]),max(lim_xy[:2]),min(lim_xy[:2]),min(lim_xy[:2])] ydata=[min(lim_xy[2:]),min(lim_xy[2:]),max(lim_xy[2:]),max(lim_xy[2:]),min(lim_xy[2:])] plt.plot(xdata,ydata,color=WOI_COLOR) # setlimsxy(lim_xy) plt.colorbar(orientation='vertical') # location='bottom') ''' ax_gtd=plt.subplot(321) ax_gtd.set_title("Ground truth disparity map") plt.imshow(data[...,qsf.GT_DISP], vmin=lim_val[0], vmax=lim_val[1]) plt.imshow(data[...,qsf.GT_DISP], vmin=lim_val[0], vmax=lim_val[1], cmap=cmap_disp) setlimsxy(lim_xy) cross_out(plt, cross_out_mask) plt.colorbar(orientation='vertical') # location='bottom') ax_hed=plt.subplot(323) ax_hed.set_title("Heuristic disparity map") plt.imshow(data[...,qsf.HEUR_NAN], vmin=lim_val[0], vmax=lim_val[1]) plt.imshow(data[...,qsf.HEUR_NAN], vmin=lim_val[0], vmax=lim_val[1], cmap=cmap_disp) setlimsxy(lim_xy) cross_out(plt, cross_out_mask) plt.colorbar(orientation='vertical') # location='bottom') ax_nnd=plt.subplot(325) ax_nnd.set_title("Network disparity output") plt.imshow(data[...,qsf.NN_NAN], vmin=lim_val[0], vmax=lim_val[1]) plt.imshow(data[...,qsf.NN_NAN], vmin=lim_val[0], vmax=lim_val[1], cmap=cmap_disp) setlimsxy(lim_xy) cross_out(plt, cross_out_mask) plt.colorbar(orientation='vertical') # location='bottom') ax_hee=plt.subplot(324) ax_hee.set_title("Heuristic disparity error") plt.imshow(data[...,qsf.HEUR_DIFF], vmin=-ERR_AMPL, vmax=ERR_AMPL) cross_out(plt, cross_out_mask) plt.imshow(data[...,qsf.HEUR_DIFF], vmin=-ERR_AMPL, vmax=ERR_AMPL, cmap=cmap_diff) setlimsxy(lim_xy) cross_out(plt, cross_out_mask) plt.colorbar(orientation='vertical') # location='bottom') ax_nne=plt.subplot(326) ax_nne.set_title("Network disparity error") plt.imshow(data[...,qsf.NN_DIFF], vmin=-ERR_AMPL, vmax=ERR_AMPL) plt.imshow(data[...,qsf.NN_DIFF], vmin=-ERR_AMPL, vmax=ERR_AMPL, cmap=cmap_diff) setlimsxy(lim_xy) cross_out(plt, cross_out_mask) plt.colorbar(orientation='vertical') # location='bottom') plt.tight_layout(rect =[0,0,1,TIGHT_TOP], h_pad = TIGHT_HPAD, w_pad = TIGHT_WPAD) figs.append(fig) fb_noext = os.path.splitext(os.path.basename(img_file))[0]# if subindex > 0: if subindex < 10: fb_noext+="abcdefghi"[subindex-1] else: fb_noext+="-"+str(subindex) # if subindex > 0: # if subindex < 10: # fb_noext+="abcdefghi"[subindex-1] # else: # fb_noext+="-"+str(subindex) ffiles.append(fb_noext) pass if True: cumul_err_heur2 = np.nan_to_num(cumul_err_heur2/cumul_weights) cumul_err_nn2 = np.nan_to_num(cumul_err_nn2/cumul_weights) cumul_gain2 = np.nan_to_num(cumul_err_heur2/cumul_err_nn2) cumul_gain = np.sqrt(cumul_gain2) cumul_diff_log2 = np.nan_to_num(cumul_diff_log2/cumul_weights) print("cumul_weights", end = " ") print(cumul_weights) print("cumul_err_heur", end = " ") print(np.sqrt(cumul_err_heur2)) print("cumul_err_nn", end = " ") print(np.sqrt(cumul_err_nn2)) print("cumul_gain", end = " ") print(cumul_gain) print("cumul_diff_log2", end = " ") print(np.sqrt(cumul_diff_log2)) fig, ax1 = plt.subplots() ax1.set_xlabel('3x3 tiles ground truth disparity max-min (pix)') ax1.set_ylabel('RMSE\n(pix)', color='black', rotation='horizontal') ax1.yaxis.set_label_coords(-0.045,0.92) ax1.plot(bin_vals[0:-1], np.sqrt(cumul_err_nn2), 'tab:red',label="network disparity RMSE") ax1.plot(bin_vals[0:-1], np.sqrt(cumul_err_heur2), 'tab:green',label="heuristic disparity RMSE") ax1.plot(bin_vals[0:-1], np.sqrt(cumul_diff_log2), 'tab:cyan',label="ground truth LoG") ax1.tick_params(axis='y', labelcolor='black') ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis ax2.set_ylabel('weight', color='black', rotation='horizontal') # we already handled the x-label with ax1 ax2.yaxis.set_label_coords(1.06,1.0) ax2.plot(bin_vals[0:-1], cumul_weights,color='grey',dashes=[6, 2],label='weights = n_tiles * gt_confidence') ax1.legend(loc="upper left", bbox_to_anchor=(0.2,1.0)) ax2.legend(loc="lower right", bbox_to_anchor=(1.0,0.1)) """ fig = plt.figure(figsize=FIGSIZE) fig.canvas.set_window_title('Cumulative') fig.suptitle('Difference to GT') # ax_conf=plt.subplot(322) ax_conf=plt.subplot(211) ax_conf.set_title("RMS vs max9-min9") plt.plot(bin_vals[0:-1], np.sqrt(cumul_err_heur2),'red', bin_vals[0:-1], np.sqrt(cumul_err_nn2),'green', bin_vals[0:-1], np.sqrt(cumul_diff_log2),'blue') figs.append(fig) ffiles.append('cumulative') ax_conf=plt.subplot(212) ax_conf.set_title("weights vs max9-min9") plt.plot(bin_vals[0:-1], cumul_weights,'black') """ figs.append(fig) ffiles.append('cumulative') pass #bin_vals[0:-1] # fig.suptitle("Groud truth confidence") # #how to allow adjustment before applying tight_layout? Loading Loading
explore_data15.py +14 −3 Original line number Diff line number Diff line Loading @@ -1755,7 +1755,7 @@ if __name__ == "__main__": test_corrs = [] #1527257933_150165-ML_DATA-32B-O-FZ0.05-MAIN-RND2.00000.tiff #/home/eyesis/x3d_data/data_sets/test_mlr32_18a/1527257933_150165/v04/mlr32_18c/1527257933_150165-ML_DATA-32B-O-FZ0.05-MAIN.tiff ''' test_sets = [ "/data_ssd/lwir_sets/lwir_test2/1562390202_933097/v01/ml32", # andrey /empty "/data_ssd/lwir_sets/lwir_test2/1562390225_269784/v01/ml32", # andrey /empty Loading @@ -1777,7 +1777,18 @@ if __name__ == "__main__": "/data_ssd/lwir_sets/lwir_test3/1562390409_661607/v01/ml32", # lena, 2 far moving cars "/data_ssd/lwir_sets/lwir_test3/1562390435_873048/v01/ml32", # 2 parked cars, lena "/data_ssd/lwir_sets/lwir_test3/1562390456_842237/v01/ml32", # near trees "/data_ssd/lwir_sets/lwir_test3/1562390460_261151/v01/ml32"] # near trees, olga "/data_ssd/lwir_sets/lwir_test3/1562390460_261151/v01/ml32", # near trees, olga ] ''' test_sets = [ "/data_ssd/lwir_sets/lwir_test6/1562390317_693673/v01/ml32", # andrey + olga "/data_ssd/lwir_sets/lwir_test6/1562390318_833313/v01/ml32", # andrey + olga "/data_ssd/lwir_sets/lwir_test6/1562390326_354823/v01/ml32", # andrey + olga "/data_ssd/lwir_sets/lwir_test6/1562390331_483132/v01/ml32", # andrey + olga "/data_ssd/lwir_sets/lwir_test6/1562390333_192523/v01/ml32", # lena ] #Parameters to generate neighbors data. Set radius to 0 to generate single-tile TEST_SAME_LENGTH_AS_TRAIN = False # True # make test to have same number of entries as train ones Loading
explore_data16.py +20 −19 Original line number Diff line number Diff line Loading @@ -1657,14 +1657,15 @@ if __name__ == "__main__": test_corrs = [] test_sets = [ "/data_ssd/lwir_sets/lwir_test2/1562390202_933097/v01/ml32", # andrey /empty "/data_ssd/lwir_sets/lwir_test2/1562390225_269784/v01/ml32", # andrey /empty "/data_ssd/lwir_sets/lwir_test2/1562390225_839538/v01/ml32", # andrey /empty "/data_ssd/lwir_sets/lwir_test2/1562390243_047919/v01/ml32", # 2 trees "/data_ssd/lwir_sets/lwir_test2/1562390251_025390/v01/ml32", # empty space "/data_ssd/lwir_sets/lwir_test2/1562390257_977146/v01/ml32", # first 3 "/data_ssd/lwir_sets/lwir_test2/1562390260_370347/v01/ml32", # all 3 "/data_ssd/lwir_sets/lwir_test2/1562390260_940102/v01/ml32", # all 3 "/data_ssd/lwir_sets/lwir_test2/1562390202_933097/v01/ml32b", # andrey /empty "/data_ssd/lwir_sets/lwir_test2/1562390225_269784/v01/ml32b", # andrey /empty "/data_ssd/lwir_sets/lwir_test2/1562390225_839538/v01/ml32b", # andrey /empty "/data_ssd/lwir_sets/lwir_test2/1562390243_047919/v01/ml32b", # 2 trees "/data_ssd/lwir_sets/lwir_test6/1562390251_025390/v01/ml32b", # empty space "/data_ssd/lwir_sets/lwir_test6/1562390257_977146/v01/ml32b", # first 3 "/data_ssd/lwir_sets/lwir_test6/1562390260_370347/v01/ml32b", # all 3 "/data_ssd/lwir_sets/lwir_test2/1562390260_940102/v01/ml32b", # all 3 "/data_ssd/lwir_sets/lwir_test6/1562390317_693673/v01/ml32", # andrey + olga "/data_ssd/lwir_sets/lwir_test6/1562390318_833313/v01/ml32", # andrey + olga Loading @@ -1672,12 +1673,12 @@ if __name__ == "__main__": "/data_ssd/lwir_sets/lwir_test6/1562390331_483132/v01/ml32", # andrey + olga "/data_ssd/lwir_sets/lwir_test6/1562390333_192523/v01/ml32", # lena "/data_ssd/lwir_sets/lwir_test3/1562390402_254007/v01/ml32", # near moving car "/data_ssd/lwir_sets/lwir_test3/1562390407_382326/v01/ml32", # near moving car "/data_ssd/lwir_sets/lwir_test3/1562390409_661607/v01/ml32", # lena, 2 far moving cars "/data_ssd/lwir_sets/lwir_test3/1562390435_873048/v01/ml32", # 2 parked cars, lena "/data_ssd/lwir_sets/lwir_test3/1562390456_842237/v01/ml32", # near trees "/data_ssd/lwir_sets/lwir_test3/1562390460_261151/v01/ml32"] # near trees, olga "/data_ssd/lwir_sets/lwir_test6/1562390402_254007/v01/ml32b", # near moving car "/data_ssd/lwir_sets/lwir_test6/1562390407_382326/v01/ml32b", # near moving car "/data_ssd/lwir_sets/lwir_test6/1562390409_661607/v01/ml32b", # lena, 2 far moving cars "/data_ssd/lwir_sets/lwir_test6/1562390435_873048/v01/ml32b", # 2 parked cars, lena "/data_ssd/lwir_sets/lwir_test6/1562390456_842237/v01/ml32b", # near trees "/data_ssd/lwir_sets/lwir_test6/1562390460_261151/v01/ml32b"] # near trees, olga #Parameters to generate neighbors data. Set radius to 0 to generate single-tile TEST_SAME_LENGTH_AS_TRAIN = False # True # make test to have same number of entries as train ones Loading
nn_ds_neibs31.py +1 −1 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ __copyright__ = "Copyright 2018-2019, Elphel, Inc." __license__ = "GPL-3.0+" __email__ = "andrey@elphel.com" #python3 nn_ds_neibs31.py /data_ssd/lwir_sets/conf/qcstereo_lwir05.xml /data_ssd/lwir_sets/ #python3 nn_ds_neibs31.py /data_ssd/lwir_sets/conf/qcstereo_lwir21.xml /data_ssd/lwir_sets/ #tensorboard --logdir="nn_ds_neibs30_graph13-9RNSWLAM0.5SLAM0.1SCLP0.2_nG_nI_HF_CP0.3_S0.03" --port=7001 import os Loading
nn_eval_lwir.py +140 −212 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ import sys import imagej_tiffwriter import time import imagej_tiff as ijt import matplotlib.pyplot as plt from matplotlib.backends.backend_pdf import PdfPages import qcstereo_functions as qsf Loading @@ -27,7 +27,8 @@ import numpy as np qsf.TIME_START = time.time() qsf.TIME_LAST = qsf.TIME_START IMG_WIDTH = 20 # 324 # tiles per image row Defined in config #IMG_WIDTH = 20 # 324 # tiles per image row Defined in config #IMG_HEIGHT = 15 # 324 # tiles per image row Defined in config DEBUG_LEVEL= 1 Loading @@ -41,6 +42,12 @@ try: except IndexError: root_dir = os.path.dirname(conf_file) try: modes = [sys.argv[3]] # train, infer except IndexError: modes = ['train'] print ("Configuration file: " + conf_file) parameters, dirs, files, dbg_parameters = qsf.parseXmlConfig(conf_file, root_dir) """ Loading @@ -53,6 +60,8 @@ if not "SLOSS_CLIP" in parameters: """ Defined in config file """ IMG_WIDTH = None # 20 # 324 # tiles per image row Defined in config IMG_HEIGHT = None # 15 # 324 # tiles per image row Defined in config TILE_SIDE, TILE_LAYERS, TWO_TRAINS, NET_ARCH1, NET_ARCH2 = [None]*5 ABSOLUTE_DISPARITY,SYM8_SUB, WLOSS_LAMBDA, SLOSS_LAMBDA, SLOSS_CLIP = [None]*5 SPREAD_CONVERGENCE, INTER_CONVERGENCE, HOR_FLIP, DISP_DIFF_CAP, DISP_DIFF_SLOPE = [None]*5 Loading Loading @@ -111,14 +120,19 @@ qsf.prepareFiles(dirs, files, suffix = SUFFIX) CONF_MAX = 0.7 ERR_AMPL = 0.3 ERR_AMPL = 0.4 # 0.3 TIGHT_TOP = 0.95 TIGHT_HPAD = 1.0 TIGHT_WPAD = 1.0 FIGSIZE = [8.5,11.0] WOI_COLOR = "red" X_COLOR = "grey" X_NEIBS = False TRANSPARENT = True # for export #dbg_parameters def get_fig_params(disparity_ranges): fig_params = [] Loading @@ -138,7 +152,14 @@ def get_fig_params(disparity_ranges): return fig_params #try: fig_params = get_fig_params(dbg_parameters['disparity_ranges']) #fig_params = get_fig_params(dbg_parameters['disparity_ranges']) extra_path = os.path.join(root_dir, dbg_parameters['extra']) eo_width = dbg_parameters['eo_params']['width'] eo_height = dbg_parameters['eo_params']['height'] eo_woi = dbg_parameters['eo_params']['woi'] # (x,y,width, height) eo_disparity_scale = 1.0/dbg_parameters['eo_params']['disparity_scale'] # 14.2 image_sets = dbg_parameters['extra_paths'] # list of dictionaries pass Loading @@ -162,10 +183,15 @@ index_gt = 2 index_gt_weight = 3 index_heur_err = 7 index_nn_err = 6 index_mm = 8 # max-min index_log = 9 index_bad = 10 index_num_neibs = 11 index_fgbg_sngl = 10 index_fgbg_neib = 11 index_mm = 23 # 8 # max-min index_log = 24 # 9 index_bad = 25 # 10 index_num_neibs = 26 # 11 index_fgbg = [index_fgbg_sngl,index_fgbg_neib][X_NEIBS] """ Debugging high 9-tile variations, removing error for all tiles with lower difference between max and min """ Loading @@ -181,7 +207,21 @@ if not 'show' in FIGS_SAVESHOW: #for mode in ['train','infer']: #for mode in ['infer']: for mode in ['train']: def cross_out( plt, cross_out_mask): height = cross_out_mask.shape[0] width = cross_out_mask.shape[1] for row in range (height): for col in range(width): if cross_out_mask[row,col]: xdata = [col-0.3, col+0.3] ydata = [row-0.3, row+0.3] plt.plot(xdata,ydata,color=X_COLOR) ydata = [row+0.3, row-0.3] plt.plot(xdata,ydata,color=X_COLOR) for mode in modes: # ['train']: figs = [] ffiles = [] # no ext def setlimsxy(lim_xy): Loading @@ -189,218 +229,106 @@ for mode in ['train']: plt.xlim(min(lim_xy[:2]),max(lim_xy[:2])) plt.ylim(max(lim_xy[2:]),min(lim_xy[2:])) cumul_weights = None for nfile, fpars in enumerate(fig_params): if not fpars is None: cmap_disp=plt.get_cmap('viridis') # ('cividis') cmap_diff=plt.get_cmap('coolwarm') #('seismic') # ('viridis') for nfile, img_pars in enumerate(image_sets): if not img_pars is None: img_file = files['result'][nfile] if mode == 'infer': img_file = img_file.replace('.npy','-infer.npy') """ try: # data,_ = qsf.result_npy_prepare(img_file, ABSOLUTE_DISPARITY, fix_nan=True, insert_deltas=True) # data,_ = qsf.result_npy_prepare(img_file, ABSOLUTE_DISPARITY, fix_nan=True, insert_deltas=3) data,labels = qsf.result_npy_prepare(img_file, ABSOLUTE_DISPARITY, fix_nan=True, insert_deltas=3) except: print ("Image file does not exist:", img_file) continue """ pass data,labels = qsf.result_npy_prepare(img_file, ABSOLUTE_DISPARITY, fix_nan=True, insert_deltas=3) if True: #TIFF_ONLY: print ("Processing image set: "+img_file) data,labels = qsf.result_npy_prepare(img_file, ABSOLUTE_DISPARITY, fix_nan=True, insert_deltas=3) cross_out_mask = data[...,index_fgbg] < 0.5 #data.shape = (15,20,27) # for subindex, rng in enumerate(fpars['ranges']): tiff_path = img_file.replace('.npy','-test.tiff') lim_val = img_pars['range'] # rng['lim_val'] lim_val[0] -= ERR_AMPL lim_xy = [-0.5, IMG_WIDTH - 0.5, -0.5, IMG_HEIGHT - 0.5] # rng['lim_xy'] data = data.transpose(2,0,1) print("Saving results to TIFF: "+tiff_path) imagej_tiffwriter.save(tiff_path,data,labels=labels) """ Calculate histograms """ err_heur2 = data[index_heur_err]*data[index_heur_err] err_nn2 = data[index_nn_err]* data[index_nn_err] diff_log2 = data[index_log]* data[index_log] weights = ( (data[index_gt] < max_disp) & (err_heur2 < max_target_err2) & (data[index_bad] < max_bad) & (data[index_gt_weight] >= min_strength) & (data[index_num_neibs] >= min_neibs)& #max_log_to_mm = 0.5 # difference between center average and center should be under this fraction of max-min (0 - disables feature) (data[index_log] < max_log_to_mm * np.sqrt(data[index_mm]) ) ).astype(data.dtype) # 0.0/1.1 #max_disp #max_target_err if use_gt_weights: weights *= data[index_gt_weight] mm = data[index_mm] weh = np.nan_to_num(weights*err_heur2) wen = np.nan_to_num(weights*err_nn2) wel = np.nan_to_num(weights*diff_log2) hist_weights,bin_vals = np.histogram(a=mm, bins = num_bins, range = (0.0, max_diff), weights = weights, density = False) hist_err_heur2,_ = np.histogram(a=mm, bins = num_bins, range = (0.0, max_diff), weights = weh, density = False) hist_err_nn2,_ = np.histogram(a=mm, bins = num_bins, range = (0.0, max_diff), weights = wen, density = False) hist_diff_log2,_ = np.histogram(a=mm, bins = num_bins, range = (0.0, max_diff), weights = wel, density = False) if cumul_weights is None: cumul_weights = hist_weights cumul_err_heur2 = hist_err_heur2 cumul_err_nn2 = hist_err_nn2 cumul_diff_log2 = hist_diff_log2 else: cumul_weights += hist_weights cumul_err_heur2 += hist_err_heur2 cumul_err_nn2 += hist_err_nn2 cumul_diff_log2 += hist_diff_log2 hist_err_heur2 = np.nan_to_num(hist_err_heur2/hist_weights) hist_err_nn2 = np.nan_to_num(hist_err_nn2/hist_weights) hist_gain2 = np.nan_to_num(hist_err_heur2/hist_err_nn2) hist_gain = np.sqrt(hist_gain2) hist_diff_log2 = np.nan_to_num(hist_diff_log2/hist_weights) print("hist_err_heur2", end = " ") print(np.sqrt(hist_err_heur2)) print("hist_err_nn2", end = " ") print(np.sqrt(hist_err_nn2)) print("hist_gain", end = " ") print(hist_gain) print("hist_diff_log2", end = " ") print(np.sqrt(hist_diff_log2)) if min_diff> 0.0: pass good = (mm > min_diff).astype(mm.dtype) good /= good # good - 1, bad - nan data[index_heur_err] *= good data[index_nn_err] *= good data = data.transpose(1,2,0) #start new image page fig = plt.figure(figsize=FIGSIZE) fig.canvas.set_window_title(img_pars['title']) fig.suptitle(img_pars['title']) if TIFF_ONLY: continue # Create EO DSI image # load tiff image img_ds_main = ijt.imagej_tiff(os.path.join(extra_path,img_pars['dsi_path'] )) ds_main = img_ds_main.image[...,img_pars['dsi_slice']] * eo_disparity_scale ds_main = np.maximum(ds_main, lim_val[0]) ds_main = np.minimum(ds_main, lim_val[1]) ax_conf=plt.subplot(322) ax_conf.set_title("Hi-res camera disparity map") plt.imshow(ds_main, vmin=lim_val[0], vmax=lim_val[1], cmap=cmap_disp) setlimsxy([-0.5, eo_width-0.5, -0.5, eo_height - 0.5]) if not eo_woi is None: pass # show frame xdata=[eo_woi['x'], eo_woi['x'] + eo_woi['width'], eo_woi['x'] + eo_woi['width'], eo_woi['x'], eo_woi['x']] ydata=[eo_woi['y'], eo_woi['y'], eo_woi['y'] + eo_woi['height'], eo_woi['y'] + eo_woi['height'], eo_woi['y']] plt.plot(xdata,ydata,color=WOI_COLOR) for subindex, rng in enumerate(fpars['ranges']): lim_val = rng['lim_val'] lim_xy = rng['lim_xy'] fig = plt.figure(figsize=FIGSIZE) fig.canvas.set_window_title(fpars['name']) fig.suptitle(fpars['name']) plt.colorbar(orientation='vertical') # location='bottom') ''' # Ground truth confidence - to be replaced ax_conf=plt.subplot(322) ax_conf.set_title("Ground truth confidence") # fig.suptitle("Groud truth confidence") plt.imshow(data[...,qsf.GT_CONF], vmin=0, vmax=CONF_MAX, cmap='gray') if not lim_xy is None: pass # show frame xdata=[min(lim_xy[:2]),max(lim_xy[:2]),max(lim_xy[:2]),min(lim_xy[:2]),min(lim_xy[:2])] ydata=[min(lim_xy[2:]),min(lim_xy[2:]),max(lim_xy[2:]),max(lim_xy[2:]),min(lim_xy[2:])] plt.plot(xdata,ydata,color=WOI_COLOR) # setlimsxy(lim_xy) plt.colorbar(orientation='vertical') # location='bottom') ''' ax_gtd=plt.subplot(321) ax_gtd.set_title("Ground truth disparity map") plt.imshow(data[...,qsf.GT_DISP], vmin=lim_val[0], vmax=lim_val[1]) plt.imshow(data[...,qsf.GT_DISP], vmin=lim_val[0], vmax=lim_val[1], cmap=cmap_disp) setlimsxy(lim_xy) cross_out(plt, cross_out_mask) plt.colorbar(orientation='vertical') # location='bottom') ax_hed=plt.subplot(323) ax_hed.set_title("Heuristic disparity map") plt.imshow(data[...,qsf.HEUR_NAN], vmin=lim_val[0], vmax=lim_val[1]) plt.imshow(data[...,qsf.HEUR_NAN], vmin=lim_val[0], vmax=lim_val[1], cmap=cmap_disp) setlimsxy(lim_xy) cross_out(plt, cross_out_mask) plt.colorbar(orientation='vertical') # location='bottom') ax_nnd=plt.subplot(325) ax_nnd.set_title("Network disparity output") plt.imshow(data[...,qsf.NN_NAN], vmin=lim_val[0], vmax=lim_val[1]) plt.imshow(data[...,qsf.NN_NAN], vmin=lim_val[0], vmax=lim_val[1], cmap=cmap_disp) setlimsxy(lim_xy) cross_out(plt, cross_out_mask) plt.colorbar(orientation='vertical') # location='bottom') ax_hee=plt.subplot(324) ax_hee.set_title("Heuristic disparity error") plt.imshow(data[...,qsf.HEUR_DIFF], vmin=-ERR_AMPL, vmax=ERR_AMPL) cross_out(plt, cross_out_mask) plt.imshow(data[...,qsf.HEUR_DIFF], vmin=-ERR_AMPL, vmax=ERR_AMPL, cmap=cmap_diff) setlimsxy(lim_xy) cross_out(plt, cross_out_mask) plt.colorbar(orientation='vertical') # location='bottom') ax_nne=plt.subplot(326) ax_nne.set_title("Network disparity error") plt.imshow(data[...,qsf.NN_DIFF], vmin=-ERR_AMPL, vmax=ERR_AMPL) plt.imshow(data[...,qsf.NN_DIFF], vmin=-ERR_AMPL, vmax=ERR_AMPL, cmap=cmap_diff) setlimsxy(lim_xy) cross_out(plt, cross_out_mask) plt.colorbar(orientation='vertical') # location='bottom') plt.tight_layout(rect =[0,0,1,TIGHT_TOP], h_pad = TIGHT_HPAD, w_pad = TIGHT_WPAD) figs.append(fig) fb_noext = os.path.splitext(os.path.basename(img_file))[0]# if subindex > 0: if subindex < 10: fb_noext+="abcdefghi"[subindex-1] else: fb_noext+="-"+str(subindex) # if subindex > 0: # if subindex < 10: # fb_noext+="abcdefghi"[subindex-1] # else: # fb_noext+="-"+str(subindex) ffiles.append(fb_noext) pass if True: cumul_err_heur2 = np.nan_to_num(cumul_err_heur2/cumul_weights) cumul_err_nn2 = np.nan_to_num(cumul_err_nn2/cumul_weights) cumul_gain2 = np.nan_to_num(cumul_err_heur2/cumul_err_nn2) cumul_gain = np.sqrt(cumul_gain2) cumul_diff_log2 = np.nan_to_num(cumul_diff_log2/cumul_weights) print("cumul_weights", end = " ") print(cumul_weights) print("cumul_err_heur", end = " ") print(np.sqrt(cumul_err_heur2)) print("cumul_err_nn", end = " ") print(np.sqrt(cumul_err_nn2)) print("cumul_gain", end = " ") print(cumul_gain) print("cumul_diff_log2", end = " ") print(np.sqrt(cumul_diff_log2)) fig, ax1 = plt.subplots() ax1.set_xlabel('3x3 tiles ground truth disparity max-min (pix)') ax1.set_ylabel('RMSE\n(pix)', color='black', rotation='horizontal') ax1.yaxis.set_label_coords(-0.045,0.92) ax1.plot(bin_vals[0:-1], np.sqrt(cumul_err_nn2), 'tab:red',label="network disparity RMSE") ax1.plot(bin_vals[0:-1], np.sqrt(cumul_err_heur2), 'tab:green',label="heuristic disparity RMSE") ax1.plot(bin_vals[0:-1], np.sqrt(cumul_diff_log2), 'tab:cyan',label="ground truth LoG") ax1.tick_params(axis='y', labelcolor='black') ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis ax2.set_ylabel('weight', color='black', rotation='horizontal') # we already handled the x-label with ax1 ax2.yaxis.set_label_coords(1.06,1.0) ax2.plot(bin_vals[0:-1], cumul_weights,color='grey',dashes=[6, 2],label='weights = n_tiles * gt_confidence') ax1.legend(loc="upper left", bbox_to_anchor=(0.2,1.0)) ax2.legend(loc="lower right", bbox_to_anchor=(1.0,0.1)) """ fig = plt.figure(figsize=FIGSIZE) fig.canvas.set_window_title('Cumulative') fig.suptitle('Difference to GT') # ax_conf=plt.subplot(322) ax_conf=plt.subplot(211) ax_conf.set_title("RMS vs max9-min9") plt.plot(bin_vals[0:-1], np.sqrt(cumul_err_heur2),'red', bin_vals[0:-1], np.sqrt(cumul_err_nn2),'green', bin_vals[0:-1], np.sqrt(cumul_diff_log2),'blue') figs.append(fig) ffiles.append('cumulative') ax_conf=plt.subplot(212) ax_conf.set_title("weights vs max9-min9") plt.plot(bin_vals[0:-1], cumul_weights,'black') """ figs.append(fig) ffiles.append('cumulative') pass #bin_vals[0:-1] # fig.suptitle("Groud truth confidence") # #how to allow adjustment before applying tight_layout? Loading