Commit 3b6137be authored by Andrey Filippov's avatar Andrey Filippov

Implemented 2-stage inference network to be used with TP in Java

parent bcf427de
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -16,7 +16,7 @@ import sys ...@@ -16,7 +16,7 @@ import sys
import time import time
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
import qcstereo_functions as qsf import qcstereo_functions as qsf
#import xml.etree.ElementTree as ET #import xml.etree.ElementTree as ET
...@@ -53,8 +53,17 @@ TILE_SIDE, TILE_LAYERS, TWO_TRAINS, NET_ARCH1, NET_ARCH2 = [None]*5 ...@@ -53,8 +53,17 @@ TILE_SIDE, TILE_LAYERS, TWO_TRAINS, NET_ARCH1, NET_ARCH2 = [None]*5
ABSOLUTE_DISPARITY,SYM8_SUB, WLOSS_LAMBDA, SLOSS_LAMBDA, SLOSS_CLIP = [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 SPREAD_CONVERGENCE, INTER_CONVERGENCE, HOR_FLIP, DISP_DIFF_CAP, DISP_DIFF_SLOPE = [None]*5
CLUSTER_RADIUS,ABSOLUTE_DISPARITY = [None]*2 CLUSTER_RADIUS,ABSOLUTE_DISPARITY = [None]*2
FIGS_EXTENSIONS = ['png','pdf','svg']
#FIGS_ESXTENSIONS = ['png','pdf','svg']
EVAL_MODES = ["train","infer"]
FIGS_SAVESHOW = ['save','show']
globals().update(parameters) globals().update(parameters)
try:
FIGS_EXTENSIONS = globals()['FIGS_ESXTENSIONS'] # fixing typo in configs
except:
pass
#exit(0) #exit(0)
...@@ -98,6 +107,7 @@ TIGHT_HPAD = 1.0 ...@@ -98,6 +107,7 @@ TIGHT_HPAD = 1.0
TIGHT_WPAD = 1.0 TIGHT_WPAD = 1.0
FIGSIZE = [8.5,11.0] FIGSIZE = [8.5,11.0]
WOI_COLOR = "red" WOI_COLOR = "red"
TRANSPARENT = True # for export
#dbg_parameters #dbg_parameters
def get_fig_params(disparity_ranges): def get_fig_params(disparity_ranges):
...@@ -121,17 +131,30 @@ def get_fig_params(disparity_ranges): ...@@ -121,17 +131,30 @@ def get_fig_params(disparity_ranges):
fig_params = get_fig_params(dbg_parameters['disparity_ranges']) fig_params = get_fig_params(dbg_parameters['disparity_ranges'])
pass pass
figs = []
def setlimsxy(lim_xy): if not 'show' in FIGS_SAVESHOW:
plt.ioff()
for mode in ['train','infer']:
figs = []
ffiles = [] # no ext
def setlimsxy(lim_xy):
if not lim_xy is None: if not lim_xy is None:
plt.xlim(min(lim_xy[:2]),max(lim_xy[:2])) plt.xlim(min(lim_xy[:2]),max(lim_xy[:2]))
plt.ylim(max(lim_xy[2:]),min(lim_xy[2:])) plt.ylim(max(lim_xy[2:]),min(lim_xy[2:]))
for nfile, fpars in enumerate(fig_params): for nfile, fpars in enumerate(fig_params):
if not fpars is None: if not fpars is None:
data = qsf.result_npy_prepare(files['result'][nfile], ABSOLUTE_DISPARITY, fix_nan=True, insert_deltas=True) 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)
except:
print ("Image file does not exist:", img_file)
continue
for rng in fpars['ranges']: for subindex, rng in enumerate(fpars['ranges']):
lim_val = rng['lim_val'] lim_val = rng['lim_val']
lim_xy = rng['lim_xy'] lim_xy = rng['lim_xy']
fig = plt.figure(figsize=FIGSIZE) fig = plt.figure(figsize=FIGSIZE)
...@@ -139,7 +162,7 @@ for nfile, fpars in enumerate(fig_params): ...@@ -139,7 +162,7 @@ for nfile, fpars in enumerate(fig_params):
fig.suptitle(fpars['name']) fig.suptitle(fpars['name'])
ax_conf=plt.subplot(322) ax_conf=plt.subplot(322)
ax_conf.set_title("Ground truth confidence") ax_conf.set_title("Ground truth confidence")
# fig.suptitle("Groud truth confidence") # fig.suptitle("Groud truth confidence")
plt.imshow(data[...,GT_CONF], vmin=0, vmax=CONF_MAX, cmap='gray') plt.imshow(data[...,GT_CONF], vmin=0, vmax=CONF_MAX, cmap='gray')
if not lim_xy is None: if not lim_xy is None:
pass # show frame pass # show frame
...@@ -147,7 +170,7 @@ for nfile, fpars in enumerate(fig_params): ...@@ -147,7 +170,7 @@ for nfile, fpars in enumerate(fig_params):
ydata=[min(lim_xy[2:]),min(lim_xy[2:]),max(lim_xy[2:]),max(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) plt.plot(xdata,ydata,color=WOI_COLOR)
# setlimsxy(lim_xy) # setlimsxy(lim_xy)
plt.colorbar(orientation='vertical') # location='bottom') plt.colorbar(orientation='vertical') # location='bottom')
ax_gtd=plt.subplot(321) ax_gtd=plt.subplot(321)
...@@ -183,15 +206,58 @@ for nfile, fpars in enumerate(fig_params): ...@@ -183,15 +206,58 @@ for nfile, fpars in enumerate(fig_params):
plt.tight_layout(rect =[0,0,1,TIGHT_TOP], h_pad = TIGHT_HPAD, w_pad = TIGHT_WPAD) plt.tight_layout(rect =[0,0,1,TIGHT_TOP], h_pad = TIGHT_HPAD, w_pad = TIGHT_WPAD)
figs.append(fig) 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)
ffiles.append(fb_noext)
pass pass
#whow to allow adjustment before applying tight_layout? #whow to allow adjustment before applying tight_layout?
pass pass
for fig in figs: for fig in figs:
fig.tight_layout(rect =[0,0,1,TIGHT_TOP], h_pad = TIGHT_HPAD, w_pad = TIGHT_WPAD) fig.tight_layout(rect =[0,0,1,TIGHT_TOP], h_pad = TIGHT_HPAD, w_pad = TIGHT_WPAD)
plt.show()
if FIGS_EXTENSIONS and figs and 'save' in FIGS_SAVESHOW:
try:
print ("Creating output directory for figures: ",dirs['figures'])
os.makedirs(dirs['figures'])
except:
pass
pp=None
if 'pdf' in FIGS_EXTENSIONS:
if mode == 'infer':
pdf_path = os.path.join(dirs['figures'],"figures-infer.pdf")
else:
pdf_path = os.path.join(dirs['figures'],"figures-train.pdf")
pp= PdfPages(pdf_path)
for fb_noext, fig in zip(ffiles,figs):
for ext in FIGS_EXTENSIONS:
if ext == 'pdf':
pass
fig.savefig(pp,format='pdf')
else:
if mode == 'infer':
noext = fb_noext+'-infer'
else:
noext = fb_noext+'-train'
fig.savefig(
fname = os.path.join(dirs['figures'],noext+"."+ext),
transparent = TRANSPARENT,
)
pass
if pp:
pp.close()
if 'show' in FIGS_SAVESHOW:
plt.show()
#FIGS_ESXTENSIONS
#qsf.evaluateAllResults(result_files = files['result'], #qsf.evaluateAllResults(result_files = files['result'],
# absolute_disparity = ABSOLUTE_DISPARITY, # absolute_disparity = ABSOLUTE_DISPARITY,
......
This diff is collapsed.
This diff is collapsed.
...@@ -8,6 +8,21 @@ __email__ = "andrey@elphel.com" ...@@ -8,6 +8,21 @@ __email__ = "andrey@elphel.com"
import tensorflow as tf import tensorflow as tf
import tensorflow.contrib.slim as slim import tensorflow.contrib.slim as slim
NN_LAYOUTS = {0:[0, 0, 0, 32, 20, 16],
1:[0, 0, 0, 256, 128, 64],
2:[0, 128, 32, 32, 32, 16],
3:[0, 0, 40, 32, 20, 16],
4:[0, 0, 0, 0, 16, 16],
5:[0, 0, 64, 32, 32, 16],
6:[0, 0, 32, 16, 16, 16],
7:[0, 0, 64, 16, 16, 16],
8:[0, 0, 0, 64, 20, 16],
9:[0, 0, 256, 64, 32, 16],
10:[0, 256, 128, 64, 32, 16],
11:[0, 0, 0, 0, 64, 32],
12:[0, 0, 256, 128, 64, 32],
13:[0, 0, 0, 256, 128, 32],
}
def lrelu(x): def lrelu(x):
return tf.maximum(x*0.2,x) return tf.maximum(x*0.2,x)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment