📊 features module¶
Factory for image feature extraction.
- class pupyl.embeddings.features.Characteristics(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)¶
Describes high level characteristics of complex feature extractors.
Notes
The currently supported characteristics are:
MINIMUMWEIGHT_FAST_SMALL_PRECISION # MobileNetLIGHTWEIGHT_FAST_SMALL_PRECISION # ResNet50V2LIGHTWEIGHT_FAST_SHORT_PRECISION # ResNet101V2LIGHTWEIGHT_QUICK_SHORT_PRECISION # DenseNet169MEDIUMWEIGHT_QUICK_GOOD_PRECISION # DenseNet201MIDDLEWEIGHT_QUICK_GOOD_PRECISION # InceptionV3MIDDLEWEIGHT_SLOW_GOOD_PRECISION # XceptionHEAVYWEIGHT_SLOW_GOOD_PRECISION # EfficientNetV2MHEAVYWEIGHT_SLOW_HUGE_PRECISION # EfficientNetV2L- static by_name(name)¶
Returns a characteristic by its name.
- Parameters:
name (
str) – String representation of enumerator- Raises:
UnknownCharacteristicsName: – If
nameis unknown.- Returns:
The corresponding characteristic.
- Return type:
enum
- static by_value(value)¶
Returns a characteristic by its value.
- Parameters:
value (
int) – Integer representing a characteristic- Raises:
UnknownCharacteristicsValue: – If
valueis unknown.- Returns:
The corresponding characteristic.
- Return type:
enum
- class pupyl.embeddings.features.Extractors(characteristics, extreme_mode=True)¶
Pretrained CNNs for embedding generation.
- __enter__()¶
Opens Extractors context.
- __exit__(exc_type, exc_val, exc_tb)¶
Close Extractors context.
- __init__(characteristics, extreme_mode=True)¶
Creates embedding extractors.
- Parameters:
characteristics (
Enum) – Describing the intended characteristics to transform images into its underlying embeddings.extreme_mode (
bool) – Should the extreme mode (faster execution but not gentle with memory) be enabled or disabled?
- _infer_network()¶
Translates a characteristic to a network architecture.
- Raises:
UnknownCharacteristics: – If the characteristics passed through are unknown.
- Returns:
With preprocessors and complete CNN architecture.
- Return type:
tuple
- acceleration_discovery()¶
Performs a hardware processing acceleration discovery.
Most NVIDIA® GPUs supported (through
CUDA), which results on faster embeddings extraction.
- extract(uri)¶
Converts image uri to its embeddings.
- Parameters:
uri (
str) – Location of the image to be converted to a embedding.- Returns:
1D tensor with extracted features.
- Return type:
numpy.ndarray
- extract_save(path, uri)¶
Extracts features from an image, saving to disk after all.
- Parameters:
path (
str) – Where to store the tensor.uri (
str) – Location of the image to be converted to a embedding.
- static load(path)¶
Loads up a
tensorreferencingindex.- Parameters:
path (
str) – Where to load from the tensor.- Returns:
Tensor loaded back again.
- Return type:
numpy.ndarray
- property output_shape¶
Getter for property output_shape.
Describes the output shape of extracted features.
- Returns:
The output shape for the picked characteristics.
- Return type:
int
- preprocessor(uri)¶
Image preprocessing methods, suitable for posterior network ingestion. It may include image resizing, normalization, among others.
- Parameters:
uri (
str) – Location of the image to be preprocessed.- Returns:
Containing the processed image
- Return type:
numpy.ndarray
- static save(path, tensor)¶
Writes down a
tensorreferencingindex.- Parameters:
path (
str) – Where to store the tensor.tensor (
Tensor) – The tensor itself, to be saved.