flair.data.Image#
- class flair.data.Image(data=None, imageURL=None)View on GitHub#
Bases:
DataPoint
Represents an image as a data point, holding image data or a URL.
- __init__(data=None, imageURL=None)View on GitHub#
Initializes an Image data point.
- Parameters:
data (Any, optional) – Raw image data (e.g., torch.Tensor, PIL Image). Defaults to None.
imageURL (Optional[str], optional) – URL of the image. Defaults to None.
Methods
__init__
([data, imageURL])Initializes an Image data point.
add_label
(typename, value[, score])Adds a new label to a specific annotation layer.
add_metadata
(key, value)Adds a key-value pair to the data point's metadata.
clear_embeddings
([embedding_names])Removes stored embeddings to free memory.
get_each_embedding
([embedding_names])Retrieves a list of individual embedding tensors.
get_embedding
([names])Retrieves embeddings, concatenating if multiple names are given or if names is None.
get_label
([label_type, zero_tag_value])Retrieves the primary label for a given type, or a default 'O' label.
get_labels
([typename])Retrieves all labels for a specific annotation layer.
get_metadata
(key)Retrieves metadata associated with the given key.
has_label
(typename)Checks if the data point has at least one label for the given annotation type.
has_metadata
(key)Checks if the data point has metadata for the given key.
remove_labels
(typename)Removes all labels associated with a specific annotation layer.
set_embedding
(name, vector)Stores an embedding tensor under a given name.
set_label
(typename, value[, score])Sets the label(s) for an annotation layer, overwriting any existing ones.
to
(device[, pin_memory])Moves all stored embedding tensors to the specified device.
Attributes
Returns the concatenated embeddings stored for this image.
The ending character offset (exclusive) within the original text.
labels
Returns a list of all labels from all annotation layers.
score
Shortcut property for the score of the first label added.
The starting character offset within the original text.
tag
Shortcut property for the value of the first label added.
The textual representation of this data point.
A string identifier for the data point itself, without label info.
- property embedding: Tensor#
Returns the concatenated embeddings stored for this image.
- property start_position: int#
The starting character offset within the original text.
- property end_position: int#
The ending character offset (exclusive) within the original text.
- property text: str#
The textual representation of this data point.
- property unlabeled_identifier: str#
A string identifier for the data point itself, without label info.