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'] if input_type is None: inputs_field = None elif input_type == 'img_seq': 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(), ]) if mode == 'train': random_view = True else: random_view = False inputs_field = data.ImageSubseqField(cfg['data']['img_seq_folder'], transform, random_view=random_view) elif input_type == 'pcl_seq': connected_samples = cfg['data']['input_pointcloud_corresponding'] transform = transforms.Compose([ data.SubsamplePointcloudSeq(cfg['data']['input_pointcloud_n'], connected_samples=connected_samples), data.PointcloudNoise(cfg['data']['input_pointcloud_noise']) ]) inputs_field = data.PointCloudSubseqField( cfg['data']['pointcloud_seq_folder'], transform, seq_len=cfg['data']['length_sequence']) elif input_type == 'end_pointclouds': transform = data.SubsamplePointcloudSeq( cfg['data']['input_pointcloud_n'], connected_samples=cfg['data']['input_pointcloud_corresponding']) inputs_field = data.PointCloudSubseqField( cfg['data']['pointcloud_seq_folder'], only_end_points=True, seq_len=cfg['data']['length_sequence'], transform=transform) 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'] 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 == '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'] 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 'img_extension' in cfg['data']: inputs_field = data.ImagesField( cfg['data']['img_folder'], transform, extension=cfg['data']['img_extension'], with_camera=with_camera, random_view=random_view) else: inputs_field = data.ImagesField(cfg['data']['img_folder'], transform, with_camera=with_camera, random_view=random_view) elif input_type == 'img_with_depth': # data augment not supported transform = transforms.Compose([ transforms.Resize((cfg['data']['img_size'])), transforms.ToTensor(), ]) with_camera = cfg['data']['img_with_camera'] if mode == 'train': random_view = True else: random_view = False data_params = { 'with_camera': with_camera, 'random_view': random_view, } if 'absolute_depth' in cfg['data']: data_params['absolute_depth'] = cfg['data']['absolute_depth'] if 'with_minmax' in cfg['data']: data_params['with_minmax'] = cfg['data']['with_minmax'] if 'img_extension' in cfg['data']: data_params['extension'] = cfg['data']['img_extension'] inputs_field = data.ImagesWithDepthField('img', 'depth', 'mask', transform, **data_params) elif input_type == 'depth_pred': # data augment not supported transform = transforms.Compose([ transforms.Resize((cfg['data']['img_size'])), transforms.ToTensor(), ]) with_camera = cfg['data']['img_with_camera'] if mode == 'train': random_view = True else: random_view = False data_params = { 'with_camera': with_camera, 'random_view': random_view, } if 'absolute_depth' in cfg['data']: data_params['absolute_depth'] = cfg['data']['absolute_depth'] if 'with_minmax' in cfg['data']: data_params['with_minmax'] = cfg['data']['with_minmax'] if 'pred_with_img' in cfg['model']: data_params['with_img'] = cfg['model']['pred_with_img'] if 'img_extension' in cfg['data']: data_params['extension'] = cfg['data']['img_extension'] inputs_field = data.DepthPredictedField('img', 'depth', 'mask', cfg['data']['depth_pred_root'], 'depth_pred', transform, **data_params) elif input_type == 'depth_pointcloud': t_lst = [] if 'depth_pointcloud_n' in cfg['data'] and cfg['data'][ 'depth_pointcloud_n'] is not None: t_lst.append( data.SubsampleDepthPointcloud( cfg['data']['depth_pointcloud_n'])) if 'depth_pointcloud_noise' in cfg['data'] and cfg['data'][ 'depth_pointcloud_noise'] is not None: t_lst.append( data.PointcloudNoise(cfg['data']['depth_pointcloud_noise'])) transform = transforms.Compose(t_lst) if mode == 'train': random_view = True else: random_view = False data_params = { 'random_view': random_view, 'with_camera': True, 'img_folder_name': 'img' } if 'view_penalty' in cfg['training'] and cfg['training'][ 'view_penalty']: data_params['with_mask'] = True data_params['mask_folder_name'] = 'mask' data_params['mask_flow_folder_name'] = 'mask_flow' data_params['extension'] = 'png' img_transform = transforms.Compose([ transforms.Resize((cfg['data']['img_size'])), transforms.ToTensor(), ]) data_params['img_transform'] = img_transform data_params['with_depth_pred'] = True data_params['depth_pred_folder_name'] = 'depth_pred' inputs_field = data.DepthPointCloudField( cfg['data']['depth_pointcloud_root'], cfg['data']['depth_pointcloud_folder'], transform, **data_params) 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.ImagesField(cfg['data']['img_folder'], transform, with_camera=with_camera, random_view=random_view) 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, 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 preprocess(points): output = data.SubsamplePointcloud( cfg["data"]["pointcloud_n"])(points) output = data.PointcloudNoise( cfg["data"]["pointcloud_noise"])(output) return output