コード例 #1
0
 def _predict(self, img_msg, label_msg):
     # convert image
     bridge = cv_bridge.CvBridge()
     input_image = bridge.imgmsg_to_cv2(img_msg, 'rgb8')
     input_label = bridge.imgmsg_to_cv2(label_msg)
     # predict
     region_imgs = []
     for l in np.unique(input_label):
         if l == 0:  # bg_label
             continue
         mask = (input_label == l)
         region = jsk_recognition_utils.bounding_rect_of_mask(
             input_image, mask)
         region_imgs.append(region)
     y_proba = self.estimator.predict(region_imgs)
     target_names = np.array(jsk_apc2015_common.get_object_list())
     y_pred = np.argmax(y_proba, axis=-1)
     label_proba = [p[i] for p, i in zip(y_proba, y_pred)]
     # prepare message
     res = ClassificationResult()
     res.header = img_msg.header
     res.labels = y_pred
     res.label_names = target_names[y_pred]
     res.label_proba = label_proba
     res.probabilities = y_proba.reshape(-1)
     res.classifier = '<jsk_2015_05_baxter_apc.ColorHistogramFeatures>'
     res.target_names = target_names
     self._pub.publish(res)
コード例 #2
0
    def _apply(self, bof_msg, ch_msg):
        target_names = bof_msg.target_names
        assert target_names == ch_msg.target_names

        N_label = len(target_names)
        bof_proba = np.array(bof_msg.probabilities).reshape((-1, N_label))
        ch_proba = np.array(ch_msg.probabilities).reshape((-1, N_label))
        bof_weight = np.array([self.weight[n]['bof'] for n in target_names])
        ch_weight = np.array([self.weight[n]['color'] for n in target_names])
        y_proba = (bof_weight * bof_proba) + (ch_weight * ch_proba)

        # verification result for debug
        y_pred = np.argmax(y_proba, axis=-1)
        target_names = np.array(target_names)
        label_proba = [p[i] for p, i in zip(y_proba, y_pred)]
        # compose msg
        msg = ClassificationResult()
        msg.header = bof_msg.header
        msg.labels = y_pred
        msg.label_names = target_names[y_pred]
        msg.label_proba = label_proba
        msg.probabilities = y_proba.reshape(-1)
        msg.classifier = '<jsk_2015_05_baxter_apc.BoostObjectRecognition>'
        msg.target_names = target_names
        self.pub.publish(msg)
コード例 #3
0
    def _apply(self, bof_msg, ch_msg):
        target_names = bof_msg.target_names
        assert target_names == ch_msg.target_names

        N_label = len(target_names)
        bof_proba = np.array(bof_msg.probabilities).reshape((-1, N_label))
        ch_proba = np.array(ch_msg.probabilities).reshape((-1, N_label))
        bof_weight = np.array([self.weight[n]['bof'] for n in target_names])
        ch_weight = np.array([self.weight[n]['color'] for n in target_names])
        y_proba = (bof_weight * bof_proba) + (ch_weight * ch_proba)

        # verification result for debug
        y_pred = np.argmax(y_proba, axis=-1)
        target_names = np.array(target_names)
        label_proba = [p[i] for p, i in zip(y_proba, y_pred)]
        # compose msg
        msg = ClassificationResult()
        msg.header = bof_msg.header
        msg.labels = y_pred
        msg.label_names = target_names[y_pred]
        msg.label_proba = label_proba
        msg.probabilities = y_proba.reshape(-1)
        msg.classifier = '<jsk_2015_05_baxter_apc.BoostObjectRecognition>'
        msg.target_names = target_names
        self.pub.publish(msg)
コード例 #4
0
 def _cb(self, imgmsg):
     bridge = cv_bridge.CvBridge()
     img = bridge.imgmsg_to_cv2(imgmsg)
     label, proba = self._classify(img)
     msg = ClassificationResult()
     msg.header = imgmsg.header
     msg.labels = [label]
     msg.label_names = [self.target_names[label]]
     msg.label_proba = [proba[label]]
     msg.probabilities = proba
     msg.classifier = self.classifier_name
     msg.target_names = self.target_names
     self.pub.publish(msg)
コード例 #5
0
 def _cb(self, imgmsg):
     bridge = cv_bridge.CvBridge()
     img = bridge.imgmsg_to_cv2(imgmsg)
     label, proba = self._classify(img)
     msg = ClassificationResult()
     msg.header = imgmsg.header
     msg.labels = [label]
     msg.label_names = [self.target_names[label]]
     msg.label_proba = [proba[label]]
     msg.probabilities = proba
     msg.classifier = self.classifier_name
     msg.target_names = self.target_names
     self.pub.publish(msg)