altndrr / clup

Code implementation of our BMVC 2022 paper: Cluster-level pseudo-labelling for source-free cross-domain facial expression recognition
MIT License
10 stars 1 forks source link

AttributeError: 'NoneType' object has no attribute 'encoder' #4

Open KhinChoWin-AI opened 9 months ago

KhinChoWin-AI commented 9 months ago

Clustering 15339 samples num_samples_class=4601 num_samples_class=0 num_samples_class=0 num_samples_class=0 num_samples_class=0 num_samples_class=0 num_samples_class=0 Selected a total of 4601 samples Using 16bit native Automatic Mixed Precision (AMP) Trainer already configured with model summary callbacks: [<class 'pytorch_lightning.callbacks.rich_model_summary.RichModelSummary'>]. Skipping setting a default ModelSummary callback. GPU available: True, used: True TPU available: False, using: 0 TPU cores IPU available: False, using: 0 IPUs HPU available: False, using: 0 HPUs before init in systems.clup model: None ╭───────────────────────────── Traceback (most recent call last) ──────────────────────────────╮ │ │ │ /home1/ai20resch16001/anaconda3/lib/python3.9/runpy.py:197 in _run_module_as_main │ │ │ │ 194 │ main_globals = sys.modules["main"].dict │ │ 195 │ if alter_argv: │ │ 196 │ │ sys.argv[0] = mod_spec.origin │ │ ❱ 197 │ return _run_code(code, main_globals, None, │ │ 198 │ │ │ │ │ "main", mod_spec) │ │ 199 │ │ 200 def run_module(mod_name, init_globals=None, │ │ /home1/ai20resch16001/anaconda3/lib/python3.9/runpy.py:87 in _run_code │ │ │ │ 84 │ │ │ │ │ loader = loader, │ │ 85 │ │ │ │ │ package = pkg_name, │ │ 86 │ │ │ │ │ spec = mod_spec) │ │ ❱ 87 │ exec(code, run_globals) │ │ 88 │ return run_globals │ │ 89 │ │ 90 def _run_module_code(code, init_globals=None, │ │ │ │ /home1/ai20resch16001/clup/cli/main.py:54 in │ │ │ │ 51 │ │ │ command = COMMANDS.get(key) │ │ 52 │ │ │ if command and value: │ │ 53 │ │ │ │ cmd = command(options, console) │ │ ❱ 54 │ │ │ │ cmd.run() │ │ 55 │ │ │ │ print("after run") │ │ 56 │ │ │ │ executed = True │ │ 57 │ │ │ │ break │ │ │ │ /home1/ai20resch16001/clup/cli/commands/clup.py:143 in run │ │ │ │ 140 │ │ │ criterion_kw["reduction"] = criterion_kw.get("reduction", "batchmean") │ │ 141 │ │ │ criterion = torch.nn.KLDivLoss(criterion_kw) │ │ 142 │ │ │ │ ❱ 143 │ │ system = CluPSystem( │ │ 144 │ │ │ model, │ │ 145 │ │ │ labels, │ │ 146 │ │ │ labeled_samples=subset_idxs, │ │ │ │ /home1/ai20resch16001/clup/src/systems/clup.py:30 in init │ │ │ │ 27 │ ) -> None: │ │ 28 │ │ print("before init in systems.clup") │ │ 29 │ │ print("model: ", model) │ │ ❱ 30 │ │ super().init(model, *args, pseudo_every=1, *kwargs) │ │ 31 │ │ self.labels = labels │ │ 32 │ │ self.labeled_samples: List[int] = labeled_samples or [] │ │ 33 │ │ self.train_criterion = self.criterion │ │ │ │ /home1/ai20resch16001/clup/src/systems/mixins/pseudo_labelling.py:20 in init │ │ │ │ 17 │ """Implementation of a mixin for pseudo labelling.""" │ │ 18 │ │ │ 19 │ def init(self, args, kwargs) -> None: │ │ ❱ 20 │ │ super().init(*args, kwargs) │ │ 21 │ │ self.pseudo_labels: Tensor │ │ 22 │ │ self.pseudo_labels_confidence: Tensor │ │ 23 │ │ self.pseudo_every = kwargs.get("pseudo_every", 10) │ │ │ │ /home1/ai20resch16001/clup/src/systems/mixins/mixup.py:13 in init │ │ │ │ 10 │ """Implementation of a mixin for mixup.""" │ │ 11 │ │ │ 12 │ def init(self, *args, *kwargs) -> None: │ │ ❱ 13 │ │ super().init(args, kwargs) │ │ 14 │ │ self.mixup_alpha = kwargs.get("mixup_alpha", -1) │ │ 15 │ │ self.mixup_last_lambda = -1 │ │ 16 │ │ │ │ /home1/ai20resch16001/clup/src/systems/mixins/base.py:15 in init │ │ │ │ 12 │ """Implementation of an abstract mixin class.""" │ │ 13 │ │ │ 14 │ def init(self, *args, kwargs) -> None: │ │ ❱ 15 │ │ super().init(*args, *kwargs) │ │ 16 │ │ │ │ 17 │ │ if not hasattr(self, "metrics"): │ │ 18 │ │ │ self.metrics: Dict[str, MetricCollection] │ │ │ │ /home1/ai20resch16001/clup/src/systems/classification.py:38 in init │ │ │ │ 35 │ │ :param lr: learning rate of the system │ │ 36 │ │ :param lr_scheduler: learning rate policy for training │ │ 37 │ │ """ │ │ ❱ 38 │ │ super().init(model, args, kwargs) │ │ 39 │ │ │ │ 40 │ │ self.criterion: Module = torch.nn.CrossEntropyLoss() │ │ 41 │ │ if criterion: │ │ │ │ /home1/ai20resch16001/clup/src/systems/base.py:32 in init │ │ │ │ 29 │ │ self.kwargs = kwargs │ │ 30 │ │ self.save_hyperparameters(kwargs) │ │ 31 │ │ │ │ ❱ 32 │ │ print("model.encoder in systems.base#######", model.encoder) │ │ 33 │ │ │ │ 34 │ │ self.encoder = model.encoder │ │ 35 │ │ self.classifier = model.classifier │ ╰──────────────────────────────────────────────────────────────────────────────────────────────╯ AttributeError: 'NoneType' object has no attribute 'encoder'

altndrr commented 8 months ago

Can you share the env? What command did you execute to get this output?

KhinChoWin-AI commented 7 months ago

The env is as follows: name: base channels:

The command is python -m cli clup \ ./models/target/pretrained/swav-1000ep-FER2013-5000prototypes.ckpt \ ./models/source/resnet18_rafdb.pt \ fer2013 \ --epochs 50 \ --lr 0.1 \ --batch_size 32 \ --optimizer sgd \ --optimizer_kw "{\"weight_decay\": 0.0005, \"momentum\": 0.9, \"nesterov\": true}" \ --lr_scheduler cosine_annealing \ --lr_scheduler_kw "{\"T_max\": 50}" \ --mixup_alpha 0.2 \ --labeled_samples_mode purity \ --labeled_samples_mode_kw "{\"num_prototypes\": 250, \"drop_outliers\": false, \"iter_clusters\": 1}" \ --labeled_samples_size 0.3

altndrr commented 7 months ago

From this I am not sure I can check the list of packages installed. Did you follow the instructions to install? Did you then also source the venv? Just making sure before moving on with other possible causes.

KhinChoWin-AI commented 7 months ago

Yes, I also followed the same stepup that you mentioned using .venv.

altndrr commented 7 months ago

Have you tried other commands? Is this the only one that does not work? Can you confirm the two args pointing to model weights link to existing files?