class TorchEmbeddingsMixin(fom.EmbeddingsMixin): (source)
Known subclasses: fiftyone.utils.torch.TorchImageModel
Constructor: TorchEmbeddingsMixin(model, layer_name, as_feature_extractor)
Mixin for Torch models that can generate embeddings.
Parameters | |
model | the Torch model, a torch:torch.nn.Module |
layer | the name of the embeddings layer whose output to save, or None if this model instance should not expose embeddings. Prepend "<" to save the input tensor instead |
as | whether to operate the model as a feature extractor. If layer_name is provided, this layer is passed to torchvision's create_feature_extractor() function. If no layer_name is provided, the model's output is used as-is for feature extraction |
Method | __init__ |
Undocumented |
Method | embed |
Generates an embedding for the given data. |
Method | embed |
Generates embeddings for the given iterable of data. |
Method | get |
Returns the embeddings generated by the last forward pass of the model. |
Property | has |
Whether this instance has embeddings. |
Method | _predict |
Applies a forward pass to the given iterable of data and returns the raw model output with no processing applied. |
Instance Variable | _as |
Undocumented |
Instance Variable | _embeddings |
Undocumented |
Instance Variable | _model |
Undocumented |
Generates an embedding for the given data.
Subclasses can override this method to increase efficiency, but, by
default, this method simply calls predict
and then returns
get_embeddings
.
Parameters | |
arg | the data. See predict for details |
Returns | |
a numpy array containing the embedding |
Generates embeddings for the given iterable of data.
Subclasses can override this method to increase efficiency, but, by
default, this method simply iterates over the data and applies
embed
to each.
Parameters | |
args | an iterable of data. See predict_all for details |
Returns | |
a numpy array containing the embeddings stacked along axis 0 |
Returns the embeddings generated by the last forward pass of the model.
By convention, this method should always return an array whose first
axis represents batch size (which will always be 1 when predict
was last used).
Returns | |
a numpy array containing the embedding(s) |
fiftyone.utils.torch.TorchImageModel
Applies a forward pass to the given iterable of data and returns the raw model output with no processing applied.
Parameters | |
args | an iterable of data. See predict_all for details |
Returns | |
the raw output of the model |