コード例 #1
0
    def communicate(self, scene, visualize=False, max_level=-1, delimit_chunks=False):
        all_landmarks = []
        all_relations = []

        for scene_lmk in scene.landmarks.values():
            all_landmarks.append(scene_lmk)

            representations = [scene_lmk.representation]
            representations.extend(scene_lmk.representation.get_alt_representations())

            for representation in representations:
                all_landmarks.extend(representation.get_landmarks(max_level))

        for rset in [DistanceRelationSet,ContainmentRelationSet, OrientationRelationSet]:
            all_relations.extend(rset.relations)

        sampled_landmark = choice(all_landmarks)
        sampled_relation = choice(all_relations)
        perspective = self.get_head_on_viewpoint(sampled_landmark)
        self.set_orientations(sampled_landmark, perspective)

        trajector = self.sample_point_trajector( scene.landmarks['table'].representation.get_geometry().bounding_box,
                                                 sampled_relation,
                                                 perspective,
                                                 sampled_landmark)

        print sampled_landmark, self.get_landmark_probability( sampled_landmark, all_landmarks, trajector )
        print sampled_relation, self.get_relation_probability( sampled_relation, trajector, scene.get_bounding_box(), perspective, sampled_landmark, step=0.1)

        sampled_relation = sampled_relation(perspective, sampled_landmark, trajector)
        description = str(trajector) + '; ' + language_generator.describe(perspective, trajector, sampled_landmark, sampled_relation, delimit_chunks)
        print description

        if visualize: self.visualize(scene, trajector, perspective, sampled_landmark, sampled_relation, description, 0.1)
コード例 #2
0
ファイル: speaker.py プロジェクト: echan3/bolt
    def demo(self, poi, scene):

        # Sentence 1
        # [0.25562221863528939, 1.0, 3.9120230054287899, Scene(3), table, <landmark.RectangleRepresentation>,
        #    m_surf, <relations.on object at 0x35cb350>, ['on the middle of the table']]
        '''
        sampled_landmark = scene.landmarks['table'].representation.landmarks['ll_corner']
        head_on = self.get_head_on_viewpoint(sampled_landmark)
        relset = DistanceRelationSet
        sampled_relation = relset.relations[0](head_on,sampled_landmark,poi)
        print 'distance',sampled_landmark.distance_to(poi)
        print 'probability', sampled_relation.is_applicable()
        description = str(poi) + '; ' + language_generator.describe(head_on, sampled_landmark, sampled_relation)
        print description
        self.visualize(scene, poi, head_on, sampled_landmark, sampled_relation, description, step=0.1)
        '''

        sampled_landmark = scene.landmarks['obj2'].representation.landmarks['r_edge']
        head_on = self.get_head_on_viewpoint(sampled_landmark)
        relset = OrientationRelationSet
        sampled_relation = relset.relations[0](head_on,sampled_landmark,poi)
        print 'distance',sampled_landmark.distance_to(poi)
        print 'probability', sampled_relation.is_applicable()
        description = str(poi) + '; ' + language_generator.describe(head_on, sampled_landmark, sampled_relation)
        print description
        self.visualize(scene, poi, head_on, sampled_landmark, sampled_relation, description, step=0.1)
コード例 #3
0
    def describe(self, trajector, scene, visualize=False, max_level=-1, delimit_chunks=False):

        sampled_landmark, sampled_relation, head_on = self.sample_meaning(trajector, scene, max_level)

        description = str(trajector.representation.middle) + '; ' + language_generator.describe(head_on, trajector, sampled_landmark, sampled_relation, delimit_chunks)
        print description

        if visualize: self.visualize(scene, trajector, head_on, sampled_landmark, sampled_relation, description, 0.01)
        return description
コード例 #4
0
ファイル: speaker.py プロジェクト: echan3/bolt
    def describe(self, poi, scene, visualize=False, max_level=-1, delimit_chunks=False):
        scenes = scene.get_child_scenes(poi) + [scene]

        all_landmarks = []

        for s in scenes:
            for scene_lmk in s.landmarks.values():
                all_landmarks.append([s, scene_lmk])

                representations = [scene_lmk.representation]
                representations.extend(scene_lmk.representation.get_alt_representations())

                for representation in representations:
                    for lmk in representation.get_landmarks(max_level):
                        all_landmarks.append([s, lmk])

        sceness, landmarks = zip( *all_landmarks )

        sampled_landmark, sl_prob, sl_ent = self.sample_landmark( landmarks, poi )
        print '   ',sampled_landmark, sl_prob, sl_ent

        # relset = choice([DistanceRelationSet,ContainmentRelationSet, OrientationRelationSet])
        # index = relset.sample_landmark(landmarks, poi)

        # sampled_scene = sceness[index]
        # sampled_landmark = landmarks[index]
        head_on = self.get_head_on_viewpoint(sampled_landmark)
        # self.set_orientations(sampled_landmark, head_on)
        # sampled_relation = relset.sample_relation(head_on, sampled_landmark, poi)

        self.set_orientations(sampled_landmark, head_on)

        sampled_relation, sr_prob, sr_ent = self.sample_relation( poi, scene.get_bounding_box(), head_on, sampled_landmark, step=0.1 )
        print '   ',sampled_relation, sr_prob, sr_ent
        sampled_relation = sampled_relation( head_on, sampled_landmark, poi )

        description = str(poi) + '; ' + language_generator.describe(head_on, sampled_landmark, sampled_relation, delimit_chunks)
        print description

        if visualize: self.visualize(sampled_scene, poi, head_on, sampled_landmark, sampled_relation, description, 0.1)