jleuschn / dival

Deep Inversion Validation Library
MIT License
75 stars 14 forks source link

how to load my own dataset when I use the iradonmap reconstructor #39

Closed listar0810 closed 2 years ago

listar0810 commented 2 years ago

I wanna to load my own CT datasets when I use the iradonmap reconstructor. I have loaded dataset in my code data_path = folder_path + 'data.pkl'

state = torch.load(data_path)

data_obs_train = state['data_obs_train'] data_obs_test = state['data_obs_test'] u_train = state['u_true_train'] u_test = state['u_true_test']

data_train = TensorDataset(u_train[0:n_samples, :, :, :], data_obs_train[0:n_samples, :, :, :])

as the iradonmap reconstructor example shows the dataset loading method: dataset = get_standard_dataset('lodopab', impl=IMPL)

how can I change my datasets to the standard_dataset format which could be read by iradonmap reconstructor like below: dataset = get_standard_dataset('lodopab', impl=IMPL)

jleuschn commented 2 years ago

The reconstructor's train() method expects a dival.datasets.Dataset instance whose elements are pairs (obs, gt) of ODL space elements (which you can think of as numpy arrays with additional space information). You would need to subclass the dival Datasetclass, which includes defining ODL spaces for both images and sinograms. Since the IRadonMapReconstructor also expects the odl.tomo.RayTransform instance, one can use it to obtain these spaces, i.e. one can use space=(ray_trafo.range, ray_trafo.domain) for the dival Dataset. You can find some examples of dival Dataset subclasses in the repo, a rather minimal one would be this.

The reconstructor then takes care of creating a torch Dataset from the dival Dataset, this is implemented in dival.reconstructors.StandardLearnedReconstructor.train(). Alternatively, you may find it easier to implement a similar method that supports a torch Dataset directly and receives the needed space and dataset split information in a different way.

listar0810 commented 2 years ago

Thx a lot,let me try it!