def __getitem__(self, index): """Returns the item at index idx. """ data = dict() attributes = dict() synset_idx = self.synset_idxs[index] obj_location = self.paths[index] / 'model.obj' mesh = TriangleMesh.from_obj(str(obj_location)) data['vertices'] = mesh.vertices data['faces'] = mesh.faces attributes['name'] = self.names[index] attributes['path'] = obj_location attributes['synset'] = self.synsets[synset_idx] attributes['label'] = self.labels[synset_idx] return {'data': data, 'attributes': attributes}
def __getitem__(self, index): data = dict() attributes = dict() img_name = self.img_names[index] obj_name = self.obj_names[index] view_num = random.randrange(0, self.views) # load image and mesh img = Image.open(os.path.join(img_name, 'rendering/{:02d}.png'.format(view_num))) mesh = TriangleMesh.from_obj(os.path.join(obj_name, 'models/model_normalized.obj')) # apply transformations to img if self.transform is not None: img = self.transform(img) else: img = torch.FloatTensor(np.array(img)) img = img.permute(2, 0, 1) img = img / 255. # load and process cam param_location = os.path.join(img_name, 'rendering/rendering_metadata.txt') azimuth, elevation, _, distance, _ = np.loadtxt(param_location)[view_num] cam_params = kal.mathutils.geometry.transformations.compute_camera_params(azimuth, elevation, distance) data['images'] = img #data['vertices'] = mesh.vertices #data['faces'] = mesh.faces data['params'] = dict() data['params']['cam_mat'] = cam_params[0] data['params']['cam_pos'] = cam_params[1] data['params']['azi'] = azimuth data['params']['elevation'] = elevation data['params']['distance'] = distance attributes['img_name'] = img_name attributes['obj_name'] = obj_name attributes['synset'] = self.synsets[self.synset_idx[index]] attributes['label'] = self.labels[self.synset_idx[index]] return {'data': data, 'attributes': attributes}
def _get_data(self, index): synset_idx = self.synset_idxs[index] obj_location = self.paths[index] / 'model.obj' mesh = TriangleMesh.from_obj(str(obj_location)) return (mesh, )