Loading autocnet/io/db/utils.py +8 −6 Original line number Original line Diff line number Diff line Loading @@ -13,6 +13,8 @@ log = logging.getLogger(__name__) @retry() @retry() def update_measures(ncg, session, measures_iterable_to_update): def update_measures(ncg, session, measures_iterable_to_update): if not measures_iterable_to_update: return with ncg.session_scope() if ncg is not None else nullcontext(session) as session: with ncg.session_scope() if ncg is not None else nullcontext(session) as session: stmt = Measures.__table__.update().\ stmt = Measures.__table__.update().\ where(Measures.__table__.c.id == bindparam('_id')).\ where(Measures.__table__.c.id == bindparam('_id')).\ Loading @@ -29,7 +31,7 @@ def update_measures(ncg, session, measures_iterable_to_update): @retry() @retry() def ignore_measures(ncg, session, measures_iterable_to_ignore, chooser): def ignore_measures(ncg, session, measures_iterable_to_ignore, chooser): with ncg.session_scope() if ncg is not None else nullcontext(session) as session: with ncg.session_scope() if ncg is not None else nullcontext(session) as session: measures_to_set_false = [{'_id':i} for i in measures_to_set_false] measures_to_set_false = [{'_id':i} for i in measures_iterable_to_ignore] # Set ignore=True measures that failed # Set ignore=True measures that failed stmt = Measures.__table__.update().\ stmt = Measures.__table__.update().\ where(Measures.__table__.c.id == bindparam('_id')).\ where(Measures.__table__.c.id == bindparam('_id')).\ Loading @@ -38,7 +40,7 @@ def ignore_measures(ncg, session, measures_iterable_to_ignore, chooser): session.execute(stmt, measures_to_set_false) session.execute(stmt, measures_to_set_false) return return #@retry(wait_time=30) @retry(wait_time=30) def get_nodes_for_overlap(ncg, session, overlap): def get_nodes_for_overlap(ncg, session, overlap): # If an NCG is passed, instantiate a session off the NCG, else just pass the session through # If an NCG is passed, instantiate a session off the NCG, else just pass the session through ids = tuple([i for i in overlap.intersections]) ids = tuple([i for i in overlap.intersections]) Loading @@ -58,17 +60,17 @@ def get_nodes_for_overlap(ncg, session, overlap): @retry(wait_time=30) @retry(wait_time=30) def get_nodes_for_measures(ncg, session, measures): def get_nodes_for_measures(ncg, session, measures): nodes = {} nodes = {} with ncg.session_scope() if ncg is not None else nullcontext(session) as session: imageids = tuple([measure.imageid for measure in measures]) imageids = tuple([measure.imageid for measure in measures]) with ncg.session_scope() if ncg is not None else nullcontext(session) as session: results = session.query(Images).filter(Images.id.in_(imageids)).all() results = session.query(Images).filter(Images.id.in_(imageids)).all() for res in results: for res in results: nn = NetworkNode(node_id=res.imageid, nn = NetworkNode(node_id=res.id, image_name=res.name, image_path=res.path, image_path=res.path, cam_type=res.cam_type, cam_type=res.cam_type, dem=res.dem, dem=res.dem, dem_type=res.dem_type) dem_type=res.dem_type) nodes[res.imageid] = nn nodes[res.id] = nn return nodes return nodes @retry(wait_time=30) @retry(wait_time=30) Loading autocnet/matcher/subpixel.py +8 −4 Original line number Original line Diff line number Diff line Loading @@ -1050,6 +1050,9 @@ def decider(measures, tol=0.6): of meaure ids to be ignored beause theu fail the consensus of meaure ids to be ignored beause theu fail the consensus building approach building approach """ """ #TODO: This is super janky. I had to add imageid above, int he func, to the by_id # list, and then again to the else statement at the end. This is way to hard # to extend with new attributes. by_id = defaultdict(list) by_id = defaultdict(list) measures_to_set_false = [] measures_to_set_false = [] for m in measures: for m in measures: Loading @@ -1064,7 +1067,8 @@ def decider(measures, tol=0.6): m['template_metric'], m['template_metric'], baseline_mi, baseline_mi, baseline_corr, baseline_corr, m['template_shift']]) m['template_shift'], m['imageid']]) else: else: measures_to_set_false.append(m['id']) measures_to_set_false.append(m['id']) Loading Loading @@ -1093,7 +1097,8 @@ def decider(measures, tol=0.6): 'template_shift': best_measure[6], 'template_shift': best_measure[6], 'choosername': choosername, 'choosername': choosername, 'ignore':False, 'ignore':False, 'best_parameter_index': best_cost} 'best_parameter_index': best_cost, 'imageid': best_measure[7]} measures_to_update.append(m) measures_to_update.append(m) # A measure could have one bad regitration and get set false, if a different parameter set passed, # A measure could have one bad regitration and get set false, if a different parameter set passed, # remove from the set false list. # remove from the set false list. Loading Loading @@ -1257,7 +1262,7 @@ def smart_register_point(point, measure_results, node_cache = subpixel_register_point_smart(point, session, ncg=ncg, parameters=parameters, **shared_kwargs) measure_results, node_cache = subpixel_register_point_smart(point, session, ncg=ncg, parameters=parameters, **shared_kwargs) measures_to_update, measures_to_set_false = decider(measure_results) measures_to_update, measures_to_set_false = decider(measure_results) log.info(f'Found {len(measures_to_update)} measures that found subpixel registration consensus. Running validation now...') log.info(f'Found {len(measures_to_update)} measures that found subpixel registration consensus.') # Validate that the new position has consensus # Validate that the new position has consensus for measure in measures_to_update: for measure in measures_to_update: reprojection_distances = validate_candidate_measure(point, measure, node_cache, parameters=parameters, **shared_kwargs) reprojection_distances = validate_candidate_measure(point, measure, node_cache, parameters=parameters, **shared_kwargs) Loading @@ -1269,7 +1274,6 @@ def smart_register_point(point, for measure in measures_to_update: for measure in measures_to_update: measure['_id'] = measure.pop('id', None) measure['_id'] = measure.pop('id', None) # Update the measures that passed and failed registration # Update the measures that passed and failed registration update_measures(ncg, session, measures_to_update) update_measures(ncg, session, measures_to_update) ignore_measures(ncg, session, measures_to_set_false, shared_kwargs['chooser']) ignore_measures(ncg, session, measures_to_set_false, shared_kwargs['chooser']) Loading Loading
autocnet/io/db/utils.py +8 −6 Original line number Original line Diff line number Diff line Loading @@ -13,6 +13,8 @@ log = logging.getLogger(__name__) @retry() @retry() def update_measures(ncg, session, measures_iterable_to_update): def update_measures(ncg, session, measures_iterable_to_update): if not measures_iterable_to_update: return with ncg.session_scope() if ncg is not None else nullcontext(session) as session: with ncg.session_scope() if ncg is not None else nullcontext(session) as session: stmt = Measures.__table__.update().\ stmt = Measures.__table__.update().\ where(Measures.__table__.c.id == bindparam('_id')).\ where(Measures.__table__.c.id == bindparam('_id')).\ Loading @@ -29,7 +31,7 @@ def update_measures(ncg, session, measures_iterable_to_update): @retry() @retry() def ignore_measures(ncg, session, measures_iterable_to_ignore, chooser): def ignore_measures(ncg, session, measures_iterable_to_ignore, chooser): with ncg.session_scope() if ncg is not None else nullcontext(session) as session: with ncg.session_scope() if ncg is not None else nullcontext(session) as session: measures_to_set_false = [{'_id':i} for i in measures_to_set_false] measures_to_set_false = [{'_id':i} for i in measures_iterable_to_ignore] # Set ignore=True measures that failed # Set ignore=True measures that failed stmt = Measures.__table__.update().\ stmt = Measures.__table__.update().\ where(Measures.__table__.c.id == bindparam('_id')).\ where(Measures.__table__.c.id == bindparam('_id')).\ Loading @@ -38,7 +40,7 @@ def ignore_measures(ncg, session, measures_iterable_to_ignore, chooser): session.execute(stmt, measures_to_set_false) session.execute(stmt, measures_to_set_false) return return #@retry(wait_time=30) @retry(wait_time=30) def get_nodes_for_overlap(ncg, session, overlap): def get_nodes_for_overlap(ncg, session, overlap): # If an NCG is passed, instantiate a session off the NCG, else just pass the session through # If an NCG is passed, instantiate a session off the NCG, else just pass the session through ids = tuple([i for i in overlap.intersections]) ids = tuple([i for i in overlap.intersections]) Loading @@ -58,17 +60,17 @@ def get_nodes_for_overlap(ncg, session, overlap): @retry(wait_time=30) @retry(wait_time=30) def get_nodes_for_measures(ncg, session, measures): def get_nodes_for_measures(ncg, session, measures): nodes = {} nodes = {} with ncg.session_scope() if ncg is not None else nullcontext(session) as session: imageids = tuple([measure.imageid for measure in measures]) imageids = tuple([measure.imageid for measure in measures]) with ncg.session_scope() if ncg is not None else nullcontext(session) as session: results = session.query(Images).filter(Images.id.in_(imageids)).all() results = session.query(Images).filter(Images.id.in_(imageids)).all() for res in results: for res in results: nn = NetworkNode(node_id=res.imageid, nn = NetworkNode(node_id=res.id, image_name=res.name, image_path=res.path, image_path=res.path, cam_type=res.cam_type, cam_type=res.cam_type, dem=res.dem, dem=res.dem, dem_type=res.dem_type) dem_type=res.dem_type) nodes[res.imageid] = nn nodes[res.id] = nn return nodes return nodes @retry(wait_time=30) @retry(wait_time=30) Loading
autocnet/matcher/subpixel.py +8 −4 Original line number Original line Diff line number Diff line Loading @@ -1050,6 +1050,9 @@ def decider(measures, tol=0.6): of meaure ids to be ignored beause theu fail the consensus of meaure ids to be ignored beause theu fail the consensus building approach building approach """ """ #TODO: This is super janky. I had to add imageid above, int he func, to the by_id # list, and then again to the else statement at the end. This is way to hard # to extend with new attributes. by_id = defaultdict(list) by_id = defaultdict(list) measures_to_set_false = [] measures_to_set_false = [] for m in measures: for m in measures: Loading @@ -1064,7 +1067,8 @@ def decider(measures, tol=0.6): m['template_metric'], m['template_metric'], baseline_mi, baseline_mi, baseline_corr, baseline_corr, m['template_shift']]) m['template_shift'], m['imageid']]) else: else: measures_to_set_false.append(m['id']) measures_to_set_false.append(m['id']) Loading Loading @@ -1093,7 +1097,8 @@ def decider(measures, tol=0.6): 'template_shift': best_measure[6], 'template_shift': best_measure[6], 'choosername': choosername, 'choosername': choosername, 'ignore':False, 'ignore':False, 'best_parameter_index': best_cost} 'best_parameter_index': best_cost, 'imageid': best_measure[7]} measures_to_update.append(m) measures_to_update.append(m) # A measure could have one bad regitration and get set false, if a different parameter set passed, # A measure could have one bad regitration and get set false, if a different parameter set passed, # remove from the set false list. # remove from the set false list. Loading Loading @@ -1257,7 +1262,7 @@ def smart_register_point(point, measure_results, node_cache = subpixel_register_point_smart(point, session, ncg=ncg, parameters=parameters, **shared_kwargs) measure_results, node_cache = subpixel_register_point_smart(point, session, ncg=ncg, parameters=parameters, **shared_kwargs) measures_to_update, measures_to_set_false = decider(measure_results) measures_to_update, measures_to_set_false = decider(measure_results) log.info(f'Found {len(measures_to_update)} measures that found subpixel registration consensus. Running validation now...') log.info(f'Found {len(measures_to_update)} measures that found subpixel registration consensus.') # Validate that the new position has consensus # Validate that the new position has consensus for measure in measures_to_update: for measure in measures_to_update: reprojection_distances = validate_candidate_measure(point, measure, node_cache, parameters=parameters, **shared_kwargs) reprojection_distances = validate_candidate_measure(point, measure, node_cache, parameters=parameters, **shared_kwargs) Loading @@ -1269,7 +1274,6 @@ def smart_register_point(point, for measure in measures_to_update: for measure in measures_to_update: measure['_id'] = measure.pop('id', None) measure['_id'] = measure.pop('id', None) # Update the measures that passed and failed registration # Update the measures that passed and failed registration update_measures(ncg, session, measures_to_update) update_measures(ncg, session, measures_to_update) ignore_measures(ncg, session, measures_to_set_false, shared_kwargs['chooser']) ignore_measures(ncg, session, measures_to_set_false, shared_kwargs['chooser']) Loading