示例#1
0
def load_grasps(obj, source):
    grasps = []
    for root, dirs, files in os.walk(source):
        for f in files:
            if f.find(obj.key) != -1 and f.endswith('.json'):
                filename = os.path.join(root, f)
                with open(filename, 'r') as grasp_file:
                    grasps.append(
                        g.ParallelJawPtGrasp3D.from_json(
                            jsons.load(grasp_file)))
    return grasps
示例#2
0
 def load_grasps(self, key, grasp_dir=None):
     """Loads a list of grasps from a file (grasp_dir/key.json).
     Params:
         key - string name of a graspable
         grasp_dir - string path to the grasp.json directory; defaults to
           self.dataset_root_dir_
     """
     if grasp_dir is None:
         grasp_dir = self.dataset_root_dir_
     path = os.path.join(grasp_dir, Dataset.json_filename(key))
     try:
         with open(path) as f:
             grasps = jsons.load(f)
     except:
         logging.warning('No grasp file found for key %s' % (key))
         return []
     return [grasp.ParallelJawPtGrasp3D.from_json(g) for g in grasps]
示例#3
0
文件: database.py 项目: brianhou/GPIS
 def load_grasps(self, key, grasp_dir=None):
     """Loads a list of grasps from a file (grasp_dir/key.json).
     Params:
         key - string name of a graspable
         grasp_dir - string path to the grasp.json directory; defaults to
           self.dataset_root_dir_
     """
     if grasp_dir is None:
         grasp_dir = self.dataset_root_dir_
     path = os.path.join(grasp_dir, Dataset.json_filename(key))
     try:
         with open(path) as f:
             grasps = jsons.load(f)
     except:
         logging.warning('No grasp file found for key %s' %(key))
         return []
     return [grasp.ParallelJawPtGrasp3D.from_json(g) for g in grasps]
示例#4
0
 def load_all_features(self, grasps, out_rate=50):
     path = os.path.join(self.features_dir_, self.graspable_.key + ".json")
     try:
         with open(path) as f:
             features_json = jsons.load(f)
         num_digits = len(str(len(grasps) - 1))  # for padding with zeros
         features = []
         for i, (feature_json, grasp) in enumerate(zip(features_json, grasps)):
             if i % out_rate == 0:
                 logging.info("Loading features for grasp %d" % (i))
             feature = self._load_feature_rep(
                 feature_json, grasp, "%s_%s" % (self.graspable_.key, str(i).zfill(num_digits))
             )
             features.append(feature)
     except Exception as e:
         logging.warning("Exception in feature loading")
         return []
     return features
示例#5
0
 def load_all_features(self, grasps, out_rate=50):
     path = os.path.join(self.features_dir_, self.graspable_.key + '.json')
     try:
         with open(path) as f:
             features_json = jsons.load(f)
         num_digits = len(str(len(grasps) - 1))  # for padding with zeros
         features = []
         for i, (feature_json,
                 grasp) in enumerate(zip(features_json, grasps)):
             if i % out_rate == 0:
                 logging.info('Loading features for grasp %d' % (i))
             feature = self._load_feature_rep(
                 feature_json, grasp,
                 '%s_%s' % (self.graspable_.key, str(i).zfill(num_digits)))
             features.append(feature)
     except Exception as e:
         logging.warning('Exception in feature loading')
         return []
     return features