Skip to content

PyTorch ver 1.0: keras 3.+ with pytorch backend for nn_models.py and … #1515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

manuelpaeza
Copy link

…associated files, pytorch replaces tensorflow for Volpy's mrcnn folder, parts of cnmf, and components evaluation. Additional testing files implemented and added, and demo folders updated. Lastly, the new pytorch models (weights-layers converted from tensorflow) have been added

Description

PyTorch dependencies are added, Keras is updated to have PyTorch backend, and Tensorflow dependencies are removed. Models are updated into the .pt format and a pytorch_model_arch.py file is added which contains the model architecture for these two files. The Ring CNN model (which uses caiman.utils.nn_models.py and caiman.source_extraction.cnmf.online_cmf.py has been updated for compatibility with torch and keras 3.+. Volpy's MRCNN module (and its respective files) have been updated with pytorch training, validation, and inferencing. Demo notebooks have been updated given these new changes. test_pytorch.py is added to test the pytorch dependency with test_tensorflow.py removed, while test_mrcnn.py has been updated to match the Volpy revisions.

Fixes # (issue)

Dependency changes with revisions to Volpy, component evaluations, and Ring CNN.

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would break back-compatibility)
  • Changes in documentation or new examples for demos and/or use cases.

Branching

  • All PRs should be made against the dev branch. The main branch is not often merged back to dev.
  • If you want to get your PR out to the world faster (urgent bugfix), poke pgunn to cut a release; this will get it onto github and into conda faster

Has your PR been tested?

Yes, it has been tested.

If you're fixing a bug or introducing a new feature it is recommended you run the tests by typing

caimanmanager test

and

caimanmanager demotest

prior to submitting your pull request.

Please describe any additional tests that you ran to verify your changes. If they are fast you can also
include them in the folder 'caiman/tests/and name themtest_***.py` so they can be included in our lists of tests.

mannypaeza added 2 commits August 5, 2025 15:41
…associated files, pytorch replaces tensorflow for Volpy's mrcnn folder, parts of cnmf, and components evaluation. Additional testing files implemented and added, and demo folders updated. Lastly, the new pytorch models (weights-layers converted from tensorflow) have been added
Copy link
Member

@pgunn pgunn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First batch of things.

If it's not too much effort, you can also consider adding type annotations to any new functions you feel like, but there's no real need for it, it'd just be nice (I can do it later if you don't want to)

])
display_table(table)
fname = fnames[ind]
return np.load(dir + fname)['img'], dir + fname
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer os.path.join

Comment on lines 16 to 17
import inspect
import h5py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two somehow ended up out of alphabetical order

print(f"USING MODEL (tensorflow API): {model_file}")
loaded_model = caiman.utils.utils.load_graph(model_file)
raise FileNotFoundError(f"File for requested model {model_name} not found")
print(f"Using model: {model_file}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably should be using the logger rather than print

@@ -2009,8 +2020,7 @@ def get_candidate_components(sv, dims, Yres_buf, min_num_trial=3, gSig=(5, 5),
gHalf=(5, 5), sniper_mode=True, rval_thr=0.85,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's not necessarily code you added, but as I assume you've had to understand this function to rework it, any docs you could add to code-dense parts of this function that might help with understanding would be really useful

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I have some notes, so I could add them in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants