ZauggGroup / DeePiCt

Pipeline for the automatic detection and segmentation of particles and cellular structures in 3D Cryo-ET data, based on deep learning (convolutional neural networks).
Apache License 2.0
29 stars 8 forks source link

Struggled loading the model #10

Closed Vilax closed 9 months ago

Vilax commented 1 year ago

Dear developers,

We are integrating Deepict into Scipion framework. However, we are stuck in the segmentation step. We do not know where the problem is if in our integration or in the model file. As you can see below the issue comes when the model is loaded with torch. Unfortunately, torch does not say much about the error, and we are not able to understand what is happening exactly. Just in advance, we downloaded the model several times to ensure the file was not corrupted, as well as we checked that the path withthe model exist before loading the model. Have you ever deal with this error?

Thanks in advance

segment.py --config_file Runs/010219_DeepictSegmentation/extra/TS_001/config.yaml --pythonpath /home/vilas/opt/scipion/software/em/DeePiCt-0/DeePiCt/3d_cnn/src --tomo_name Runs/010219_DeepictSegmentation/extra/TS_001/TS_001.mrc --gpu 0' returned non-zero exit status 1

Traceback (most recent call last): File "/home/vilas/opt/scipion/software/em/DeePiCt-0/DeePiCt/3d_cnn/scripts/segment.py", line 74, in checkpoint = torch.load(model_path, map_location=device) File "/home/vilas/opt/miniconda/lib/python3.9/site-packages/torch/serialization.py", line 713, in load return _legacy_load(opened_file, map_location, pickle_module, pickle_load_args) File "/home/vilas/opt/miniconda/lib/python3.9/site-packages/torch/serialization.py", line 920, in _legacy_load magic_number = pickle_module.load(f, pickle_load_args) _pickle.UnpicklingError: invalid load key, '#'.

frosinastojanovska commented 1 year ago

Dear @Vilax, could you send me the file that creates this error?

Vilax commented 1 year ago

Thanks @frosinastojanovska ,

For the integration we are following the jupyter/collab file. Is this the right way of using deepict?. And therefore the models are taken from the dropbox URL that the notebook has. In particular, for the membrane one:

wget -O membraneModel.pth https://www.dropbox.com/sh/oavbtcvusi07xbh/AADm29QsXAHenTSTkASMcCk0a/3d_cnn/full_vpp_memb_model_IF4_D2_BN.pth?dl=0

Also I tried to download them from here. In fact it is the same link when the model is selected.

I can prepare the files and send them to you, but I did not carried out any different than the command that I pasted above.

Thanks in advance

frosinastojanovska commented 1 year ago

Yes, you can follow the collab notebook for prediction with trained DeePiCt models. I would also ask for the config.yaml file in order to try to reproduce this error.

Vilax commented 1 year ago

@frosinastojanovska this is the config file (see below, a picture to visualize it better). Note that we create this file in execution time.

I will copy a brief summary of our code to give an idea about what we are doing

cluster: logdir: logs cross_validation: active: false folds: 2 statistics_file: cv_statistics.csv dataset_table: Runs/010219_DeepictSegmentation/extra/TS_001/data.csv debug: true evaluation: particle_picking: active: false pr_tolerance_radius: 10 statistics_file: pr_statistics.csv segmentation_evaluation: active: false statistics_file: dice_eval.csv model_path: /home/vilas/opt/scipion/software/em/DeePiCt-0/models/membraneModel.pth output_dir: Runs/010219_DeepictSegmentation/extra/TS_001 postprocessing_clustering: active: false calculate_motl: false clustering_connectivity: 3 contact_distance: 10 contact_mode: intersection ignore_border_thickness:

imagen

Vilax commented 1 year ago

A short explanation about the previous post:

Deepict folder Runs/010219_DeepictSegmentation -> the number 010219 is just an identifier, it does not matter

The results are writen in extra folder Runs/010219_DeepictSegmentation/extra

Because we allow the management of many tomograms, a folder per tomogram is created Runs/010219_DeepictSegmentation/extra/TS_001 -> This is the folder with the results of the tomogram TS_001

Inside the tomogram folder (TS_001) we store all deepict files related with that tomogram. For instance the config file. An illustrative image

imagen

The config file I posted is the one that is in this folder

Regarding about how we manage the deepict executions... they are carried out in steps. For each tomogram, we execute the deepict steps:

imagen

And later in each step we run the corresponding command lines.

I hope this helps a little bit, let me know any else information I can provide

Thanks in advance

frosinastojanovska commented 1 year ago

@Vilax could you please test the weights file through the Colab notebook? You can upload your local model weights file after running step 2.1 in the Colab. Delete the existing file /content/model_weights.pth and upload your file (with the same name model_weights.pth). If the same error occurs there, then the file is corrupted somehow.

From the other info you provided, I cannot see anything that can be a problem.

Vilax commented 1 year ago

@frosinastojanovska Thanks for your support, we have checked in the google collab. And the models are perfectly working.

We will check our integration to figure out what is the problem. I will let you know once it will be working just in case you feel curiosity about it

Best

frosinastojanovska commented 1 year ago

@Vilax, yes please give us an update and let us know if we can help with some parts.

All the best

Vilax commented 1 year ago

@frosinastojanovska , good news we could fix the problem, and now we are proud to announce that Deepict is fully integrated into ScipionTomo framework

We would be really happy to show you the final result in call if you want and also discuss the future updates maintenance ...

The integration in Scipion would also allow the processing of sets of tomograms in streaming and interoperability with other packages.

Here a screenshot of the integration

imagen