def _select_evo(name): nd.evo = None for evo in _evolution_manager.evolutions(): nd.log('check', evo.name(), name) if evo.name() == name: nd.log('<<< determined current evolution: %s >>>' % name) nd.evo = evo if nd.evo is None: raise BaseException('evolution %s not found' % name)
def add_evolution(self, evolution): idx = len(self.evolutions()) evolution.set_index(idx) if evolution.name() is None: evolution.set_name('%02d__%s__%s' % (idx, evolution.training_dataset(), evolution.schedule().name())) evolution.make_folder() self._evolutions.append(evolution) ds_name = evolution.training_dataset() if isinstance(evolution.training_dataset(), dict): ds_name = '' for key in evolution.training_dataset(): if ds_name != '': ds_name += '_' ds_name += key nd.log('evolution <%s>: %s' % (evolution.name(), str(evolution)))
def get(self, full_name): for member in self._members: member_name = self._member_to_str(member) nd.log("mem: {} ".format(member_name)) if self.is_data(member) and member_name == full_name: return self[member] elif self.is_struct(member) and full_name.startswith( member_name) and (full_name[len(member_name)] in ['.', '[']): sub_struct = self[member] sub_name = full_name[len(member_name):] if sub_name.startswith('.'): sub_name = sub_name[1:] return sub_struct.get(sub_name) elif member_name == full_name: return self[member] raise KeyError
def make_graph(self, data, include_losses=False): # hypNet pred_config = nd.PredConfig() pred_config.add(nd.PredConfigId(type='flow_hyp', dir='fwd', offset=0, channels=2, scale=self._scale, array_length=self._num_hypotheses)) pred_config.add(nd.PredConfigId(type='iul_b_hyp_log', dir='fwd', offset=0, channels=2, scale=self._scale, array_length=self._num_hypotheses, mod_func=self._log_sigmoid)) nd.log('pred_config:') nd.log(pred_config) with nd.Scope('hypNet', shared_batchnorm=False, correlation_leaky_relu=True, **self.scope_args()): arch = Architecture_C( num_outputs=pred_config.total_channels(), disassembling_function=pred_config.disassemble, conv_upsample=True, loss_function= None, channel_factor=self._channel_factor, feature_channels=self._feature_channels ) out_hyp = arch.make_graph(data.img[0], data.img[1]) # mergeNet pred_config = nd.PredConfig() pred_config.add(nd.PredConfigId(type='flow', dir='fwd', offset=0, channels=2, scale=self._scale, dist=1)) pred_config.add(nd.PredConfigId(type='iul_b_log', dir='fwd', offset=0, channels=2, scale=self._scale, dist=1, mod_func=self.iul_b_log_sigmoid)) nd.log('pred_config:') nd.log(pred_config) hyps = [nd.ops.resample(hyp, reference=data.img[0], antialias=False, type='LINEAR') for hyp in [out_hyp.final.flow_hyp[0].fwd[i] for i in range(self._num_hypotheses)]] uncertainties = [nd.ops.resample(unc, reference=data.img[0], antialias=False, type='LINEAR') for unc in [out_hyp.final.iul_b_hyp_log[0].fwd[i] for i in range(self._num_hypotheses)]] img_warped = [nd.ops.warp(data.img[1], hyp) for hyp in hyps] with nd.Scope('mergeNet', shared_batchnorm=False, **self.scope_args()): input = nd.ops.concat([data.img[0]] + [data.img[1]] + hyps + uncertainties + img_warped) arch = Architecture_S( num_outputs=pred_config.total_channels(), disassembling_function=pred_config.disassemble, conv_upsample=True, loss_function= None, channel_factor=self._channel_factor ) out_merge = arch.make_graph(input) return out_merge
def make_graph(self, data, net_graph_constructor, divisor=64., scale=1.0): self._scale = scale self._width = data.width self._height = data.height self._temp_width = ceil(self._width*self._scale/divisor) * divisor self._temp_height = ceil(self._height*self._scale/divisor) * divisor self._rescale_coeff_x = self._width / self._temp_width self._rescale_coeff_y = self._height / self._temp_height nd.log('data:') nd.log(data) input = nd.Struct() data.map('img', self.input_image_resample, input) data.map('flow', self.input_resample_flow, input) data.map('disp', self.input_resample_disp, input) data.map('occ', self.input_resample_binary, input) data.map('mb', self.input_resample_binary, input) data.map('db', self.input_resample_binary, input) pred = net_graph_constructor(input) nd.log('pred:') nd.log(pred) if isinstance(pred, (tuple)): pred = pred[0] if isinstance(pred, (list)): output = [] for prediction in pred: out = nd.Struct() self.map_output(prediction.final, out) output.append(out) else: output = nd.Struct() self.map_output(pred.final, output) nd.log('output:') nd.log(output) return output
def make_graph(self, data, include_losses=True): pred_config = nd.PredConfig() pred_config.add( nd.PredConfigId(type='flow', dir='fwd', offset=0, channels=2, scale=self._scale)) pred_config.add( nd.PredConfigId(type='occ', dir='fwd', offset=0, channels=2, scale=self._scale)) nd.log('pred_config:') nd.log(pred_config) #### Net 1 #### with nd.Scope('net1', learn=False, **self.scope_args()): arch1 = Architecture_C( num_outputs=pred_config.total_channels(), disassembling_function=pred_config.disassemble, loss_function=None, conv_upsample=self._conv_upsample) out1 = arch1.make_graph(data.img[0], data.img[1]) #### Net 2 #### flow_fwd = out1.final.flow[0].fwd upsampled_flow_fwd = nd.ops.differentiable_resample( flow_fwd, reference=data.img[0]) warped = nd.ops.warp(data.img[1], upsampled_flow_fwd) # prepare data for second net occ_fwd = self.resample_occ(out1.final.occ[0].fwd, data.img[0]) input2 = nd.ops.concat(data.img[0], data.img[1], nd.ops.scale(upsampled_flow_fwd, 0.05), warped, occ_fwd) pred_config[0].mod_func = lambda x: nd.ops.add( x, nd.ops.resample( flow_fwd, reference=x, type='LINEAR', antialias=False)) pred_config[1].mod_func = lambda x: nd.ops.add( x, nd.ops.resample( occ_fwd, reference=x, type='LINEAR', antialias=False)) with nd.Scope('net2', learn=False, **self.scope_args()): arch2 = Architecture_S( num_outputs=pred_config.total_channels(), disassembling_function=pred_config.disassemble, loss_function=None, conv_upsample=self._conv_upsample) out2 = arch2.make_graph(input2) #### Net 3 #### flow_fwd = out2.final.flow[0].fwd upsampled_flow_fwd = nd.ops.differentiable_resample( flow_fwd, reference=data.img[0]) warped = nd.ops.warp(data.img[1], upsampled_flow_fwd) # prepare data for third net occ_fwd = self.resample_occ(out2.final.occ[0].fwd, data.img[0]) input3 = nd.ops.concat(data.img[0], data.img[1], nd.ops.scale(upsampled_flow_fwd, 0.05), warped, occ_fwd) pred_config.add( nd.PredConfigId(type='mb', dir='fwd', offset=0, channels=2, scale=self._scale)) pred_config[0].mod_func = lambda x: nd.ops.add( x, nd.ops.resample( flow_fwd, reference=x, type='LINEAR', antialias=False)) pred_config[1].mod_func = lambda x: nd.ops.add( x, nd.ops.resample( occ_fwd, reference=x, type='LINEAR', antialias=False)) with nd.Scope('net3', learn=True, **self.scope_args()): arch3 = Architecture_S( num_outputs=pred_config.total_channels(), disassembling_function=pred_config.disassemble, loss_function=None, conv_upsample=self._conv_upsample, exit_after=0, ) out3 = arch3.make_graph(input3, edge_features=data.img[0]) return out3