def fromYaml(yamlData): entireText, esdcsYaml = yamlData['command'] try: yamlGroundings = yamlData.get('objectGroundings') if yamlGroundings != None: g = [ groundings.fromYaml(grounding) for grounding in yamlGroundings ] else: g = None groundingIsCorrect = yamlData.get('groundingIsCorrect') source = yamlData.get("source") if 'context' in yamlData: context = Context.fromYaml(yamlData['context']) else: context = None return Annotation( yamlData['assignmentId'], esdcIo.fromYaml(entireText, esdcsYaml, use_ids=True), g, groundingIsCorrect, groundings.PhysicalObject.fromYaml(yamlData.get('agent')), context, source) except: print "couldn't make esdcs", entireText raise
def load(self, context, cf_obj, factor): self.cf_obj = cf_obj self.candidateModel.setData(cf_obj.factor_to_cost[factor], cf_obj) self.factorCandidateTable.selectRow(0) if context == None: context = Context.empty_context() self.contextWindow.setContext(context)
def __init__(self, parent=None): self.parent = parent QtOpenGL.QGLWidget.__init__(self, parent) self.setMouseTracking(True) self.yRotDeg = 0.0 self.camera_xyz = na.array([10, 10, 10]) self.camera_rpy = na.array([0, 0, 0]) self._selected_groundings = [] self._highlighted_groundings = {} self.groundingFilter = lambda x: True self.placeOnObjectFilter = lambda x: True self.clearModes() self.placeHeight = 0.1 self.setContext(Context.empty_context(), updateGL=False)
def generate_path_heat_map(esdcs, cf, output_fname=None, title=None): path_esdc = esdcs[0] landmark_esdc = path_esdc.l[0] agent = PhysicalObject(Prism.from_points_xy( tp([(-1, -1), (1, -1), (1, 1), (-1, 1)]), 0, 2), tags=("robot", ), lcmId=-1) landmark = PhysicalObject(Prism.from_points_xy( tp([(9, -1), (10, -1), (10, 1), (9, 1)]), 0, 2), tags=("square", ), lcmId=3) context = Context.from_groundings([agent, landmark]) print 'path', path_esdc gggs = gggs_from_esdc_group(esdcs) ggg = gggs[0] context.agent = agent ggg.context = context path_factor = ggg.esdc_to_factor(path_esdc) path_node = ggg.node_for_esdc(path_esdc) landmark_node = ggg.node_for_esdc(landmark_esdc) ggg.set_evidence_for_node(landmark_node, [landmark]) probs, xstart, ystart = path_probabilities(cf, path_factor, path_node, ggg, -5, 20, -10, 10, 1) print "starting draw" draw(probs, -5, 20, -10, 10, xstart, ystart, agent, landmark, output_fname=output_fname, title=esdcs.entireText)
def selectResult(self): print "selecting result" result = self.resultsModel.selectedEntry() self.commandText.setText(result.esdc.text) highlightTextLabelESDCs(self.commandText, result.obs.sdcs) self.featureModel.setData(result.crf, result.obs) if result.obs.annotation != None: context = Context.from_groundings(result.obs.annotation.groundings) self.contextWindow.setContext(context) if result.obs.factor != None: groundings = [] for n in result.obs.factor.nodes: if n.is_gamma: groundings.extend(result.obs.ggg.evidence_for_node(n)) self.contextWindow.highlightGroundings(groundings) cm = self.resultsModel.confusionMatrix() self.accuracyLabel.setText(cm.accuracy_string()) self.precisionLabel.setText(cm.precision_string()) self.recallLabel.setText(cm.recall_string())
def selectAnnotation(self): print "selecting annotation" entry = self.annotationModel.selectedData() annotation = entry.annotation if len(annotation.context.groundings) == 0: new_context = Context.from_groundings(annotation.groundings) self.contextWindow.setContext(new_context) else: self.contextWindow.setContext(annotation.context) self.contextModel.setData(annotation.context.groundings) self.drawWithoutGroundings() self.esdcModel.setData(annotation.esdcs) self.esdcTreeView.expandAll() self.esdcList = sorted([e for e in annotation.esdcs.flattenedEsdcs #if annotation.getGroundings(e) != [] and e.type == "PLACE" if e.type in ["EVENT", "OBJECT", "PLACE", "PATH"] #if e.type in ["OBJECT", "PLACE"] ], key=lambda esdc: esdc.range[0]) #self.esdcList = [e for e in annotation.esdcs] if len(self.esdcList) > 0: print "selecting first esdc", self.esdcList[0] self.esdcModel.selectEsdc(self.esdcList[0]) self.entireText = annotation.entireText #paths = self.path_segmenter.segment_path(annotation.agent.path) #self.pathSegmentsModel.setData(paths) #paths = self.large_path_segmenter.segment_path(annotation.agent.path) #self.largePathSegmentsModel.setData(paths) #self.pathSegmentsTable.selectRow(0) self.annotationFnameEdit.setText(annotation.fname)
def main(): import basewindow app = basewindow.makeApp() win = MainWindow() obj1 = PhysicalObject(Prism(tp([(0, 0), (1, 0), (1, 1), (0, 1)]), 0, 3), ["tires"], path=Path([0, 1, 2], tp([(3, 3, 0, 0), (3, 3, 0, math.pi / 4), (4, 4, 1, math.pi / 4)]))) obj2 = PhysicalObject(Prism(tp([(2, 2), (3, 2), (3, 3), (2, 3)]), 0, 3), ["boxes"], path=Path([0, 1, 2], tp([(3, 3, 0, 0), (3, 3, 0, math.pi / 4), (4, 4, 1, math.pi / 4)]))) obj3 = PhysicalObject( Prism(tp([(5, 5), (10, 5), (10, 10), (5, 10)]), 0, 3), ["truck"]) context = Context([obj1, obj2, obj3], []) win.show() win.setContext(context) sys.exit(app.exec_())
def to_context(self): if use_physical_object == False: return Context([], []) return Context([i.phyObj for i in self.table.contains], [])
def main(argv): app = basewindow.makeApp() parser = OptionParser() parser.add_option("--model-filename", dest="model_fname", help="CRF Filename", metavar="FILE") parser.add_option("--use-rrt", dest="use_rrt", help="Use RRT?") parser.add_option("--limits", dest="limits", help="Browser axis limits", metavar="FILE") parser.add_option("--state-type", dest="state_type", help="State or Agent Type", metavar="FILE") parser.add_option("--merging-mode", dest="merging_mode", default="merge_none") parser.add_option("--start-command", dest="start_command", help="Initial Command", default=None) parser.add_option("--start-state-file", dest="start_state_fname", help="Initial state file", default=None) parser.add_option("--start-context-file", dest="start_context_fname", help="Initial context file", default=None) parser.add_option("--search-depth", dest="search_depth", type="int", default=2) parser.add_option("--beam-width", dest="beam_width", type="int", default=2) parser.add_option("--beam-width-event", dest="beam_width_event", type="int", default=2) (options, args) = parser.parse_args() useRrt = False cf = CostFnCrf.from_mallet(options.model_fname) #cf_constant = cost_function_constant.CostFunction(cf.lccrf.dataset) taskPlanner = nodeSearch.BeamSearch(cf, useRrt=useRrt) limits = [float(x) for x in options.limits.split(",")] wnd = MainWindow(taskPlanner=taskPlanner, limits=limits, merging_mode=options.merging_mode, start_command=options.start_command) wnd.searchDepthBox.setValue(options.search_depth) wnd.beamWidthBox.setValue(options.beam_width) wnd.beamWidthEventBox.setValue(options.beam_width_event) state_type = state_type_from_name(options.state_type) if options.start_state_fname != None: start_state = pickle_util.load(options.start_state_fname) elif options.start_context_fname: start_context = Context.fromYaml( yaml.load(open(options.start_context_fname))) start_state = state_type.from_context(start_context) else: start_state = state_type.init_state() wnd.setState(start_state) wnd.show() wnd.selectEsdcExtractor() wnd.followCommand() app.exec_()
def loadContext(self): fname = QFileDialog.getOpenFileName(self) context = Context.fromYaml(yaml.load(open(fname)))
def to_context(self): objects = [ self.getGroundableById(gid) for gid in self.getObjectsSet() ] + [self.agent] places = [self.getGroundableById(gid) for gid in self.getPlacesSet()] return Context(objects, places)
def __init__(self, assignmentId, esdcs, objectGroundings=None, groundingIsCorrect=None, agent=None, context=None, esdcSource=None): """ The ith grounding is mapped to the ith ESDC in breadth first traverse order. """ self.assignmentId = assignmentId self.id = assignmentId self.entireText = esdcs.entireText self.esdcs = esdcs self.flattenedEsdcs = self.esdcs.flattenedEsdcs if objectGroundings == None: objectGroundings = [[] for esdc in self.flattenedEsdcs] ##### hack part 1 of 3: add in extra fields if esdcs have been modified after annotating # for i in range(len(self.flattenedEsdcs) - len(objectGroundings)): # objectGroundings.append([]) # if len(self.flattenedEsdcs) < len(objectGroundings): # objectGroundings = objectGroundings[:len(self.flattenedEsdcs)] ##### end hack part 1 if not len(objectGroundings) == len(self.flattenedEsdcs): print "len groundings", len(objectGroundings) print "len esdcs ", len(self.flattenedEsdcs) print "esdcs" for e in self.flattenedEsdcs: print e print "text", self.entireText print "esdcs", self.esdcs raise ValueError( "Object groundings must be same size as esdc list.") for o in objectGroundings: assert isinstance(o, list) self.esdcToGroundings = dict(zip(self.flattenedEsdcs, objectGroundings)) if groundingIsCorrect == None: groundingIsCorrect = [None for esdc in self.flattenedEsdcs] ##### hack part 2 of 3: add in extra fields if esdcs have been modified after annotating # for i in range(len(self.flattenedEsdcs) - len(groundingIsCorrect)): # groundingIsCorrect.append(None) # if len(self.flattenedEsdcs) < len(groundingIsCorrect): # groundingIsCorrect = groundingIsCorrect[:len(self.flattenedEsdcs)] ##### end hack part 2 assert len(groundingIsCorrect) == len(self.flattenedEsdcs), \ (len(groundingIsCorrect), len(self.flattenedEsdcs)) self.esdcToGroundingIsCorrect = dict( zip(self.flattenedEsdcs, groundingIsCorrect)) ##### hack part 3 of 3: add in extra fields if esdcs have been modified after annotating # for i in range(len(self.flattenedEsdcs) - len(esdcSource)): # esdcSource.append(None) # if len(self.flattenedEsdcs) < len(esdcSource): # esdcSource = esdcSource[:len(self.flattenedEsdcs)] ##### end hack part 3 if esdcSource == None or esdcSource == [] or all( [e == None for e in esdcSource]): esdcSource = [None for esdc in self.flattenedEsdcs] assert len(esdcSource) == len(self.flattenedEsdcs), \ (len(esdcSource), len(self.flattenedEsdcs)) self.esdcToSource = dict(zip(self.flattenedEsdcs, esdcSource)) self.agent = agent self.priorAnnotation = None #if this is an annotation for a sequential ESDC, stores previous annotation if context == None: self.context = Context.from_groundings(chain(*objectGroundings)) else: self.context = context if self.context.agent == None: self.context.agent = self.agent elif self.agent == None: self.agent = self.context.agent else: #assert self.context.agent == self.agent, (self.context.agent, self.agent) pass self.fname = None self.checkRep()
def toContext(self): return Context.from_groundings(self.groundableDict.values())
def to_context(self): return Context.from_groundings(self.groundings)