def __init__(self, root, split, isize, nsamples, noise_info, dynamic_info): # -- set init params -- self.root = root self.split = split self.noise_info = noise_info self.dynamic_info = dynamic_info self.nsamples = nsamples self.isize = isize # -- create transforms -- self.noise_trans = get_noise_transform(noise_info, noise_only=True) self.dynamic_trans = get_dynamic_transform(dynamic_info, None, load_res) # -- load paths -- self.paths = [] # -- limit num of samples -- self.indices = enumerate_indices(len(self.paths), nsamples) self.nsamples = len(self.indices) # -- single random dynamics -- self.dyn_once = return_optional(dynamic_info, "sim_once", False) self.fixRandDynamics = RandomOnce(self.dyn_once, nsamples) # -- single random noise -- self.noise_once = return_optional(noise_info, "sim_once", False) self.fixRandNoise_1 = RandomOnce(self.noise_once, nsamples) self.fixRandNoise_2 = RandomOnce(self.noise_once, nsamples)
def __init__(self, info, noise_trans=None, load_res=False): # -- setup parameters -- self.nframes = info['nframes'] self.ppf = info['ppf'] self.frame_size = info['frame_size'] self.load_res = load_res self.sobel_filter = create_sobel_filter() # -- manage frame size -- if isinstance(self.frame_size, int): self.frame_size = (self.frame_size, self.frame_size) if not (self.frame_size is None): if self.frame_size[0] <= 64: self.very_small = True else: self.very_small = False self.min_frame_size = np.min(self.frame_size) else: self.very_small = None self.min_frame_size = None # -- optional -- self.total_pixels = return_optional(info, 'total_pixels', 0) self.random_eraser_bool = return_optional(info, 'random_eraser_bool', False) self.reset_seed = return_optional(info, 'reset_seed', False) self.textured = return_optional(info, 'textured', False) # -- init vars and consts -- self.random_eraser = thT.RandomErasing() #scale=(0.40,0.80)) self.PI = 2 * torch.acos(torch.zeros(1)).item() self.szm = thT.Compose([ScaleZeroMean()]) self.noise_trans = noise_trans
def get_cbsd68_dataset(cfg): # # -- extract -- # # -- misc -- root = cfg.dataset.root noise_info = cfg.noise_params[cfg.noise_type] dynamic_info = cfg.dynamic isize = return_optional(cfg, "frame_size", None) # -- samples -- nsamples = return_optional(cfg, "nsamples", 0) tr_nsamples = return_optional(cfg, "tr_nsamples", nsamples) val_nsamples = return_optional(cfg, "val_nsamples", nsamples) te_nsamples = return_optional(cfg, "te_nsamples", nsamples) # -- setup paths -- root = Path(root) / Path("./template/images/") # -- create objcs -- data = edict() data.tr = Template(root, "train", isize, tr_nsamples, noise_params, dynamic_info) data.val = Template(root, "val", isize, val_samples, noise_params, dynamic_info) data.test = Template(root, "test", isize, te_samples, noise_params, dynamic_info) # -- create loader -- loader = get_loader(cfg, data, cfg.batch_size) return data, loader
def __init__(self, iroot, froot, sroot, split, isize, ps, nsamples, nframes, noise_info): # -- set init params -- self.iroot = iroot self.froot = froot self.sroot = sroot self.split = split self.noise_info = noise_info self.ps = ps self.nsamples = nsamples self.isize = isize # -- create transforms -- self.noise_trans = get_noise_transform(noise_info, noise_only=True) # -- load paths -- self.paths, self.nframes, all_eq = read_files(iroot, froot, sroot, split, isize, ps, nframes) if not (all_eq): print("\n\n\n\nWarning: Not all bursts are same length!!!\n\n\n\n") self.groups = sorted(list(self.paths['images'].keys())) # -- limit num of samples -- self.indices = enumerate_indices(len(self.paths['images']), nsamples) self.nsamples = len(self.indices) # -- single random noise -- self.noise_once = return_optional(noise_info, "sim_once", False) self.fixRandNoise_1 = RandomOnce(self.noise_once, nsamples) self.fixRandNoise_2 = RandomOnce(self.noise_once, nsamples)
def get_cbsd68_dataset(cfg): # # -- extract -- # # -- noise and dyanmics -- noise_info = cfg.noise_params dynamic_info = cfg.dynamic_info isize = return_optional(cfg, "frame_size", None) # -- samples -- nsamples = return_optional(cfg, "nsamples", 0) tr_nsamples = return_optional(cfg, "tr_nsamples", nsamples) val_nsamples = return_optional(cfg, "val_nsamples", nsamples) te_nsamples = return_optional(cfg, "te_nsamples", nsamples) # -- setup paths -- root = IMAGE_PATH # -- checks / re-assignments -- dynamic_info.frame_size = isize # -- create objcs -- data = edict() data.tr = CBSD68(root, "train", isize, tr_nsamples, noise_info, dynamic_info) data.val = CBSD68(root, "val", isize, val_nsamples, noise_info, dynamic_info) data.te = CBSD68(root, "test", isize, te_nsamples, noise_info, dynamic_info) # -- create loader -- loader = get_loader(cfg, data, cfg.batch_size) return data, loader
def get_set8_dataset(cfg): # # -- extract -- # # -- noise and dyanmics -- noise_info = cfg.noise_params isize = return_optional(cfg, "frame_size", None) nframes = return_optional(cfg, "nframes", None) ps = return_optional(cfg.dataset, "patchsize", 3) tr_split = return_optional(cfg, "train_split", "train") # alt = ["all"] # -- samples -- nsamples = return_optional(cfg, "nsamples", 0) tr_nsamples = return_optional(cfg, "tr_nsamples", nsamples) val_nsamples = return_optional(cfg, "val_nsamples", nsamples) te_nsamples = return_optional(cfg, "te_nsamples", nsamples) # -- setup paths -- iroot = IMAGE_PATH froot = FLOW_PATH sroot = IMAGE_SETS # -- create objcs -- data = edict() data.tr = SET8(iroot, froot, sroot, tr_split, isize, ps, tr_nsamples, nframes, noise_info) data.val = SET8(iroot, froot, sroot, "val", isize, ps, val_nsamples, nframes, noise_info) data.te = SET8(iroot, froot, sroot, "test", isize, ps, te_nsamples, nframes, noise_info) # -- create loader -- loader = get_loader(cfg, data, cfg.batch_size) return data, loader
def load_resample_dataset(cfg, records, use_wrapper=True): # -- sims from cfg -- noise_fxn, dynamic_fxn = transforms_from_cfg(cfg) # -- cfg copy without noise -- cfg_copy = copy.deepcopy(cfg) cfg_copy.noise_params.ntype = 'none' cfg_copy.noise_params['none'] = {} data, loader = load_dataset(cfg_copy, cfg_copy.dataset.mode) full_image_index = return_optional(cfg_copy.dataset, 'full_image_index', 2) # -- wrapped -- wdata = edict({}) for key, value in data.items(): if use_wrapper: wrapper = WrapperDataset(value, noise_fxn, dynamic_fxn, full_image_index) else: wrapper = value wdata[key] = ResampleWrapperDataset(wrapper, records[key]) wloader = get_loader(cfg, wdata, cfg.batch_size, None) return wdata, wloader
def get_burst_with_flow_kitti_dataset(cfg, mode): root = cfg.dataset.root root = Path(root) / Path("kitti") data = edict() batch_size = cfg.batch_size rtype = 'dict' if cfg.dataset.dict_loader else 'list' nnf_K = 3 nnf_ps = 3 nnf_exists = return_optional(cfg.dataset, 'nnf_exists', True) crop = cfg.frame_size if isinstance(crop, int): print("WARNING: the [cfg.frame_size] parameter is just an int.") path_resize = (1224, 370) load_resize = crop #(256, 128) resizes = edict({'path': path_resize, 'load': load_resize}) if mode == "dynamic": edition = "2015" nframes = cfg.nframes noise_info = cfg.noise_params data.tr = BurstWithFlowKITTI(root, "train", edition, nframes, noise_info, crop, resizes, nnf_K, nnf_ps, nnf_exists) data.val = BurstWithFlowKITTI(root, "val", edition, nframes, noise_info, crop, resizes, nnf_K, nnf_ps, nnf_exists) data.te = BurstWithFlowKITTI(root, "test", edition, nframes, noise_info, crop, resizes, nnf_K, nnf_ps, nnf_exists) else: raise ValueError(f"Unknown KITTI mode {mode}") # for split in data: # print(split,len(data[split])) loader = get_loader(cfg, data, batch_size, mode) return data, loader
def get_burst_kitti_dataset(cfg, mode): root = cfg.dataset.root root = Path(root) / Path("kitti") data = edict() batch_size = cfg.batch_size rtype = 'dict' if cfg.dataset.dict_loader else 'list' nnf_K = 3 nnf_ps = 3 nnf_exists = return_optional(cfg.dataset, 'nnf_exists', True) if mode in ["dynamic", "denoising"]: edition = "2015" nframes = cfg.nframes noise_info = cfg.noise_params data.tr = BurstKITTI(root, "train", edition, nframes, noise_info, nnf_K, nnf_ps, nnf_exists) data.val = BurstKITTI(root, "val", edition, nframes, noise_info, nnf_K, nnf_ps, nnf_exists) data.te = BurstKITTI(root, "test", edition, nframes, noise_info, nnf_K, nnf_ps, nnf_exists) else: raise ValueError(f"Unknown KITTI mode {mode}") loader = get_loader(cfg, data, batch_size, mode) return data, loader