spacetelescope / hellouniverse

https://spacetelescope.github.io/hellouniverse/
11 stars 13 forks source link

Add pytorch training examples #7

Closed jwuphysics closed 1 year ago

jwuphysics commented 2 years ago

Opening a PR to incorporate a training example using Pytorch in a new notebook. I think this is a good idea because Pytorch is a highly relevant machine learning framework and Hello Universe users can benefit from seeing code in two flavors. Here I am using Fastai on top of Pytorch, which is analogous to using Keras as a high-level API for TensorFlow.

I've run the notebook in Colab, and if you want I can add one of those "Open in Colab" badges which will allow users to train these deeper (18-layer) CNNs using a GPU. I include two examples: one using the standard 18-layer residual neural network, and one using a custom version of the 18-layer residual neural network that I developed two years back.

Unfortunately I haven't done much documentation but I'd be happy to add more! Just let me know if there's any style guide I should conform to, and if there's any requirements I need to jot down (or whatever else for CI/CD).

jwuphysics commented 2 years ago

Relates to Enhancement #8

cmurray-astro commented 2 years ago

Thanks, John! We'll review your notebook and get back to you soon!

cmurray-astro commented 2 years ago

Hi @jwuphysics! Thanks for your patience with this process. We've set up infrastructure for reviewing contributions, and I've added a commit with some output. The first issue I encountered was that pytorch was "not compiled with CUDA enabled". Would you be able to create a requirements file for this notebook (this is something we'll need to make anyway). Thanks!

jwuphysics commented 1 year ago

Sure thing @cmurray-astro! Should I append requirements into the existing requirements.txt file? I'm worried that we might encounter conflicts, i.e. the current one using Keras/TF might conflict with mine using Fastai/Pytorch. In any event I can give it a shot.

cmurray-astro commented 1 year ago

For now I think you can create your own requirements.txt file and we will keep the notebooks and requirements separate during the review stage.

jwuphysics commented 1 year ago

Okay! I think I caught all of the dependencies here. Please note that fastai and its dependencies can be installed via pip or conda, although the latter only works if you're using the custom fastai channel (i.e. conda install -c fastai fastai).

cmurray-astro commented 1 year ago

Thanks, John! I'm working through the notebook and am still getting an error in the learning step that:

AssertionError: Torch not compiled with CUDA enabled

Then with some reading about PyTorch, it appears that CUDA is not supported on macOS: https://github.com/pytorch/pytorch#from-source

I wonder if it's possible to revise the notebook to not rely on CUDA (or perhaps I'm misreading the errors)?

jwuphysics commented 1 year ago

Ah yeah, I didn't execute this locally as Pytorch (and Fastai) are not really meant to be run on macOS. In fact this was written and run on Google Colab.

Maybe I should close this PR and consider forking the project to something like Hello Universe in the cloud?

cmurray-astro commented 1 year ago

Yep I like that idea! Thanks, John!!