Skip to content
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

Downloading TotalSpineSeg Model Weights and Offline Installation #97

Open
tomDag25 opened this issue Dec 12, 2024 · 9 comments
Open

Downloading TotalSpineSeg Model Weights and Offline Installation #97

tomDag25 opened this issue Dec 12, 2024 · 9 comments

Comments

@tomDag25
Copy link

Hey, I was wondering how I could just download the weights of totalspineseg ? I want to use the model offline and I need to be able to access the model without internet access.
Thanks !

@yw7
Copy link
Collaborator

yw7 commented Dec 20, 2024

Hi @tomDag25,

Thank you for using TotalSpineSeg!

To install the model weights offline:

  1. Install TotalSpineSeg:

    • Follow the installation instructions in the README. Ensure you pull and install version 20241115.
  2. Download the model weights:

  3. Set the directory:

    • Place the downloaded .zip files (without extraction) in totalspineseg/models/nnUNet/exports.
    • If you've set the TOTALSPINESEG_DATA environment variable, use: $TOTALSPINESEG_DATA/nnUNet/exports.

With these files in place, TotalSpineSeg will recognize the zip files and install them without requiring an internet connection when you run the totalspineseg command.

If you have further questions or need additional assistance, please don't hesitate to ask.

Additionally, please note that TotalSpineSeg has been integrated into the Spinal Cord Toolbox, providing an alternative platform for utilization: https://spinalcordtoolbox.com/.

@tomDag25
Copy link
Author

tomDag25 commented Jan 8, 2025

Thanks it worked !

@tomDag25
Copy link
Author

tomDag25 commented Jan 8, 2025

Okay sorry I spoke too fast it's not working.

I can download the model using your link but there is an issue:
The problem is that the git version of totalspineseg is not compatible with r20241115, it's not the good release.

The fact that it's not the good version of the model leads to problems with the folders name.

In my case the code is expecting:
Dataset101_TotalSpineSeg_step1
but gets
Dataset101_TotalSpineSeg_step1_r20241115

If I manually remove the r20241115 I get another error when the model is trying to get the dataset.json since the name of the version changes.

@tomDag25
Copy link
Author

tomDag25 commented Jan 8, 2025

This is the error message I get when removing the r20241115

Traceback (most recent call last):
  File "/opt/conda/bin/nnUNetv2_predict", line 8, in <module>
    sys.exit(predict_entry_point())
  File "/opt/conda/lib/python3.10/site-packages/nnunetv2/inference/predict_from_raw_data.py", line 861, in predict_entry_point
    predictor.initialize_from_trained_model_folder(
  File "/opt/conda/lib/python3.10/site-packages/nnunetv2/inference/predict_from_raw_data.py", line 74, in initialize_from_trained_model_folder
    dataset_json = load_json(join(model_training_output_dir, 'dataset.json'))
  File "/opt/conda/lib/python3.10/site-packages/batchgenerators/utilities/file_and_folder_operations.py", line 68, in load_json
    with open(file, 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/kaggle/working/TotalSpineSeg/tss_input/nnUNet/results/Dataset101_TotalSpineSeg_step1/nnUNetTrainer_16000epochs__nnUNetPlans__3d_fullres_small/dataset.json'

@yw7
Copy link
Collaborator

yw7 commented Jan 8, 2025

Okay sorry I spoke too fast it's not working.

I can download the model using your link but there is an issue:
The problem is that the git version of totalspineseg is not compatible with r20241115, it's not the good release.

The fact that it's not the good version of the model leads to problems with the folders name.

In my case the code is expecting:
Dataset101_TotalSpineSeg_step1
but gets
Dataset101_TotalSpineSeg_step1_r20241115

If I manually remove the r20241115 I get another error when the model is trying to get the dataset.json since the name of the version changes.

Strange, it should be working. We have to investigate this.
In the meantime, try to extract it into ‘nnUNet/results/r20241115’ instead of ‘nnUNet/results’.
In your case you should probably create '/kaggle/working/TotalSpineSeg/tss_input/nnUNet/results/r20241115' and extract there.
I can't test it right now but i think it should be working this way. If not I'll debug it tomorrow.

@tomDag25
Copy link
Author

tomDag25 commented Jan 8, 2025

Tried to change the name of the folder to the name of version it was expected aka nnUNetTrainer_16000epochs__nnUNetPlans__3d_fullres_small and the model is running but the labels don't seem to be the good one.
Did you change the labels in this version in comparison to what is on the github page ?

If I put them in the folder r20241115 like you suggested it doesn't run. The model is not finding the weights.

@yw7
Copy link
Collaborator

yw7 commented Jan 10, 2025

Hi @tomDag25,

I'm sorry for the confusion earlier. There's a simpler way to handle the offline model weights installation. I've also updated the original post for clarity.

To install the model weights offline:

  1. Install TotalSpineSeg:

    • Follow the installation instructions in the README. Ensure you pull and install version 20241115.
  2. Download the model weights:

  3. Set the directory:

    • Place the downloaded .zip files (without extraction) in totalspineseg/models/nnUNet/exports.
    • If you've set the TOTALSPINESEG_DATA environment variable, use: $TOTALSPINESEG_DATA/nnUNet/exports.

With these files in place, TotalSpineSeg will recognize the zip files and install them without requiring an internet connection when you run the totalspineseg command.

Regarding the labels, they remain unchanged from the ones specified in the README. The classes listed there match the step2_output.

This method has been tested and works as expected. Let me know if you need further assistance!

@tomDag25
Copy link
Author

Ok so it's not working and I still get the same error:

Traceback (most recent call last):
  File "/opt/conda/bin/nnUNetv2_predict", line 8, in <module>
    sys.exit(predict_entry_point())
  File "/opt/conda/lib/python3.10/site-packages/nnunetv2/inference/predict_from_raw_data.py", line 861, in predict_entry_point
    predictor.initialize_from_trained_model_folder(
  File "/opt/conda/lib/python3.10/site-packages/nnunetv2/inference/predict_from_raw_data.py", line 74, in initialize_from_trained_model_folder
    dataset_json = load_json(join(model_training_output_dir, 'dataset.json'))
  File "/opt/conda/lib/python3.10/site-packages/batchgenerators/utilities/file_and_folder_operations.py", line 68, in load_json
    with open(file, 'r') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/kaggle/working/TotalSpineSeg/tss_input/nnUNet/results/Dataset101_TotalSpineSeg_step1/nnUNetTrainer_16000epochs__nnUNetPlans__3d_fullres_small/dataset.json'

I think I know why. Basically I'm updating a code that used a former version of totalspineseg offline. The problem is that since it's in kaggle I can't directly upload the libraries I need to upload the wheels and do an offline pip install. The idea is that I didn't upgrade the wheels (only thing I didn't upload actually so the problem must come from that).
Will look into that to see if that's the problem.

@tomDag25
Copy link
Author

That was it. The wheel for totalspineseg I installed was from a former version. This is something to be careful about when using totalspineseg offline with wheels.

Thank you for your help @yw7 !

@yw7 yw7 changed the title Downloading the weights of the model Downloading TotalSpineSeg Model Weights and Offline Installation Jan 11, 2025
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

No branches or pull requests

2 participants