conor-horgan / spectrai

spectrai: a deep learning framework for spectral data
Apache License 2.0
49 stars 13 forks source link

Example code #1

Open no-clue-what-to-do opened 2 years ago

no-clue-what-to-do commented 2 years ago

Could you post an example of using the spectral denoising model with python? I'm very interested in trying out your methods on my own data, but I'm confused about how to interface my data and how to use your scripts. Is it possible to write a standalone script to train a model with the architecture you use, or do I have to edit the train.py file?

Thanks!

conor-horgan commented 2 years ago

Hi,

If you would like to train a denoising model using an architecture already implemented in spectrai, the only thing you would need to create/modify is a .yaml config file that defines your setup. An example config file for denoising can be found here. You can edit the various different settings and parameters to suit your case. In particular, you will have to edit the paths for input and target data under DataManger_Options. Note that this assumes that your spectral data is stored as an array of size (n x L) where n is the number of spectra in your dataset and L is the spectral length (either as a .mat or a .npy file).

Then, to train you can type (once you have installed spectrai):

>> spectrai_train --config custom_config.yml --verbose

Where custom_config.yml is the custom config file you have created and saved in the spectrai configs directory.

If you are interested in a standalone spectral denoising model in Python (without some of the overheads of using spectrai) you can also check out DeepeR

no-clue-what-to-do commented 2 years ago

Where does the model get saved when you do this procedure? I see that a I have new tensorboard data, but I don't see where a model was saved

conor-horgan commented 2 years ago

The save_output function defines where models are saved. This will create a new folder called 'saved_models' in the spectrai directory. This function is called in the train_epoch function here.

no-clue-what-to-do commented 2 years ago

Hey,

So I actually used the train_epoch function on its own and didn't get a saved model for some reason. I got it to work by changing the save_frequency to 1 instead of zero. No clue why this would do the trick, because the logic on line 130 of trainer.py seems to work properly when save frequency is set to zero.

I didn't use the spectra_train command because my system isn't recognizing (even though I have spectrai installed with pip). Not sure why this isn't working either.

Sorry for the kind of basic questions. I'm jsut trying to compare multiple methods of spectral denoising for Raman spectra and I'm reading a lot of new code that I'm not used to! Thanks so much for making this public, really appreciate it

Kevin