def prepare_data(self, *args, **kwargs): mnist_test = MNIST(self.root_dir, train=False, download=True).data.type(torch.float32) mnist_train_val = MNIST(self.root_dir, train=True, download=True).data.type(torch.float32) np.random.seed(1612) perm = np.random.permutation(mnist_train_val.shape[0]) mnist_train = mnist_train_val[perm[:55000], 1:, 1:] mnist_val = mnist_train_val[perm[55000:], 1:, 1:] mnist_test = mnist_test[:, 1:, 1:] assert mnist_train.shape[1] == self.gt_shape assert mnist_train.shape[2] == self.gt_shape circle = self.__get_circle__() mnist_train = circle * np.clip(mnist_train, 50, 255) mnist_val = circle * np.clip(mnist_val, 50, 255) mnist_test = circle * np.clip(mnist_test, 50, 255) self.mean = mnist_train.mean() self.std = mnist_train.std() mnist_train = normalize(mnist_train, self.mean, self.std) mnist_val = normalize(mnist_val, self.mean, self.std) mnist_test = normalize(mnist_test, self.mean, self.std) mnist_train *= circle mnist_val *= circle mnist_test *= circle ds_factory = GroundTruthDatasetFactory(mnist_train, mnist_val, mnist_test, inner_circle=self.inner_circle) self.gt_ds = ds_factory.build_projection_dataset(num_angles=self.num_angles, upscale_shape=70, impl='astra_cpu')
def prepare_data(self, *args, **kwargs): if not exists(join(self.root_dir, 'gt_data.npz')): wget.download('https://download.fht.org/jug/fit/Kanji_TRec_gt_data.npz', out=join(self.root_dir, 'gt_data.npz')) gt_data = np.load(join(self.root_dir, 'gt_data.npz')) gt_train = torch.from_numpy(gt_data['gt_train']) gt_val = torch.from_numpy(gt_data['gt_val']) gt_test = torch.from_numpy(gt_data['gt_test']) self.mean = gt_train.mean() self.std = gt_train.std() gt_train = normalize(gt_train, self.mean, self.std) gt_val = normalize(gt_val, self.mean, self.std) gt_test = normalize(gt_test, self.mean, self.std) circle = self.__get_circle__() gt_train *= circle gt_val *= circle gt_test *= circle ds_factory = GroundTruthDatasetFactory(gt_train, gt_val, gt_test, inner_circle=self.inner_circle) self.gt_ds = ds_factory.build_projection_dataset(num_angles=self.num_angles, upscale_shape=133, impl='astra_cpu')
def prepare_data(self, *args, **kwargs): if not exists(join(self.root_dir, 'gt_data.npz')): wget.download( 'https://cloud.mpi-cbg.de/index.php/s/7MK9vNUnq4Ndkhg/download', out=join(self.root_dir, 'gt_data.npz')) gt_data = np.load(join(self.root_dir, 'gt_data.npz')) gt_train = torch.from_numpy(gt_data['gt_train']) gt_val = torch.from_numpy(gt_data['gt_val']) gt_test = torch.from_numpy(gt_data['gt_test']) self.mean = gt_train.mean() self.std = gt_train.std() gt_train = normalize(gt_train, self.mean, self.std) gt_val = normalize(gt_val, self.mean, self.std) gt_test = normalize(gt_test, self.mean, self.std) circle = self.__get_circle__() gt_train *= circle gt_val *= circle gt_test *= circle ds_factory = GroundTruthDatasetFactory(gt_train, gt_val, gt_test, inner_circle=self.inner_circle) impl = kwargs.get('impl', 'skimage') self.gt_ds = ds_factory.build_projection_dataset( num_angles=self.num_angles, upscale_shape=133, impl=impl)
def prepare_data(self, *args, **kwargs): mnist_test = MNIST(self.root_dir, train=False, download=True).data.type(torch.float32) mnist_train_val = MNIST(self.root_dir, train=True, download=True).data.type(torch.float32) np.random.seed(1612) perm = np.random.permutation(mnist_train_val.shape[0]) mnist_train = mnist_train_val[perm[:55000], 1:, 1:] mnist_val = mnist_train_val[perm[55000:], 1:, 1:] mnist_test = mnist_test[:, 1:, 1:] self.mean = mnist_train.mean() self.std = mnist_train.std() mnist_train = normalize(mnist_train, self.mean, self.std) mnist_val = normalize(mnist_val, self.mean, self.std) mnist_test = normalize(mnist_test, self.mean, self.std) self.gt_ds = GroundTruthDatasetFactory(mnist_train, mnist_val, mnist_test)
def prepare_data(self, *args, **kwargs): if not exists(join(self.root_dir, 'gt_data.npz')): wget.download('https://cloud.mpi-cbg.de/index.php/s/Wtuy9IqUsSpjKav/download', out=join(self.root_dir, 'gt_data.npz')) gt_data = np.load(join(self.root_dir, 'gt_data.npz')) gt_train = torch.from_numpy(gt_data['gt_train']) gt_val = torch.from_numpy(gt_data['gt_val']) gt_test = torch.from_numpy(gt_data['gt_test']) self.mean = gt_train.mean() self.std = gt_train.std() gt_train = normalize(gt_train, self.mean, self.std) gt_val = normalize(gt_val, self.mean, self.std) gt_test = normalize(gt_test, self.mean, self.std) self.gt_ds = GroundTruthDatasetFactory(gt_train, gt_val, gt_test)
def prepare_data(self, *args, **kwargs): lodopab = dival.get_standard_dataset('lodopab', impl='astra_cpu') assert self.gt_shape <= self.IMG_SHAPE, 'GT is larger than original images.' if self.gt_shape < self.IMG_SHAPE: crop_off = (362 - self.gt_shape) // 2 gt_train = np.array([lodopab.get_sample(i, part='train', out=(False, True))[1][crop_off:-(crop_off + 1), crop_off:-(crop_off + 1)] for i in range(4000)]) gt_val = np.array([lodopab.get_sample(i, part='validation', out=(False, True))[1][crop_off:-(crop_off + 1), crop_off:-(crop_off + 1)] for i in range(400)]) gt_test = np.array([lodopab.get_sample(i, part='test', out=(False, True))[1][crop_off:-(crop_off + 1), crop_off:-(crop_off + 1)] for i in range(3553)]) else: gt_train = np.array( [lodopab.get_sample(i, part='train', out=(False, True))[1][1:, 1:] for i in range(4000)]) gt_val = np.array( [lodopab.get_sample(i, part='validation', out=(False, True))[1][1:, 1:] for i in range(400)]) gt_test = np.array( [lodopab.get_sample(i, part='test', out=(False, True))[1][1:, 1:] for i in range(3553)]) gt_train = torch.from_numpy(gt_train) gt_val = torch.from_numpy(gt_val) gt_test = torch.from_numpy(gt_test) assert gt_train.shape[1] == self.gt_shape assert gt_train.shape[2] == self.gt_shape self.mean = gt_train.mean() self.std = gt_train.std() gt_train = normalize(gt_train, self.mean, self.std) gt_val = normalize(gt_val, self.mean, self.std) gt_test = normalize(gt_test, self.mean, self.std) circle = self.__get_circle__() gt_train *= circle gt_val *= circle gt_test *= circle ds_factory = GroundTruthDatasetFactory(gt_train, gt_val, gt_test, inner_circle=self.inner_circle) self.gt_ds = ds_factory.build_projection_dataset(num_angles=self.num_angles, upscale_shape=self.gt_shape + (self.gt_shape // 2 - 7), impl='astra_cpu')
def prepare_data(self, *args, **kwargs): if not exists(join(self.root_dir, 'gt_data.npz')): wget.download( 'https://download.fht.org/jug/fit/CelebA_SRes_gt_data.npz', out=join(self.root_dir, 'gt_data.npz')) gt_data = np.load(join(self.root_dir, 'gt_data.npz')) gt_train = torch.from_numpy(gt_data['gt_train']) gt_val = torch.from_numpy(gt_data['gt_val']) gt_test = torch.from_numpy(gt_data['gt_test']) self.mean = gt_train.mean() self.std = gt_train.std() gt_train = normalize(gt_train, self.mean, self.std) gt_val = normalize(gt_val, self.mean, self.std) gt_test = normalize(gt_test, self.mean, self.std) self.gt_ds = GroundTruthDatasetFactory(gt_train, gt_val, gt_test)