def main(): """ need to specify save path: save_path_npy and save_path_txt :return: """ args = make_parser().parse_args() grasp_sampler_args = utils.read_checkpoint_args(args.grasp_sampler_folder) grasp_sampler_args.is_train = False grasp_evaluator_args = utils.read_checkpoint_args( args.grasp_evaluator_folder) grasp_evaluator_args.continue_train = True estimator = grasp_estimator.GraspEstimator(grasp_sampler_args, grasp_evaluator_args, args) point_cloud = np.load(args.pc_path) generated_grasps, generated_scores = estimator.generate_and_refine_grasps( point_cloud) grasp_pose_score = { 'grasp': np.array(generated_grasps), 'score': np.array(generated_scores) } np.save(args.npy_save_path, grasp_pose_score) print('successfully saved %s' % args.npy_save_path) with open(args.txt_save_path, 'w') as w: for pose, score in zip(generated_grasps, generated_scores): w.write(str(pose)) w.write(' ') w.write(str(score) + '\n') w.flush() print('successfully saved %s' % args.txt_save_path)
def main(args): parser = make_parser() args = parser.parse_args() grasp_sampler_args = utils.read_checkpoint_args(args.grasp_sampler_folder) grasp_sampler_args.is_train = False grasp_evaluator_args = utils.read_checkpoint_args( args.grasp_evaluator_folder) grasp_evaluator_args.continue_train = True estimator = grasp_estimator.GraspEstimator(grasp_sampler_args, grasp_evaluator_args, args) if args.train_data: grasp_sampler_args.dataset_root_folder = args.dataset_root_folder grasp_sampler_args.num_grasps_per_object = 1 grasp_sampler_args.num_objects_per_batch = 1 dataset = DataLoader(grasp_sampler_args) for i, data in enumerate(dataset): generated_grasps, generated_scores = estimator.generate_and_refine_grasps( data["pc"].squeeze()) return generated_grasps, generated_scores else: for npy_file in glob.glob(os.path.join(args.npy_folder, '*.npy'))[::-1]: # Depending on your numpy version you may need to change allow_pickle # from True to False. data = np.load(npy_file, allow_pickle=True, encoding="latin1").item() depth = data['depth'] image = data['image'] K = data['intrinsics_matrix'] # Removing points that are farther than 1 meter or missing depth # values. #depth[depth == 0 or depth > 1] = np.nan np.nan_to_num(depth, copy=False) mask = np.where(np.logical_or(depth == 0, depth > 1)) depth[mask] = np.nan pc, selection = backproject(depth, K, return_finite_depth=True, return_selection=True) pc_colors = image.copy() pc_colors = np.reshape(pc_colors, [-1, 3]) pc_colors = pc_colors[selection, :] # Smoothed pc comes from averaging the depth for 10 frames and removing # the pixels with jittery depth between those 10 frames. object_pc = data['smoothed_object_pc'] generated_grasps, generated_scores = estimator.generate_and_refine_grasps( object_pc) return generated_grasps, generated_scores
def configure(self, cfg: dict): """Additional class configuration Parameters ---------- cfg : dict configuration dict, as sourced from the YAML file """ # Create a namespace from the config dict # Since the GraspNet implementation uses a namespace self.cfg_ns = SimpleNamespace(**self.cfg) self.grasp_sampler_args = utils.read_checkpoint_args( self.cfg_ns.grasp_sampler_folder) self.grasp_sampler_args.is_train = False self.grasp_evaluator_args = utils.read_checkpoint_args( self.cfg_ns.grasp_evaluator_folder) self.grasp_evaluator_args.continue_train = True self.estimator = grasp_estimator.GraspEstimator( self.grasp_sampler_args, self.grasp_evaluator_args, self.cfg_ns)
Returns: grasp_success: list of binary numbers. 0 means that the grasp failed, and 1 means that the grasp succeeded. """ raise NotImplementedError( "The code for grasp evaluation is not released") def __del__(self): del self._grasp_reader if __name__ == '__main__': args = make_parser(sys.argv) utils.mkdir(args.output_folder) grasp_sampler_args = utils.read_checkpoint_args(args.grasp_sampler_folder) grasp_sampler_args.is_train = False grasp_evaluator_args = utils.read_checkpoint_args( args.grasp_evaluator_folder) grasp_evaluator_args.continue_train = True if args.gradient_based_refinement: args.num_refine_steps = 10 args.refinement = "gradient" else: args.num_refine_steps = 20 args.refinement = "sampling" estimator = grasp_estimator.GraspEstimator(grasp_sampler_args, grasp_evaluator_args, args) evaluator = Evaluator( cfg,