simet.feature_extractor.inception¶
simet.feature_extractor.inception ¶
InceptionFeatureExtractor ¶
InceptionFeatureExtractor(
cache_dir=Path("cache/features"), force_cache_recompute=False
)
Bases: FeatureExtractor
Inception-v3 feature extractor with cached, batchwise inference.
Loads a torchvision Inception v3 backbone pretrained on ImageNet
(Inception_V3_Weights.IMAGENET1K_V1), replaces the final fully-connected
layer with torch.nn.Identity(), and returns the penultimate features
(dimension 2048) for each input image. Supports CUDA with autocast
(mixed precision) when available.
Inputs are expected to be already transformed according to the
Inception-v3 weights transforms (resize/crop to 299×299 and ImageNet
normalization). In this project, use :class:simet.transforms.InceptionTransform
to ensure compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_dir
|
Path | str
|
See :class: |
Path('cache/features')
|
force_cache_recompute
|
bool
|
See :class: |
False
|
Attributes:
| Name | Type | Description |
|---|---|---|
device |
device
|
Device used for inference ( |
inception |
Module
|
The initialized Inception-v3 model in eval mode, with |
Notes
- Output feature matrix shape is
(N, 2048)for a loader that yieldsNimages. - Mixed precision is used automatically on CUDA if AMP is available.
- Progress is displayed via
tqdmduring feature extraction. - Caching behavior (keying and storage) is handled by :class:
FeatureCacheService.
Example
extractor = InceptionFeatureExtractor() feats = extractor.extract_features(loader) # may hit cache feats.shape # doctest: +SKIP (N, 2048)
Source code in simet/feature_extractor/feature_extractor.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
cache_key_suffix
property
¶
cache_key_suffix
Suffix used to disambiguate cache entries for this extractor.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The cache key suffix ( |