Mercurial > repos > goeckslab > image_learner
comparison metaformer_setup.py @ 12:bcfa2e234a80 draft
planemo upload for repository https://github.com/goeckslab/gleam.git commit 96bab8325992d16fcaad8e0a4dc4c62b00e2abc2
| author | goeckslab |
|---|---|
| date | Fri, 21 Nov 2025 15:58:13 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 11:c5150cceab47 | 12:bcfa2e234a80 |
|---|---|
| 1 import logging | |
| 2 from typing import Any, Dict | |
| 3 | |
| 4 logger = logging.getLogger("ImageLearner") | |
| 5 | |
| 6 # Optional MetaFormer configuration registry | |
| 7 META_DEFAULT_CFGS: Dict[str, Any] = {} | |
| 8 try: | |
| 9 from MetaFormer import default_cfgs as META_DEFAULT_CFGS # type: ignore[attr-defined] | |
| 10 except Exception as exc: # pragma: no cover - optional dependency | |
| 11 logger.debug("MetaFormer default configs unavailable: %s", exc) | |
| 12 META_DEFAULT_CFGS = {} | |
| 13 | |
| 14 # Try to import Ludwig visualization registry (may fail due to optional dependencies) | |
| 15 _ludwig_viz_available = False | |
| 16 try: | |
| 17 from ludwig.visualize import get_visualizations_registry as _raw_get_visualizations_registry | |
| 18 _ludwig_viz_available = True | |
| 19 logger.info("Ludwig visualizations available") | |
| 20 except ImportError as exc: # pragma: no cover - optional dependency | |
| 21 logger.warning( | |
| 22 "Ludwig visualizations not available: %s. Will use fallback plots only.", | |
| 23 exc, | |
| 24 ) | |
| 25 _raw_get_visualizations_registry = None | |
| 26 except Exception as exc: # pragma: no cover - defensive | |
| 27 logger.warning( | |
| 28 "Ludwig visualizations not available due to dependency issues: %s. Will use fallback plots only.", | |
| 29 exc, | |
| 30 ) | |
| 31 _raw_get_visualizations_registry = None | |
| 32 | |
| 33 | |
| 34 def get_visualizations_registry(): | |
| 35 """Return the Ludwig visualizations registry or an empty dict if unavailable.""" | |
| 36 if not _raw_get_visualizations_registry: | |
| 37 return {} | |
| 38 try: | |
| 39 return _raw_get_visualizations_registry() | |
| 40 except Exception as exc: # pragma: no cover - defensive | |
| 41 logger.warning("Failed to load Ludwig visualizations registry: %s", exc) | |
| 42 return {} | |
| 43 | |
| 44 | |
| 45 # --- MetaFormer patching integration --- | |
| 46 _metaformer_patch_ok = False | |
| 47 try: | |
| 48 from MetaFormer.metaformer_stacked_cnn import patch_ludwig_stacked_cnn as _mf_patch | |
| 49 | |
| 50 if _mf_patch(): | |
| 51 _metaformer_patch_ok = True | |
| 52 logger.info("MetaFormer patching applied for Ludwig stacked_cnn encoder.") | |
| 53 except Exception as exc: # pragma: no cover - optional dependency | |
| 54 logger.warning("MetaFormer stacked CNN not available: %s", exc) | |
| 55 _metaformer_patch_ok = False | |
| 56 | |
| 57 # Note: CAFormer models are now handled through MetaFormer framework |
