parser.add_argument('--no-cuda', action='store_true', help='Do not use cuda.') parser.add_argument('--eval_input', action='store_true', help='Evaluate inputs instead.') args = parser.parse_args() cfg = config.load_config(args.config, 'configs/default.yaml') is_cuda = (torch.cuda.is_available() and not args.no_cuda) device = torch.device("cuda" if is_cuda else "cpu") # Dataset points_field = data.PointsField( cfg['data']['points_iou_file'], unpackbits=cfg['data']['points_unpackbits'], ) pointcloud_field = data.PointCloudField(cfg['data']['pointcloud_chamfer_file']) fields = { 'points_iou': points_field, 'pointcloud_chamfer': pointcloud_field, 'idx': data.IndexField(), } print('Test split: ', cfg['data']['test_split']) dataset_folder = cfg['data']['path'] dataset = data.Shapes3dDataset_Human(dataset_folder, fields, cfg['data']['test_split'], categories=cfg['data']['classes']) # Evaluator
def get_inputs_field(mode, cfg, use_target_domain = False): ''' Returns the inputs fields. Args: mode (str): the mode which is used cfg (dict): config dictionary use_target_domain (bool): whether to use the target_domain dataset ''' input_type = cfg['data']['input_type'] with_transforms = cfg['data']['with_transforms'] if input_type is None: inputs_field = None elif input_type == 'img': if mode == 'train' and cfg['data']['img_augment']: resize_op = transforms.RandomResizedCrop( cfg['data']['img_size'], (0.75, 1.), (1., 1.)) else: resize_op = transforms.Resize((cfg['data']['img_size'])) transform = transforms.Compose([ resize_op, transforms.ToTensor(), ]) with_camera = cfg['data']['img_with_camera'] if mode == 'train': random_view = True else: random_view = False if use_target_domain: img_folder_name = cfg['data']['uda_img_folder'] filename_pattern= cfg['data']['uda_bg_configure'] else: img_folder_name = cfg['data']['img_folder'] filename_pattern = cfg['data']['img_filename_pattern'] inputs_field = data.ImagesField( img_folder_name, transform, with_camera=with_camera, random_view=random_view, filename_pattern=filename_pattern, extensions=['jpg', 'jpeg', 'png'] ) elif input_type == 'pointcloud': transform = transforms.Compose([ data.SubsamplePointcloud(cfg['data']['pointcloud_n']), data.PointcloudNoise(cfg['data']['pointcloud_noise']) ]) with_transforms = cfg['data']['with_transforms'] inputs_field = data.PointCloudField( cfg['data']['pointcloud_file'], transform, with_transforms=with_transforms ) elif input_type == 'voxels': inputs_field = data.VoxelsField( cfg['data']['voxels_file'] ) elif input_type == 'idx': inputs_field = data.IndexField() else: raise ValueError( 'Invalid input type (%s)' % input_type) return inputs_field
def get_inputs_field(mode, cfg): ''' Returns the inputs fields. Args: mode (str): the mode which is used cfg (dict): config dictionary ''' input_type = cfg['data']['input_type'] with_transforms = cfg['data']['with_transforms'] n_views = cfg['data']['n_views'] if input_type is None: inputs_field = None elif input_type == 'img': if mode == 'train' and cfg['data']['img_augment']: resize_op = transforms.RandomResizedCrop(cfg['data']['img_size'], (0.75, 1.), (1., 1.)) else: resize_op = transforms.Resize((cfg['data']['img_size'])) transform = transforms.Compose([ resize_op, transforms.ToTensor(), ]) with_camera = cfg['data']['img_with_camera'] if mode == 'train': random_view = True else: random_view = False inputs_field = data.ImagesField(cfg['data']['img_folder'], transform, with_camera=with_camera, random_view=random_view) elif input_type == 'multi_img': if mode == 'train' and cfg['data']['img_augment']: resize_op = transforms.RandomResizedCrop(cfg['data']['img_size'], (0.75, 1.), (1., 1.)) else: resize_op = transforms.Resize((cfg['data']['img_size'])) transform = transforms.Compose([ resize_op, transforms.ToTensor(), ]) with_camera = cfg['data']['img_with_camera'] if mode == 'train': random_view = True else: random_view = False inputs_field = data.MultiImageField(cfg['data']['img_folder'], transform=transform, with_camera=with_camera, random_view=random_view, n_views=n_views) elif input_type == 'pointcloud': transform = transforms.Compose([ data.SubsamplePointcloud(cfg['data']['pointcloud_n']), data.PointcloudNoise(cfg['data']['pointcloud_noise']) ]) with_transforms = cfg['data']['with_transforms'] inputs_field = data.PointCloudField(cfg['data']['pointcloud_file'], transform, with_transforms=with_transforms) elif input_type == 'voxels': inputs_field = data.VoxelsField(cfg['data']['voxels_file']) elif input_type == 'idx': inputs_field = data.IndexField() else: raise ValueError('Invalid input type (%s)' % input_type) return inputs_field
def get_data_fields(mode, cfg): ''' Returns the data fields. Args: mode (str): the mode which is used cfg (dict): imported yaml config ''' points_transform = data.SubsamplePoints(cfg['data']['points_subsample']) if cfg.get('sdf_generation', False): points_transform = None with_transforms = cfg['model']['use_camera'] fields = {} fields['points'] = data.PointsField( cfg['data']['points_file'], points_transform, with_transforms=with_transforms, unpackbits=cfg['data']['points_unpackbits'], ) if not cfg.get('sdf_generation', False) and cfg['trainer'].get( 'is_sdf', False): sdf_points_transform = data.SubsampleSDFPoints( cfg['data']['points_subsample']) fields['sdf_points'] = data.SDFPointsField( cfg['data']['sdf_points_file'], sdf_points_transform, with_transforms=with_transforms) pointcloud_transform = data.SubsamplePointcloud( cfg['data']['pointcloud_target_n']) if cfg.get('sdf_generation', False): pointcloud_transform = None fields['pointcloud'] = data.PointCloudField(cfg['data']['pointcloud_file'], pointcloud_transform, with_transforms=True) fields['angles'] = nsd_data.SphericalCoordinateField( cfg['data']['primitive_points_sample_n'], mode, is_normal_icosahedron=cfg['data'].get('is_normal_icosahedron', False), is_normal_uv_sphere=cfg['data'].get('is_normal_uv_sphere', False), icosahedron_subdiv=cfg['data'].get('icosahedron_subdiv', 2), icosahedron_uv_margin=cfg['data'].get('icosahedron_uv_margin', 1e-5), icosahedron_uv_margin_phi=cfg['data'].get('icosahedron_uv_margin_phi', 1e-5), uv_sphere_length=cfg['data'].get('uv_sphere_length', 20), normal_mesh_no_invert=cfg['data'].get('normal_mesh_no_invert', False)) if mode in ('val', 'test'): points_iou_file = cfg['data']['points_iou_file'] voxels_file = cfg['data']['voxels_file'] if points_iou_file is not None: fields['points_iou'] = data.PointsField( points_iou_file, with_transforms=with_transforms, unpackbits=cfg['data']['points_unpackbits'], ) if voxels_file is not None: fields['voxels'] = data.VoxelsField(voxels_file) return fields
def get_inputs_field(mode, cfg): """ Returns the inputs fields. Args: mode (str): the mode which is used cfg (dict): config dictionary """ input_type = cfg["data"]["input_type"] with_transforms = cfg["data"]["with_transforms"] if input_type is None: inputs_field = None elif input_type == "img": transform = None if mode == "train" and cfg["data"]["img_augment"]: # resize_op = transforms.RandomResizedCrop(cfg["data"]["img_size"],(0.75, 1.0), (1.0, 1.0)) def preprocess(image): # image = tf.image.crop_and_resize( # image, crop_size=cfg["data"]["img_size"]) # CHECK image = tf.image.resize( image, [cfg["data"]["img_size"], cfg["data"]["img_size"]]) image /= 255.0 return image transform = preprocess else: def preprocess(image): # image = image[tf.newaxis, ...] image = tf.image.resize( image, [cfg["data"]["img_size"], cfg["data"]["img_size"]]) image /= 255.0 return image transform = preprocess # transform = transforms.Compose([ # resize_op, # transforms.ToTensor(), # ]) with_camera = cfg["data"]["img_with_camera"] if mode == "train": random_view = True else: random_view = False inputs_field = data.ImagesField( cfg["data"]["img_folder"], transform, with_camera=with_camera, random_view=random_view, ) elif input_type == "pointcloud": def preprocess(points): output = data.SubsamplePointcloud( cfg["data"]["pointcloud_n"])(points) output = data.PointcloudNoise( cfg["data"]["pointcloud_noise"])(output) return output transform = preprocess with_transforms = cfg["data"]["with_transforms"] inputs_field = data.PointCloudField(cfg["data"]["pointcloud_file"], transform, with_transforms=with_transforms) elif input_type == "voxels": inputs_field = data.VoxelsField(cfg["data"]["voxels_file"]) elif input_type == "idx": inputs_field = data.IndexField() else: raise ValueError("Invalid input type (%s)" % input_type) return inputs_field