Utility function to infer feature type from an unknow json response.
Functions:
feature_type_from_model(feature_type_input: BBoxFeatureType | CategoricalFeatureType | HistogramFeatureType | ImageFeatureType | ListFeatureTypeInput | NumericalFeatureType | OrdinalFeatureType | TimeseriesFeatureTypeInput | VectorFeatureTypeInput | VideoFeatureType) -> FeatureTypeUnion
Convert json features into the corresponding Feature.
Source code in src/xpdeep/dataset/feature/feature_types/feature_from_model.py
| def feature_type_from_model( # noqa: PLR0911
feature_type_input: BBoxFeatureType
| CategoricalFeatureType
| HistogramFeatureType
| ImageFeatureType
| ListFeatureTypeInput
| NumericalFeatureType
| OrdinalFeatureType
| TimeseriesFeatureTypeInput
| VectorFeatureTypeInput
| VideoFeatureType,
) -> "FeatureTypeUnion":
"""Convert json features into the corresponding Feature."""
from xpdeep.dataset.feature.feature_types import ( # noqa:PLC0415
BboxFeature,
CategoricalFeature,
HistogramFeature,
ImageFeature,
ListFeature,
NumericalFeature,
OrdinalFeature,
TimeSeriesFeature,
VectorFeature,
)
match feature_type_input:
case NumericalFeatureType():
return NumericalFeature.from_model(feature_type_input)
case CategoricalFeatureType():
return CategoricalFeature.from_model(feature_type_input)
case VectorFeatureTypeInput():
return VectorFeature.from_model(feature_type_input)
case TimeseriesFeatureTypeInput():
return TimeSeriesFeature.from_model(feature_type_input)
case ImageFeatureType():
return ImageFeature.from_model(feature_type_input)
case ListFeatureTypeInput():
return ListFeature.from_model(feature_type_input)
case OrdinalFeatureType():
return OrdinalFeature.from_model(feature_type_input)
case HistogramFeatureType():
return HistogramFeature.from_model(feature_type_input)
case BBoxFeatureType():
return BboxFeature.from_model(feature_type_input)
case _:
msg = f"Feature name `{feature_type_input}` not recognized"
raise ApiError(msg)
|