def __init__(self, obj_filenames=None, debug=False, start_node=True, env='simulator'): COLOR_TOPIC = '/kinect2/sd/image_color_rect' DEPTH_TOPIC = '/kinect2/sd/image_depth_rect' CAMINFO_TOPIC = '/kinect2/sd/camera_info' self.CAM_FRAME = 'kinect2_ir_optical_frame' self.WORLD_FRAME = 'world' self.MICO_TARGET_FRAME = 'mico_target_frame' self.debug = debug self.env = env rospack = rospkg.RosPack() self.grasping_ro_mico_path = rospack.get_path('grasping_ros_mico') self.config_path = self.grasping_ro_mico_path + '/config_files/dexnet_config/' if env == 'simulator': self.config = YamlConfig(self.config_path + 'mico_control_node.yaml') else: self.config = YamlConfig(self.config_path + 'mico_control_node_' + env + '.yaml') if self.config['kinect_sensor_cfg']['color_topic']: COLOR_TOPIC = self.config['kinect_sensor_cfg']['color_topic'] if self.config['kinect_sensor_cfg']['depth_topic']: DEPTH_TOPIC = self.config['kinect_sensor_cfg']['depth_topic'] if self.config['kinect_sensor_cfg']['camera_info_topic']: CAMINFO_TOPIC = self.config['kinect_sensor_cfg'][ 'camera_info_topic'] if self.config['kinect_sensor_cfg']['cam_frame']: self.CAM_FRAME = self.config['kinect_sensor_cfg']['cam_frame'] if 'world_frame' in self.config['kinect_sensor_cfg'].keys(): self.WORLD_FRAME = self.config['kinect_sensor_cfg']['world_frame'] self.detector_cfg = self.config['detector'] if obj_filenames is not None: self.obj_filenames = obj_filenames #Not loading all point clods to save memory #self.load_object_point_clouds() # create rgbd sensor self.sensor = None print "Creating sensor" rospy.loginfo('Creating RGBD Sensor') self.sensor = KinectSensor(COLOR_TOPIC, DEPTH_TOPIC, CAMINFO_TOPIC, start_node, env) rospy.loginfo('Sensor Running') print "Sensor running"
def __init__(self, output_dir): self.NUM_OBJECTS = None self.table_file = DATA_DIR + '/meshes/table.obj' self.data_dir = DATA_DIR + '/meshes/dexnet/' output_dir = DATA_DIR + output_dir if not os.path.exists(output_dir): os.mkdir(output_dir) self.output_dir = output_dir self.config = YamlConfig( './cfg/tools/generate_oblique_gqcnn_dataset.yaml') self.phi_offsets = self._generate_phi_offsets() self.datasets, self.target_object_keys = self._load_datasets() self.tensor_dataset = TensorDataset(self.output_dir, self._set_tensor_config()) self.tensor_datapoint = self.tensor_dataset.datapoint_template self.gripper = self._set_gripper() self._table_mesh_filename = self._set_table_mesh_filename() self.table_mesh = self._set_table_mesh() self.cur_pose_label = 0 self.cur_obj_label = 0 self.cur_image_label = 0 self.grasp_upsample_distribuitions = self._get_upsample_distributions() self.camera_distributions = self._get_camera_distributions() self.obj = None self.T_obj_camera = None
def __init__(self, output_dir): self.NUM_OBJECTS = None self.table_file = DATA_DIR + '/meshes/table.obj' self.data_dir = DATA_DIR + '/meshes/dexnet/' if not os.path.exists(output_dir): os.mkdir(output_dir) self.image_dir = output_dir + '/images/' if not os.path.exists(self.image_dir): os.mkdir(self.image_dir) self.orig_image_dir = output_dir + '/orig_images/' if not os.path.exists(self.orig_image_dir): os.mkdir(self.orig_image_dir) self.config = YamlConfig(CONFIG) self.phi_offsets = self._generate_phi_offsets() self.datasets = self._load_datasets() self.tensor_dataset = TensorDataset(output_dir, self._set_tensor_config()) self.tensor_datapoint = self.tensor_dataset.datapoint_template self.gripper = self._set_gripper() self._table_mesh_filename = self._set_table_mesh_filename() self.table_mesh = self._set_table_mesh() self.cur_pose_label = 0 self.cur_obj_label = 0 self.cur_image_label = 0 self.cur_image_file = 0 self.obj = None self.T_obj_camera = None
def setup_perception(self): self.cfg = YamlConfig("april_tag_pick_place_azure_kinect_cfg.yaml") self.T_camera_world = RigidTransform.load( self.cfg['T_k4a_franka_path']) self.sensor = Kinect2SensorFactory.sensor( 'bridged', self.cfg) # Kinect sensor object prefix = "" self.sensor.topic_image_color = prefix + self.sensor.topic_image_color self.sensor.topic_image_depth = prefix + self.sensor.topic_image_depth self.sensor.topic_info_camera = prefix + self.sensor.topic_info_camera self.sensor.start() self.april = AprilTagDetector(self.cfg['april_tag']) # intr = sensor.color_intrinsics #original overhead_intr = CameraIntrinsics('k4a', fx=970.4990844726562, cx=1025.4967041015625, fy=970.1990966796875, cy=777.769775390625, height=1536, width=2048) #fx fy cx cy overhead frontdown_intr = CameraIntrinsics('k4a', fx=611.9021606445312, cx=637.0317993164062, fy=611.779968261718, cy=369.051239013671, height=1536, width=2048) #fx fy cx cy frontdown self.intr = overhead_intr
def __init__(self, config_fn = "cfg/franka_block_push_two_d.yaml"): self.step = self.predict self.cfg = YamlConfig(config_fn) self.dir_to_rpy= {0:[-np.pi/2,np.pi/2,0], 1:[-np.pi/2,np.pi/2,np.pi/2], 2:[-np.pi/2,np.pi/2,np.pi], 3:[-np.pi/2,np.pi/2,1.5*np.pi]}
def main(): parser = argparse.ArgumentParser() parser.add_argument('--config_filename', type=str, default=None, help='configuration file to use') args = parser.parse_args() config_filename = args.config_filename if config_filename is None: config_filename = os.path.join( os.path.dirname(os.path.realpath(__file__)), '..', 'cfg/tools/generate_training_data.yaml') cfg = YamlConfig(config_filename) input_dir = cfg['edge_set_dir'] output_dir = cfg['output_dir'] image_generator = SalientEdgeImageGenerator(cfg['generator_config']) filename_counter = len(os.listdir(output_dir)) for zip_filepath in os.listdir(input_dir): full_path = os.path.join(input_dir, zip_filepath) ses = SalientEdgeSet.load(full_path) depth_ims, normal_ims, edge_masks = image_generator.generate_images( ses, cfg['n_samples_per_mesh']) for di, ni, em in zip(depth_ims, normal_ims, edge_masks): fn = os.path.join(output_dir, '{}.npz'.format(filename_counter)) filename_counter += 1 np.savez(fn, depth=di.data.astype(np.float32), normals=ni.data.astype(np.float32), mask=em.data.astype(np.float32) / 255.0)
def main(): # initialize logging logging.getLogger().setLevel(31) parser = argparse.ArgumentParser( description='Pull new data from Thingiverse', epilog='Written by Matthew Matl (mmatl)') parser.add_argument('--config', help='config filename', default='cfg/tools/crawler.yaml') args = parser.parse_args() config_filename = args.config config = YamlConfig(config_filename) ds = ThingiverseDataset(config['dataset_dir']) thing_ids = [str(s) for s in config['thing_ids']] for license in config['licenses']: for category in config['categories']: params = { # 'category' : category, 'license': license, 'query': '' } ds.retrieve_from_thingiverse(config['number'], config['cache_dir'], params, thing_ids)
def __init__(self, config, use_sensitivity=True, num_samples=1000): """ config : :obj:`autolab_core.YamlConfig` configuration with toppling parameters use_sensitivity : bool Whether to run multiple trials per vertex to get a probability estimate num_samples : int how many vertices to sample on the object surface """ MultiEnvPolicy.__init__(self) policy_params = config['policy'] model_params = config['model'] grasping_config = YamlConfig(policy_params['grasping_policy_config_filename']) self.grasping_policy = DexNetGreedyGraspingPolicy( grasping_config['policy']['database'], grasping_config['policy']['params'] ) self.use_sensitivity = use_sensitivity self.num_samples = num_samples self.thresh = policy_params['thresh'] self.log = policy_params['log'] if model_params['load']: self.toppling_model = TopplingDatasetModel(model_params['datasets']) self.get_topple = self.load_topple else: self.toppling_model = TopplingModel(model_params) self.get_topple = self.compute_topple
def __init__(self, model_dir): self.cfg = YamlConfig(model_dir + '/config.json') self.im_stream = self.cfg['gqcnn']['architecture']['im_stream'] self.pose_stream = self.cfg['gqcnn']['architecture']['pose_stream'] self.merge_stream = self.cfg['gqcnn']['architecture']['merge_stream'] self._read_weights_and_biases(model_dir) self.build()
def test_GQCNN(): config = YamlConfig( '/home/baymax/catkin_ws/src/jaco_manipulation/cfg/grasp_test.yaml') # create rgbd sensor rospy.loginfo('Creating RGBD Sensor') sensor_cfg = config['sensor_cfg'] sensor_type = sensor_cfg['type'] sensor = RgbdSensorFactory.sensor(sensor_type, sensor_cfg) sensor.start() rospy.loginfo('Sensor Running') # setup safe termination def handler(signum, frame): rospy.loginfo('caught CTRL+C, exiting...') if sensor is not None: sensor.stop() if robot is not None: robot.stop() if subscriber is not None and subscriber._started: subscriber.stop() exit(0) signal.signal(signal.SIGINT, handler) planner = GQCNNPlanner(sensor, config) # rospy.sleep(10) planner.get_grasp_plan("cup")
def run_sequential_bin_picking_benchmark( # input_dataset_path, # heap_ids, # timesteps, # output_dataset_path, config_filename, # excluded_heaps_file, num_rollouts=None): # open config file logging.getLogger().setLevel(logging.INFO) config = YamlConfig(config_filename) if num_rollouts is not None: config['num_rollouts'] = num_rollouts # load policy policy = TopplingPolicy(config['policy']['grasping_policy_config_filename']) # perform rollouts logging.info('Rolling out policy') dataset = benchmark_bin_picking_policy(policy, # input_dataset_path, # heap_ids, # timesteps, # output_dataset_path, config, # excluded_heaps_file) ) return dataset
def main(): parser = argparse.ArgumentParser() parser.add_argument('--config_filename', type=str, default=None, help='configuration file to use') args = parser.parse_args() config_filename = args.config_filename if config_filename is None: config_filename = os.path.join( os.path.dirname(os.path.realpath(__file__)), '..', 'cfg/tools/generate_salient_edge_sets.yaml') cfg = YamlConfig(config_filename) mesh_dir = cfg['mesh_dir'] output_dir = cfg['output_dir'] filename_counter = len(os.listdir(output_dir)) for mesh_filepath in os.listdir(mesh_dir): print(mesh_filepath) full_path = os.path.join(mesh_dir, mesh_filepath) m = trimesh.load_mesh(full_path) if len(m.faces) > cfg['max_n_faces']: continue ses = SalientEdgeSet(m, cfg['salient_edge_set_cfg']) ses.save(os.path.join(output_dir, '{}.zip'.format(filename_counter))) filename_counter += 1
def main(): parser = argparse.ArgumentParser() parser.add_argument('--config_filename', type=str, default=None, help='configuration file to use') args = parser.parse_args() config_filename = args.config_filename if config_filename is None: config_filename = os.path.join( os.path.dirname(os.path.realpath(__file__)), '..', 'cfg/tools/evaluate_registration_examples.yaml') cfg = YamlConfig(config_filename) input_dir = cfg['examples_dir'] os.environ['CUDA_VISIBLE_DEVICES'] = str(cfg['cuda_device']) aligner = Super4PCSAligner(cfg['super4pcs_config']) model = load_model(cfg['model_file']) for filepath in os.listdir(input_dir): full_path = os.path.join(input_dir, filepath) example = RegistrationExample.load(full_path) T_obj_camera_est = register_example(example, aligner, model) print('Error: {}'.format(example.alignment_error(T_obj_camera_est))) example.visualize_alignment(T_obj_camera_est)
def __init__(self, cfgFile="cfg/maskrcnn.yaml"): config = YamlConfig(cfgFile) print("Benchmarking model.") # Create new directory for outputs output_dir = config['output_dir'] utils.mkdir_if_missing(output_dir) # Save config in output directory image_shape = config['model']['settings']['image_shape'] config['model']['settings']['image_min_dim'] = min(image_shape) config['model']['settings']['image_max_dim'] = max(image_shape) config['model']['settings']['gpu_count'] = 1 config['model']['settings']['images_per_gpu'] = 1 inference_config = MaskConfig(config['model']['settings']) model_dir, _ = os.path.split(config['model']['path']) self.model = modellib.MaskRCNN(mode=config['model']['mode'], config=inference_config, model_dir=model_dir) print(("Loading weights from ", config['model']['path'])) self.model.load_weights(config['model']['path'], by_name=True) self.graph = tf.get_default_graph() print(self.model.keras_model.layers[0].dtype)
def visualization(): visualization_config = YamlConfig( '/home/simon/sandbox/graspitmod/catkin_ws/src/gqcnn/custom/visualization.yaml' ) visualizer = GQCNNPredictionVisualizer(visualization_config) visualizer.visualize()
def main(): parser = argparse.ArgumentParser() parser.add_argument('--config_filename', type=str, default=None, help='configuration file to use') args = parser.parse_args() config_filename = args.config_filename if config_filename is None: config_filename = os.path.join( os.path.dirname(os.path.realpath(__file__)), '..', 'cfg/tools/generate_test_cases.yaml') cfg = YamlConfig(config_filename) input_dir = cfg['edge_set_dir'] output_dir = cfg['output_dir'] example_generator = RegistrationExampleGenerator(cfg['generator_config']) filename_counter = len(os.listdir(output_dir)) for ses_filepath in os.listdir(input_dir): full_path = os.path.join(input_dir, ses_filepath) examples = example_generator.generate_examples( full_path, cfg['n_samples_per_mesh']) for example in examples: fn = os.path.join(output_dir, '{}.pkl'.format(filename_counter)) filename_counter += 1 example.save(fn)
def _get_cfg(self, config_filepath=None): """ Function retrieves the model and policy configuration files for a given model. Parameters ---------- model: type `str` Model used for the grasp detection CNN. """ model_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "models") model_path = os.path.join(model_dir, self.model) # Retrieve model related configuration values self.model_config = json.load( open(os.path.join(model_path, "config.json"), "r")) try: gqcnn_config = self.model_config["gqcnn"] gripper_mode = gqcnn_config["gripper_mode"] except KeyError: gqcnn_config = self.model_config["gqcnn_config"] input_data_mode = gqcnn_config["input_data_mode"] if input_data_mode == "tf_image": gripper_mode = GripperMode.LEGACY_PARALLEL_JAW elif input_data_mode == "tf_image_suction": gripper_mode = GripperMode.LEGACY_SUCTION elif input_data_mode == "suction": gripper_mode = GripperMode.SUCTION elif input_data_mode == "multi_suction": gripper_mode = GripperMode.MULTI_SUCTION elif input_data_mode == "parallel_jaw": gripper_mode = GripperMode.PARALLEL_JAW else: raise ValueError("Input data mode {} not supported!".format( input_data_mode)) # Get config filename corrsponds to the model if config_filepath is None: if gripper_mode == GripperMode.LEGACY_PARALLEL_JAW or gripper_mode == GripperMode.PARALLEL_JAW: if "FC" in self.model: config_filepath = os.path.join( os.path.dirname(os.path.realpath(__file__)), "gqcnn/cfg/examples/fc_gqcnn_pj.yaml") else: config_filepath = os.path.join( os.path.dirname(os.path.realpath(__file__)), "gqcnn/cfg/examples/gqcnn_pj.yaml") elif gripper_mode == GripperMode.LEGACY_SUCTION or gripper_mode == GripperMode.SUCTION: if "FC" in self.model: config_filepath = os.path.join( os.path.dirname(os.path.realpath(__file__)), "gqcnn/cfg/examples/fc_gqcnn_suction.yaml") else: config_filepath = os.path.join( os.path.dirname(os.path.realpath(__file__)), "gqcnn/cfg/examples/gqcnn_suction.yaml") # Read config. self.config = YamlConfig(config_filepath) self.policy_config = self.config["policy"] self.policy_config["metric"]["gqcnn_model"] = model_path
def create_multiflex(path, num_instances=1): from flex_gym.flex_vec_env import set_flex_bin_path, make_flex_vec_env_muli_env from autolab_core import YamlConfig import gym set_flex_bin_path(FLEX_PATH + '/bin') cfg_env = YamlConfig(path) env = make_flex_vec_env_muli_env([cfg_env] * num_instances) return env
def create_flex(path): from flex_gym.flex_vec_env import set_flex_bin_path, make_flex_vec_env from autolab_core import YamlConfig import gym set_flex_bin_path(FLEX_PATH + '/bin') cfg_env = YamlConfig(path) cfg_env['gym']['rank'] = 0 env = make_flex_vec_env(cfg_env) return env
def setup_config(self, egad_path, dexnet_path): # Use local config file self.egad_config = YamlConfig( os.path.join(egad_path, "scripts/cfg/dexnet_api_settings.yaml")) # setup collision params for alignment coll_vis_config = YamlConfig( os.path.join(dexnet_path, "cfg/tools/generate_gqcnn_dataset.yaml")) coll_check_params = coll_vis_config['collision_checking'] self.table_offset = coll_check_params['table_offset'] self.table_mesh_filename = coll_check_params['table_mesh_filename'] self.approach_dist = coll_check_params['approach_dist'] self.delta_approach = coll_check_params['delta_approach'] # paramet for alignement of grasps table_alignment_params = coll_vis_config['table_alignment'] min_grasp_approach_offset = -np.deg2rad( table_alignment_params['max_approach_offset']) max_grasp_approach_offset = np.deg2rad( table_alignment_params['max_approach_offset']) num_grasp_approach_samples = table_alignment_params[ 'num_approach_offset_samples'] self.max_grasp_approach_table_angle = np.deg2rad( table_alignment_params['max_approach_table_angle']) self.phi_offsets = [] if max_grasp_approach_offset == min_grasp_approach_offset: phi_inc = 1 elif num_grasp_approach_samples == 1: phi_inc = max_grasp_approach_offset - min_grasp_approach_offset + 1 else: phi_inc = (max_grasp_approach_offset - min_grasp_approach_offset ) / (num_grasp_approach_samples - 1) phi = min_grasp_approach_offset while phi <= max_grasp_approach_offset: self.phi_offsets.append(phi) phi += phi_inc
def __init__(self, output_dir): self.NUM_OBJECTS = None if not os.path.exists(output_dir): os.mkdir(output_dir) self.config = YamlConfig(CONFIG) self.output_dir = output_dir self.datasets, self.target_object_keys = self._load_datasets() self.gripper = self._set_gripper() self.cur_obj_label = 0
def __init__(self): """Create a DexNet object """ self.database = None self.dataset = None self._database_temp_cache_dir = None # open default config self.default_config = YamlConfig(DEXNET_API_DEFAULTS_FILE) # Resolve gripper_dir and cache_dir relative to dex-net root for key in ['gripper_dir', 'cache_dir']: if not os.path.isabs(self.default_config[key]): self.default_config[key] = os.path.realpath( DEXNET_DIR + self.default_config[key])
def _carbongym_env(name, config, params, env_class, cfg, render_mode='rgb_array'): cfg = YamlConfig(cfg) env = SingleEnvWrapper(env_class(cfg, **cfg['env'])) env = control.wrappers.ObservationDict(env, 'state') size = params.get('render_size', 64) env = control.wrappers.PixelObservations(env, (size, size), np.uint8, 'image', render_mode) params.unlock() params['max_length'] = 10 return _common_env(env, config, params)
def main(): # initialize logging logging.getLogger().setLevel(31) parser = argparse.ArgumentParser( description='Annotate Thingiverse Dataset Models', epilog='Written by Matthew Matl (mmatl)') parser.add_argument('--config', help='config filename', default='cfg/tools/annotater.yaml') args = parser.parse_args() config_filename = args.config config = YamlConfig(config_filename) target_key = config['target_key'] default_value = config['default_value'] set_value = config['set_value'] override = config['override'] ds = ThingiverseDataset(config['dataset_dir']) for i, thing_id in enumerate(ds.keys): thing = None thing_metadata = ds.metadata(thing_id) for model_id in thing_metadata['models']: model_data = thing_metadata['models'][model_id] if override or target_key not in model_data['metadata']: if thing is None: thing = ds[thing_id] model = thing[model_id] logging.log( 31, u"{} ({}): {} ({})".format(thing.name, thing.id, model.name, model.id).encode('utf-8')) model.metadata[target_key] = default_value vis.figure() vis.mesh(model.mesh, style='surface') vis.show(animate=True, registered_keys={ 'g': (good_label_callback, [model, target_key, set_value]) }) if thing: ds.save(thing, only_metadata=True) logging.log(31, '{}/{} things...'.format(i, len(ds.keys)))
def __init__(self, output_dir): if not os.path.exists(output_dir): os.mkdir(output_dir) self.config = YamlConfig(CONFIG) self.output_dir = output_dir self._table_mesh_filename = self._set_table_mesh_filename() self.test_obj_labels = np.loadtxt('/data/test_object_labels.txt') self.datasets, self.target_object_keys = self._load_datasets() self.gripper = self._set_gripper() self.output_dir = output_dir if not os.path.exists(output_dir): os.mkdir(output_dir) self.cur_obj_label = 0
def main(): logging.getLogger().setLevel(logging.INFO) # parse args parser = argparse.ArgumentParser(description='Register a webcam to the Photoneo PhoXi') parser.add_argument('--config_filename', type=str, default='cfg/tools/colorize_phoxi.yaml', help='filename of a YAML configuration for registration') args = parser.parse_args() config_filename = args.config_filename config = YamlConfig(config_filename) sensor_data = config['sensors'] phoxi_config = sensor_data['phoxi'] phoxi_config['frame'] = 'phoxi' # Initialize ROS node rospy.init_node('colorize_phoxi', anonymous=True) logging.getLogger().addHandler(rl.RosStreamHandler()) # Get PhoXi sensor set up phoxi = RgbdSensorFactory.sensor(phoxi_config['type'], phoxi_config) phoxi.start() # Capture PhoXi and webcam images phoxi_color_im, phoxi_depth_im, _ = phoxi.frames() # vis2d.figure() # vis2d.subplot(121) # vis2d.imshow(phoxi_color_im) # vis2d.subplot(122) # vis2d.imshow(phoxi_depth_im) # vis2d.show() phoxi_pc = phoxi.ir_intrinsics.deproject(phoxi_depth_im) colors = phoxi_color_im.data.reshape((phoxi_color_im.shape[0] * phoxi_color_im.shape[1], phoxi_color_im.shape[2])) / 255.0 vis3d.figure() vis3d.points(phoxi_pc.data.T[::3], color=colors[::3], scale=0.001) vis3d.show() # Export to PLY file vertices = phoxi.ir_intrinsics.deproject(phoxi_depth_im).data.T colors = phoxi_color_im.data.reshape(phoxi_color_im.data.shape[0] * phoxi_color_im.data.shape[1], phoxi_color_im.data.shape[2]) f = open('pcloud.ply', 'w') f.write('ply\nformat ascii 1.0\nelement vertex {}\nproperty float x\nproperty float y\nproperty float z\nproperty uchar red\n'.format(len(vertices)) + 'property uchar green\nproperty uchar blue\nend_header\n') for v, c in zip(vertices,colors): f.write('{} {} {} {} {} {}\n'.format(v[0], v[1], v[2], c[0], c[1], c[2])) f.close()
def __init__(self, path, elev): if not os.path.exists(DATA_DIR): raise NameError( "Path %s is not specified. Is the docker file set up properly?" % DATA_DIR) table_file = DATA_DIR + '/meshes/table.obj' self.table_mesh = ObjFile(table_file).read() self.data_dir = DATA_DIR + '/meshes/dexnet/' self.output_dir = DATA_DIR + '/reprojections/' self.config = YamlConfig( './cfg/tools/generate_projected_gqcnn_dataset.yaml') self.random_positions = 1 self.image_size = (300, 300) self.elev = 0 self.show_images = False self.cur_obj_label = 0 self.cur_image_label = 0 self.cur_pose_label = 0 if path is not None: self.output_dir = DATA_DIR + '/reprojections/' + path if elev is not None: print("Elevation angle is being set to %d" % elev) self.config['env_rv_params']['min_elev'] = elev self.config['env_rv_params']['max_elev'] = elev self.elev = elev tensor_config = self.config['tensors'] tensor_config['fields']['depth_ims_tf_table']['height'] = 32 tensor_config['fields']['depth_ims_tf_table']['width'] = 32 tensor_config['fields']['robust_ferrari_canny'] = {} tensor_config['fields']['robust_ferrari_canny']['dtype'] = 'float32' tensor_config['fields']['ferrari_canny'] = {} tensor_config['fields']['ferrari_canny']['dtype'] = 'float32' tensor_config['fields']['force_closure'] = {} tensor_config['fields']['force_closure']['dtype'] = 'float32' self.tensor_dataset = TensorDataset(self.output_dir, tensor_config) self.tensor_datapoint = self.tensor_dataset.datapoint_template if not os.path.exists(self.output_dir + '/images'): os.makedirs(self.output_dir + '/images') if not os.path.exists(self.output_dir + '/meshes'): os.makedirs(self.output_dir + '/meshes')
def load(dir_): """ Load the gripper specified by gripper_name. Parameters ---------- dir_ : :obj:`str` directory where the gripper files are stored Returns ------- :obj:`RobotGripper` loaded gripper objects """ yaml_config = YamlConfig(dir_) return RobotGripper(yaml_config)
def main(): # initialize logging logging.getLogger().setLevel(31) # parse args parser = argparse.ArgumentParser( description='Extract labelled models from a Thingiverse Dataset', epilog='Written by Matthew Matl (mmatl)') parser.add_argument('--config', help='config filename', default='cfg/tools/extractor.yaml') args = parser.parse_args() # read config config_filename = args.config config = YamlConfig(config_filename) # get metadata information identifier_key = config['identifier_key'] identifier_value = config['identifier_value'] dsold = ThingiverseDataset(config['dataset_dir']) dsnew = ThingiverseDataset(config['output_dir']) meshdir = None if 'mesh_out_dir' in config: meshdir = config['mesh_out_dir'] if not os.path.exists(meshdir): os.makedirs(meshdir) for i, thing_id in enumerate(dsold.keys): thing_metadata = dsold.metadata(thing_id) model_keys = [] for model_id in thing_metadata['models']: model_data = thing_metadata['models'][model_id] # If the identifier isn't in the model's metadata, skip it if identifier_key in model_data['metadata'] and model_data[ 'metadata'][identifier_key] == identifier_value: model_keys.append(model_id) if meshdir is not None: dsold[thing_id]._models[model_id].mesh.export( os.path.join(meshdir, '{}.obj'.format(model_id)))
def main(): parser = argparse.ArgumentParser() parser.add_argument('--config_filename', type=str, default=None, help='configuration file to use') args = parser.parse_args() # Load Config config_filename = args.config_filename if config_filename is None: config_filename = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'cfg/tools/train_edge_detection_net.yaml') cfg = YamlConfig(config_filename) data_dir = cfg['data_dir'] output_fn = cfg['output_file'] validation_pct = cfg['validation_pct'] model_cfg = cfg['model_cfg'] training_cfg = cfg['training_cfg'] os.environ['CUDA_VISIBLE_DEVICES'] = str(training_cfg['cuda_device']) # Create data generators filenames = [os.path.join(data_dir, fn) for fn in os.listdir(data_dir)] n_data_points = len(filenames) n_train = int(np.floor((1.0 - validation_pct) * n_data_points)) training_files = filenames[:n_train] validation_files = filenames[n_train:] training_gen = DataGenerator(training_files) validation_gen = DataGenerator(validation_files) # Create model model = get_edge_detection_model(model_cfg) # Train model model.compile(loss=binary_crossentropy, optimizer=Adam(lr=training_cfg['learning_rate']), metrics=['accuracy']) model.fit_generator(generator=training_gen, validation_data=validation_gen, #use_multiprocessing=True, #workers=2, verbose=1, epochs=training_cfg['num_epochs']) # Save model model.save(output_fn)