Lightning-Universe / lightning-bolts

Toolbox of models, callbacks, and datasets for AI/ML researchers.
https://lightning-bolts.readthedocs.io
Apache License 2.0
1.69k stars 321 forks source link

Error when making new CPC_v2 model #679

Closed shatz01 closed 3 years ago

shatz01 commented 3 years ago

🐛 Bug

Missing Attribute "encoder" error when creating new CPC_v2 model. Same code is shown in docs here: https://lightning-bolts.readthedocs.io/en/latest/self_supervised_models.html#research

To Reproduce

Steps to reproduce the behavior:

Run:

from pl_bolts.models.self_supervised import CPC_v2
from pl_bolts.losses.self_supervised_learning import FeatureMapContrastiveTask

amdim_task = FeatureMapContrastiveTask(comparisons='01, 11, 02', bidirectional=True)
model = CPC_v2(contrastive_task=amdim_task)

Error:

Traceback (most recent call last):                                                                                                                                                        
  File "/home/shatz/miniconda3/envs/fix_lightning/lib/python3.9/site-packages/pytorch_lightning/utilities/parsing.py", line 250, in __getattr__                                           
    return self[key]                                                                                                                                                                      
KeyError: 'encoder'                                                                                                                                                                       

The above exception was the direct cause of the following exception:                                                                                                                      

Traceback (most recent call last):                                                                                                                                                        
  File "/home/shatz/Documents/lightning-bolts/mytest.py", line 6, in <module>                                                                                                             
    model = CPC_v2(contrastive_task=amdim_task)                                                                                                                                           
  File "/home/shatz/Documents/lightning-bolts/pl_bolts/models/self_supervised/cpc/cpc_module.py", line 72, in __init__                                                                    
    c, h = self.__compute_final_nb_c(patch_size)                                                                                                                                          
  File "/home/shatz/Documents/lightning-bolts/pl_bolts/models/self_supervised/cpc/cpc_module.py", line 103, in __compute_final_nb_c                                                       
    if self.hparams.encoder != 'cpc_encoder':                                                                                                                                             
  File "/home/shatz/miniconda3/envs/fix_lightning/lib/python3.9/site-packages/pytorch_lightning/utilities/parsing.py", line 252, in __getattr__                                           
    raise AttributeError(f'Missing attribute "{key}"') from exp                                                                                                                           
AttributeError: Missing attribute "encoder" 

Expected behavior

No errors.

Environment

Additional context

The code is from the docs: https://lightning-bolts.readthedocs.io/en/latest/self_supervised_models.html#research

github-actions[bot] commented 3 years ago

Hi! thanks for your contribution!, great first issue!

shatz01 commented 3 years ago

Fixed in Pull Request #680

shatz01 commented 3 years ago

Also its my first time contributing to a big project. Please let me know if I should do anything different.