NiftyNet icon indicating copy to clipboard operation
NiftyNet copied to clipboard

Straightforward way to re-use model (from zoo) in python

Open michaelschwier opened this issue 6 years ago • 2 comments

Maybe I missed it (if so please give me a hint), but it would be nice if there was a straight forward way to load a pre-trained model from the model zoo and then feed it input data (e.g. as numpy array) via python, run it, and get the results directly in python (e.g. again as numpy array).

If I understand it correctly, such an easy interface is only available via command line?

michaelschwier avatar May 17 '18 15:05 michaelschwier

Yes this is a high priority task on the to-do list, I'm copying @eligibson's ticket here:

It is currently not trivial to run NiftyNet as part of a separate python script. It would be nice to have an alternative to run_application() that let you do the following:

import niftynet
nn = ApplicationDriver()
nn.initialise_application(system_param, input_data_param)
my_output_data_dict = nn.process_image(my_input_data_dict)

This would enable NN to be used more easily in complex pipelines, and integrated more easily into interactive systems.

This would require a few modifications:

  1. a process_image function that takes in a dictionary of data (matching what you would get from a reader?), processes it as if it had been read from a file, and returns the results as would be written to a file.
  2. to facilitate this, the reading/writing to files would need to be decoupled from the preprocessing and the sampler systems.

(FYI @crousseau)

wyli avatar May 18 '18 09:05 wyli

Great to know you are working on it. Let me know when you get there :) I also think this will make a big difference in terms of integrating niftynet into applications.

Thanks @wyli for your quick answers and very nice work on NN!

michaelschwier avatar May 18 '18 13:05 michaelschwier