ctlearn-project / ctlearn

Deep Learning for IACT Event Reconstruction
BSD 3-Clause "New" or "Revised" License
52 stars 43 forks source link

Set input weights into a TRN model - Transfer Learning #210

Open rcervinoucm opened 3 weeks ago

rcervinoucm commented 3 weeks ago

Describe the bug I am traying to set a weight set as input for a TRN model a TRN model, and I am getting this error:

pd.DataFrame( /home/rcervino/anaconda3/envs/mrkrabs2/lib/python3.10/site-packages/dl1_data_handler/reader.py:818: PerformanceWarning: your performance may suffer as PyTables will pickle object types that it cannot map directly to c-types [inferred_type->mixed-integer,key->block0_items] [items->None] pd.DataFrame( INFO: Number of events loaded: 2810246 INFO:Setting up model: INFO: Constructing model from config. Traceback (most recent call last): File "/home/rcervino/anaconda3/envs/mrkrabs2/bin/ctlearn", line 8, in sys.exit(main()) File "/home/rcervino/anaconda3/envs/mrkrabs2/lib/python3.10/site-packages/ctlearn/run_model.py", line 691, in main run_model(config, mode="train", debug=args.debug, log_to_file=args.log_to_file, save_best_only= args.save_best_only) File "/home/rcervino/anaconda3/envs/mrkrabs2/lib/python3.10/site-packages/ctlearn/run_model.py", line 178, in run_model backbone, backbone_inputs = backbone_model(data, model_params) File "/home/rcervino/anaconda3/envs/mrkrabs2/lib/python3.10/site-packages/ctlearn/default_models/single_cnn.py", line 123, in single_cnn_model return singlecnn_model, network_input UnboundLocalError: local variable 'singlecnn_model' referenced before assignment

To Reproduce Steps to reproduce the behavior:

  1. Use a weight set as input - Command like: ctlearn -r type -w /data2/datasets/mrkrabs/Training/30.390_az_266.360/particletype/ -d TRN --num_epochs 15 --clean --input /data2/datasets/mrkrabs/TrainingDataMC/ --pattern "*" --tel_types LST_LST_LSTCam --size_cut 50 --output .
TjarkMiener commented 3 weeks ago

Thanks for reporting @rcervinoucm. I think it would be matter for renaming model to singlecnn_model here. Can you please take care of it?

TjarkMiener commented 3 weeks ago

I just checked, I think loaded_model needs to be renamed to singlecnn_model.

rcervinoucm commented 3 weeks ago

I have to change loaded_model and model, right?

TjarkMiener commented 3 weeks ago

Only loaded_model should be enough. The other variable called model is just there to set the layer to trainable or not. Maybe a more descriptive name would be good for this one (e.g. backbone_layer or so).

TjarkMiener commented 3 weeks ago

I solved it in the new model API here.

rcervinoucm commented 3 weeks ago

I solved locally and in the branch issue210, haven't made a pull request because I was locally testing. Do you think I should remove the branch and wait until de API deployment?