You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey guys :) I want to use WinCLIP for my custom dataset. In order to "calibrate the thresholds" I use engine.validate before prediction as described e.g. in (#2446#2701) For zero-shot mode this works as expected. However I just cannot bring it to work for few-shot mode when adding custom reference images.
This is my code. When adding the few_shot_source I always run in a problem with the pre_processor. It seems that in this case the test_transform attribute is missing. Any ideas how I can solve this?
Any help would be greatly appreciated!
File ~/projects/WINCLIP_try2/.venv/lib/python3.12/site-packages/anomalib/models/image/winclip/lightning_model.py:150, in WinClip.setup(failed resolving arguments)
146 if self.few_shot_source:
147 logger.info("Loading reference images from %s", self.few_shot_source)
148 reference_dataset = PredictDataset(
149 self.few_shot_source,
--> 150 transform=self.pre_processor.test_transform if self.pre_processor else None,
151 )
152 dataloader = DataLoader(reference_dataset, batch_size=1, shuffle=False, pin_memory=True)
153 else:
File ~/projects/WINCLIP_try2/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py:1964, in Module.getattr(self, name)
1962 if name in modules:
1963 return modules[name]
-> 1964 raise AttributeError(
1965 f"'{type(self).name}' object has no attribute '{name}'"
1966 )
AttributeError: 'PreProcessor' object has no attribute 'test_transform'
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey guys :) I want to use WinCLIP for my custom dataset. In order to "calibrate the thresholds" I use engine.validate before prediction as described e.g. in (#2446 #2701) For zero-shot mode this works as expected. However I just cannot bring it to work for few-shot mode when adding custom reference images.
This is my code. When adding the few_shot_source I always run in a problem with the pre_processor. It seems that in this case the test_transform attribute is missing. Any ideas how I can solve this?
Any help would be greatly appreciated!
AttributeError Traceback (most recent call last)
Cell In[15], line 1
----> 1 validations = engine.validate(model=model, datamodule=datamodule)
2 print(validations)
File ~/projects/WINCLIP_try2/.venv/lib/python3.12/site-packages/anomalib/engine/engine.py:460, in Engine.validate(self, model, dataloaders, ckpt_path, verbose, datamodule)
458 if model:
459 self._setup_trainer(model)
--> 460 return self.trainer.validate(model, dataloaders, ckpt_path, verbose, datamodule)
File ~/projects/WINCLIP_try2/.venv/lib/python3.12/site-packages/lightning/pytorch/trainer/trainer.py:663, in Trainer.validate(self, model, dataloaders, ckpt_path, verbose, datamodule)
661 self.state.status = TrainerStatus.RUNNING
662 self.validating = True
--> 663 return call._call_and_handle_interrupt(
664 self, self._validate_impl, model, dataloaders, ckpt_path, verbose, datamodule
665 )
File ~/projects/WINCLIP_try2/.venv/lib/python3.12/site-packages/lightning/pytorch/trainer/call.py:49, in _call_and_handle_interrupt(trainer, trainer_fn, *args, **kwargs)
47 if trainer.strategy.launcher is not None:
48 return trainer.strategy.launcher.launch(trainer_fn, *args, trainer=trainer, **kwargs)
---> 49 return trainer_fn(*args, **kwargs)
51 except _TunerExitException:
52 _call_teardown_hook(trainer)
File ~/projects/WINCLIP_try2/.venv/lib/python3.12/site-packages/lightning/pytorch/trainer/trainer.py:705, in Trainer._validate_impl(self, model, dataloaders, ckpt_path, verbose, datamodule)
701 download_model_from_registry(ckpt_path, self)
702 ckpt_path = self._checkpoint_connector._select_ckpt_path(
703 self.state.fn, ckpt_path, model_provided=model_provided, model_connected=self.lightning_module is not None
704 )
--> 705 results = self._run(model, ckpt_path=ckpt_path)
706 # remove the tensors from the validation results
707 results = convert_tensors_to_scalars(results)
File ~/projects/WINCLIP_try2/.venv/lib/python3.12/site-packages/lightning/pytorch/trainer/trainer.py:973, in Trainer._run(self, model, ckpt_path)
970 log.debug(f"{self.class.name}: preparing data")
971 self._data_connector.prepare_data()
--> 973 call._call_setup_hook(self) # allow user to set up LightningModule in accelerator environment
974 log.debug(f"{self.class.name}: configuring model")
975 call._call_configure_model(self)
File ~/projects/WINCLIP_try2/.venv/lib/python3.12/site-packages/lightning/pytorch/trainer/call.py:110, in _call_setup_hook(trainer)
108 _call_lightning_datamodule_hook(trainer, "setup", stage=fn)
109 _call_callback_hooks(trainer, "setup", stage=fn)
--> 110 _call_lightning_module_hook(trainer, "setup", stage=fn)
112 trainer.strategy.barrier("post_setup")
File ~/projects/WINCLIP_try2/.venv/lib/python3.12/site-packages/lightning/pytorch/trainer/call.py:177, in _call_lightning_module_hook(trainer, hook_name, pl_module, *args, **kwargs)
174 pl_module._current_fx_name = hook_name
176 with trainer.profiler.profile(f"[LightningModule]{pl_module.class.name}.{hook_name}"):
--> 177 output = fn(*args, **kwargs)
179 # restore current_fx when nested context
180 pl_module._current_fx_name = prev_fx_name
File ~/projects/WINCLIP_try2/.venv/lib/python3.12/site-packages/anomalib/models/image/winclip/lightning_model.py:150, in WinClip.setup(failed resolving arguments)
146 if self.few_shot_source:
147 logger.info("Loading reference images from %s", self.few_shot_source)
148 reference_dataset = PredictDataset(
149 self.few_shot_source,
--> 150 transform=self.pre_processor.test_transform if self.pre_processor else None,
151 )
152 dataloader = DataLoader(reference_dataset, batch_size=1, shuffle=False, pin_memory=True)
153 else:
File ~/projects/WINCLIP_try2/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py:1964, in Module.getattr(self, name)
1962 if name in modules:
1963 return modules[name]
-> 1964 raise AttributeError(
1965 f"'{type(self).name}' object has no attribute '{name}'"
1966 )
AttributeError: 'PreProcessor' object has no attribute 'test_transform'
Beta Was this translation helpful? Give feedback.
All reactions