def spin_once(self): if self.bof_data is None or self.cfeature is None: return stamp, bof_objects_proba = self.bof_data stamp, cfeature_objects_proba = self.cfeature weight = self.weight target_bin = rospy.get_param('target_bin', None) object_list = jsk_apc2015_common.get_object_list() all_proba = [ (o, (weight[o]['bof'] * bof_objects_proba[o]) + (weight[o]['color'] * cfeature_objects_proba[o]) ) for o in object_list ] # verification result for debug candidates = self.bin_contents.get(target_bin, None) if candidates is None: candidates = object_list matched = sorted(all_proba, key=lambda x: x[1])[-1][0] # compose msg msg = ObjectRecognition() msg.header.stamp = stamp msg.matched = matched msg.probability = dict(all_proba)[matched] / sum(dict(all_proba).values()) msg.candidates = candidates msg.probabilities = np.array([dict(all_proba)[c] for c in candidates]) msg.probabilities /= msg.probabilities.sum() self.pub_debug.publish(msg) # verification result with json target if target_bin is None or target_bin == '': return proba = [ (c, (weight[c]['bof'] * bof_objects_proba[c]) + (weight[c]['color'] * cfeature_objects_proba[c]) ) for c in candidates ] matched = sorted(proba, key=lambda x: x[1])[-1][0] # compose msg msg = ObjectRecognition() msg.header.stamp = stamp msg.matched = matched msg.probability = dict(proba)[matched] / sum(dict(proba).values()) msg.candidates = candidates msg.probabilities = np.array([dict(proba)[c] for c in candidates]) msg.probabilities /= msg.probabilities.sum() self.pub.publish(msg)
def predict_now(self): query_image = self.query_image object_list = jsk_2015_apc_common.data.object_list() probs = self.match(object_list) matched_idx = np.argmax(probs) # prepare message res = ObjectRecognition() res.header.stamp = query_image.header.stamp res.matched = object_list[matched_idx] res.probability = probs[matched_idx] res.candidates = object_list res.probabilities = probs return res
def _apply(self, msg): target_bin = rospy.get_param('target_bin', '') if (not target_bin) or (target_bin not in 'abcdefghijkl'): return # get candidates probabilities if target_bin not in self.bin_contents: rospy.logerr("target_bin '{0}' is not found in json: {1}".format( target_bin, self.bin_contents)) return candidates = self.bin_contents[target_bin] + ['no_object'] label_to_proba = dict(zip(msg.target_names, msg.probabilities)) candidates_proba = [label_to_proba[label] for label in candidates] candidates_proba = np.array(candidates_proba) candidates_proba = candidates_proba / candidates_proba.sum() # compose output message top_index = np.argmax(candidates_proba) out_msg = ObjectRecognition( header=msg.header, matched=candidates[top_index], probability=candidates_proba[top_index], candidates=candidates, probabilities=candidates_proba, ) self.pub.publish(out_msg)
def predict_now(self): query_features = self.query_features if not len(query_features.descriptors) > 0: return descs = np.array(query_features.descriptors) X = self.bof.transform([descs]) normalize(X, copy=False) self._pub_debug.publish(Histogram(header=query_features.header, histogram=X[0])) object_list = jsk_2015_apc_common.data.object_list() proba = self.clf.predict_proba(X)[0] matched_idx = np.argmax(proba) # prepare message res = ObjectRecognition() res.header.stamp = query_features.header.stamp res.matched = object_list[matched_idx] res.probability = proba[matched_idx] res.candidates = object_list res.probabilities = proba return res
def _apply(self, msg): # get candidates probabilities candidates = [ obj for obj in self.tote_contents if obj not in self.blacklist ] candidates = ['no_object'] + candidates[:] label_to_proba = dict(zip(msg.target_names, msg.probabilities)) candidates_proba = [label_to_proba[label] for label in candidates] candidates_proba = np.array(candidates_proba) candidates_proba = candidates_proba / candidates_proba.sum() # compose output message top_index = np.argmax(candidates_proba) out_msg = ObjectRecognition( header=msg.header, matched=candidates[top_index], probability=candidates_proba[top_index], candidates=candidates, probabilities=candidates_proba, ) self.pub.publish(out_msg)
def spin_once(self): if self.bof_data is None or self.cfeature is None: return stamp, bof_objects_proba = self.bof_data stamp, cfeature_objects_proba = self.cfeature weight = self.weight target_bin = rospy.get_param('target', None) object_list = jsk_2015_apc_common.data.object_list() all_proba = [ (o, (weight[o]['bof'] * bof_objects_proba[o]) + (weight[o]['color'] * cfeature_objects_proba[o]) ) for o in object_list ] # verification result for debug candidates = self.bin_contents.get(target_bin, None) if candidates is None: candidates = object_list matched = sorted(all_proba, key=lambda x: x[1])[-1][0] # compose msg msg = ObjectRecognition() msg.header.stamp = stamp msg.matched = matched msg.probability = dict(all_proba)[matched] / sum(dict(all_proba).values()) msg.candidates = candidates msg.probabilities = np.array([dict(all_proba)[c] for c in candidates]) msg.probabilities /= msg.probabilities.sum() self.pub_debug.publish(msg) # verification result with json target if target_bin is None or target_bin == '': return proba = [ (c, (weight[c]['bof'] * bof_objects_proba[c]) + (weight[c]['color'] * cfeature_objects_proba[c]) ) for c in candidates ] matched = sorted(proba, key=lambda x: x[1])[-1][0] # compose msg msg = ObjectRecognition() msg.header.stamp = stamp msg.matched = matched msg.probability = dict(proba)[matched] / sum(dict(proba).values()) msg.candidates = candidates msg.probabilities = np.array([dict(proba)[c] for c in candidates]) msg.probabilities /= msg.probabilities.sum() self.pub.publish(msg)