def update_data(self): is_updated = False for arm in ['right', 'left']: target_bin = self.arm_target_bin[arm] if target_bin not in self.finished_bin_list \ and target_bin in 'abcdefghijkl' \ and self.arm_state[arm] == "place_object": target_object = self.work_order[target_bin] self.tote_contents.append(target_object) target_bin_ = 'bin_' + target_bin.upper() self.bin_contents[target_bin_].remove(target_object) self.finished_bin_list.append(target_bin) jsk_loginfo('bin {}: object {} has moved to tote' .format(target_bin, target_object)) is_updated = True return is_updated
def _load_chainer_model(self): model_name = rospy.get_param('~model_name') model_h5 = rospy.get_param('~model_h5') n_class = len(self.target_names) if model_name == 'fcn32s': self.model = fcn.models.FCN32s(n_class=n_class) elif model_name == 'fcn16s': self.model = fcn.models.FCN16s(n_class=n_class) elif model_name == 'fcn8s': self.model = fcn.models.FCN8s(n_class=n_class) else: raise ValueError('Unsupported ~model_name: {}'.format(model_name)) jsk_loginfo('Loading trained model: {0}'.format(model_h5)) S.load_hdf5(model_h5, self.model) jsk_loginfo('Finished loading trained model: {0}'.format(model_h5)) if self.gpu != -1: self.model.to_gpu(self.gpu) self.model.train = False
def update_data(self): is_updated = False for arm in ['right', 'left']: target_bin = self.arm_target_bin[arm] target_object = self.arm_target_object[arm] if not target_bin: continue if self.arm_update_json[arm] is True and \ target_object not in self.finished_object_list and \ target_bin in 'abcdefghijkl' and \ self.arm_state[arm] == "place_object": target_bin_ = 'bin_' + target_bin.upper() self.bin_contents[target_bin_].append(target_object) self.tote_contents.remove(target_object) self.finished_object_list.append(target_object) jsk_loginfo('object {} has moved to bin {}' .format(target_object, target_bin)) is_updated = True return is_updated
def _load_torch_model(self): try: import torchfcn except ImportError: raise ImportError('Please install torchfcn: pip install torchfcn') n_class = len(self.target_names) model_file = rospy.get_param('~model_file') model_name = rospy.get_param('~model_name') if model_name == 'fcn32s': self.model = torchfcn.models.FCN32s(n_class=n_class) elif model_name == 'fcn32s_bilinear': self.model = torchfcn.models.FCN32s(n_class=n_class, nodeconv=True) else: raise ValueError('Unsupported ~model_name: {0}'.format(model_name)) jsk_loginfo('Loading trained model: %s' % model_file) self.model.load_state_dict(torch.load(model_file)) jsk_loginfo('Finished loading trained model: %s' % model_file) if self.gpu >= 0: self.model = self.model.cuda(self.gpu) self.model.eval()
def _load_model(self): self.gpu = rospy.get_param('~gpu', -1) # -1 is cpu mode self.model_name = rospy.get_param('~model_name') model_h5 = rospy.get_param('~model_h5') self.target_names = rospy.get_param('~target_names') self.mean_bgr = np.array([104.00698793, 116.66876762, 122.67891434]) n_class = len(self.target_names) if self.model_name == 'fcn32s': self.model = fcn.models.FCN32s(n_class=n_class) elif self.model_name == 'fcn16s': self.model = fcn.models.FCN16s(n_class=n_class) elif self.model_name == 'fcn8s': self.model = fcn.models.FCN8s(n_class=n_class) else: rospy.logerr('Unsupported ~model_name: {0}' .format(self.model_name)) jsk_loginfo('Loading trained model: {0}'.format(model_h5)) S.load_hdf5(model_h5, self.model) jsk_loginfo('Finished loading trained model: {0}'.format(model_h5)) if self.gpu != -1: self.model.to_gpu(self.gpu)
def _load_model(self): self.gpu = rospy.get_param('~gpu', -1) # -1 is cpu mode self.model_name = rospy.get_param('~model_name') model_h5 = rospy.get_param('~model_h5') self.target_names = rospy.get_param('~target_names') self.mean_bgr = np.array([104.00698793, 116.66876762, 122.67891434]) n_class = len(self.target_names) if self.model_name == 'fcn32s': self.model = fcn.models.FCN32s(n_class=n_class) elif self.model_name == 'fcn16s': self.model = fcn.models.FCN16s(n_class=n_class) elif self.model_name == 'fcn8s': self.model = fcn.models.FCN8s(n_class=n_class) else: rospy.logerr('Unsupported ~model_name: {0}'.format( self.model_name)) jsk_loginfo('Loading trained model: {0}'.format(model_h5)) S.load_hdf5(model_h5, self.model) jsk_loginfo('Finished loading trained model: {0}'.format(model_h5)) if self.gpu != -1: self.model.to_gpu(self.gpu)
def test_jsk_loginfo(self, mock_get_name, mock_log): mock_get_name.return_value = '/spam' jsk_loginfo('spam') mock_log.assert_called_with('[/spam] [TestJSKLogXXX::test_jsk_loginfo] spam')
def main(): rospy.init_node('fast_rcnn_caffenet') # get parameters try: model_name = rospy.get_param('~model') except KeyError as e: rospy.logerr('Unspecified rosparam: {0}'.format(e)) sys.exit(1) # FIXME: In CPU mode, there is no detections. if not cuda.available: jsk_logfatal('CUDA environment is required.') sys.exit(1) use_gpu = True # setup model PKG = 'jsk_perception' rp = rospkg.RosPack() data_path = osp.join(rp.get_path(PKG), 'trained_data') if model_name == 'vgg_cnn_m_1024': model = VGG_CNN_M_1024() chainermodel = osp.join(data_path, 'vgg_cnn_m_1024.chainermodel') elif model_name == 'vgg16': model = VGG16FastRCNN() chainermodel = osp.join(data_path, 'vgg16_fast_rcnn.chainermodel') else: rospy.logerr('Unsupported model: {0}'.format(model_name)) sys.exit(1) jsk_loginfo('Loading chainermodel') S.load_hdf5(chainermodel, model) if use_gpu: model.to_gpu() jsk_loginfo('Finished loading chainermodel') # assumptions target_names = [ '__background__', 'aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor', ] pixel_means = [102.9801, 115.9465, 122.7717] fast_rcnn = FastRCNN( model=model, target_names=target_names, pixel_means=pixel_means, use_gpu=use_gpu) rospy.spin()
def main(): rospy.init_node("fast_rcnn_caffenet") # get parameters try: model_name = rospy.get_param("~model") except KeyError as e: rospy.logerr("Unspecified rosparam: {0}".format(e)) sys.exit(1) # FIXME: In CPU mode, there is no detections. if not cuda.available: jsk_logfatal("CUDA environment is required.") sys.exit(1) use_gpu = True # setup model PKG = "jsk_perception" rp = rospkg.RosPack() data_path = osp.join(rp.get_path(PKG), "trained_data") if model_name == "vgg_cnn_m_1024": model = VGG_CNN_M_1024() chainermodel = osp.join(data_path, "vgg_cnn_m_1024.chainermodel") elif model_name == "vgg16": model = VGG16FastRCNN() chainermodel = osp.join(data_path, "vgg16_fast_rcnn.chainermodel") else: rospy.logerr("Unsupported model: {0}".format(model_name)) sys.exit(1) jsk_loginfo("Loading chainermodel") S.load_hdf5(chainermodel, model) if use_gpu: model.to_gpu() jsk_loginfo("Finished loading chainermodel") # assumptions target_names = [ "__background__", "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor", ] pixel_means = [102.9801, 115.9465, 122.7717] fast_rcnn = FastRCNN(model=model, target_names=target_names, pixel_means=pixel_means, use_gpu=use_gpu) rospy.spin()
def test_jsk_loginfo(self, mock_log): jsk_loginfo('spam') mock_log.assert_called_with('[TestJSKLogXXX::test_jsk_loginfo] spam')