示例#1
0
 def __init__(self, is_site):
     # load classifier
     if (is_site):
         self.model = SiteModel(
             "light_classification/models/frozen_inference_graph.pb")
     else:
         self.model = SimModel()
示例#2
0
def run():
    from sim_model import SimModel
    from sim_array import SimArray

    pstudy = SimArray(sim_model=SimModel())
    pstudy_view = SimArrayView(model=pstudy)
    pstudy_view.configure_traits()
示例#3
0
 def __init__(self, scenario):
     if scenario == "sim":
         self.model = SimModel()
     else:
         # self.model = RealModel("light_classification/models/tl_model")
         self.model = RealModel(
             "light_classification/models/frozen_inference_graph.pb")
 def __init__(self, scenario):
     if scenario == "sim":
         self.model = SimModel()
     else:
         # self.model = RealModel("light_classification/models/tl_model")
         self.model = RealModel(
             "light_classification/frozen_models/faster_rcnn_resnet101_coco_2018_01_28/frozen_inference_graph.pb"
         )
示例#5
0
 def __init__(self, is_sim):
     self.is_sim = is_sim
     if is_sim:
         self.model = SimModel()
     else:
         self.threshold = THRESHOLD
         self.graph = self.load_graph(GRAPH_PATH_SIM)
         self.image_tensor = self.graph.get_tensor_by_name('image_tensor:0')
         self.detect_boxes = self.graph.get_tensor_by_name(
             'detection_boxes:0')
         self.detect_scores = self.graph.get_tensor_by_name(
             'detection_scores:0')
         self.detect_classes = self.graph.get_tensor_by_name(
             'detection_classes:0')
         self.num_detections = self.graph.get_tensor_by_name(
             'num_detections:0')
         self.sess = tf.Session(graph=self.graph)
示例#6
0
def run():
    from sim_model import SimModel
    sim_array = SimArray(sim_model=SimModel())
    print sim_array.levels2run[:, 0, 0, 0]
    print sim_array[:, 0, 0, 0]
    print sim_array.run_table[0]
    print 'array_content', sim_array.output_array[0, 0, 0, 0, :]
    sim_array.clear_cache()
    print 'array_content', sim_array.output_array[0, 0, 0, 0, :]
    sim_array.configure_traits()
示例#7
0
class TLClassifier(object):
    def __init__(self, is_site):
        # load classifier
        if (is_site):
            self.model = SiteModel(
                "light_classification/models/frozen_inference_graph.pb")
        else:
            self.model = SimModel()

    def get_classification(self, image):
        """Determines the color of the traffic light in the image

        Args:
            image (cv::Mat): image containing the traffic light

        Returns:
            int: ID of traffic light color (specified in styx_msgs/TrafficLight)

        """
        # implement light color prediction
        return self.model.predict(image)
示例#8
0
    #                   A trait is regarded as Factor if it specifies
    #                   a set of levels in form ps_levels = True.
    # - get_sim_outputs()   as instances of SimOut class
    #                   defining the name and order of outputs
    # - peval()          method returning a vector of results
    #                   the order of outputs is prescribed by the
    #                   specification given in the get_outputs() method
    #
    # Here we just import predefined Foo model with three four inputs
    #
    # [ index_1, material_model, param_1, param_2 ]
    #
    # The inputs have the types [ Int, Callable, Float, Float
    #
    from sim_model import SimModel
    sim_model = SimModel()

    # The model response is obtained by issuing
    #
    print 'default evaluation', sim_model.peval()

    # returning an array with two values.
    # In this call, the default values of the factors
    # [input_1, material_model, param_1, param_2 ]
    # were taken. The factor levels were ignored.

    # DEFINING A STUDY
    # --------------
    # In order to study the response of the model in a broader range
    # of specified levels we now construct the parametric study
    #
示例#9
0
def run():

    from sim_model import SimModel
    pstudy_app = SimPStudy(sim_model=SimModel())
    pstudy_app.configure_traits(kind='live')
示例#10
0
class TLClassifier(object):
    def __init__(self, is_sim):
        self.is_sim = is_sim
        if is_sim:
            self.model = SimModel()
        else:
            self.threshold = THRESHOLD
            self.graph = self.load_graph(GRAPH_PATH_SIM)
            self.image_tensor = self.graph.get_tensor_by_name('image_tensor:0')
            self.detect_boxes = self.graph.get_tensor_by_name(
                'detection_boxes:0')
            self.detect_scores = self.graph.get_tensor_by_name(
                'detection_scores:0')
            self.detect_classes = self.graph.get_tensor_by_name(
                'detection_classes:0')
            self.num_detections = self.graph.get_tensor_by_name(
                'num_detections:0')
            self.sess = tf.Session(graph=self.graph)

    def get_classification(self, image):
        """Determines the color of the traffic light in the image
        Args:
            image (cv::Mat): image containing the traffic light, BGR channel
        Returns:
            int: ID of traffic light color (specified in styx_msgs/TrafficLight)
        """
        if self.is_sim:
            return self.model.predict(image)
        else:
            with self.graph.as_default():
                image_expanded = np.expand_dims(image, axis=0)

                (boxes, scores, classes, num) = self.sess.run(
                    [
                        self.detect_boxes, self.detect_scores,
                        self.detect_classes, self.num_detections
                    ],
                    feed_dict={self.image_tensor: image_expanded})

                boxes = np.squeeze(boxes)
                scores = np.squeeze(scores)
                classes = np.squeeze(classes)

                if scores[0] > self.threshold:

                    if classes[0] == 1:
                        return TrafficLight.GREEN
                    elif classes[0] == 2:
                        return TrafficLight.RED
                    elif classes[0] == 3:
                        return TrafficLight.YELLOW
            return TrafficLight.UNKNOWN

    def load_graph(self, graph_path):
        graph = tf.Graph()
        with graph.as_default():
            graph_def = tf.GraphDef()
            with tf.gfile.GFile(graph_path, 'rb') as fid:
                read_graph = fid.read()
                graph_def.ParseFromString(read_graph)
                tf.import_graph_def(graph_def, name='')

        return graph
示例#11
0
 def _sim_model_default(self):
     from sim_model import SimModel
     return SimModel()
示例#12
0
 #                   A trait is regarded as Factor if it specifies
 #                   a set of levels in form ps_levels = True.
 # - get_sim_outputs()   as instances of SimOut class
 #                   defining the name and order of outputs
 # - peval()          method returning a vector of results
 #                   the order of outputs is prescribed by the
 #                   specification given in the get_outputs() method 
 #
 # Here we just import predefined Foo model with three four inputs
 #
 # [ index_1, material_model, param_1, param_2 ]
 # 
 # The inputs have the types [ Int, Callable, Float, Float
 # 
 from sim_model import SimModel
 sim_model = SimModel()
 
 # The model response is obtained by issueing
 #    
 print 'default evaluation', sim_model.peval()
    
 # returning an array with two values. 
 # In this call, the default values of the factors 
 # [input_1, material_model, param_1, param_2 ]
 # were taken. The factor levels were ignored.
 
 # DEFINING A STUDY
 # --------------
 # In order to study the response of the model in a broader range 
 # of specified levels we now construct the parametric study
 #