get_one_frame#

Dataset.get_one_frame(n: int) tuple[Series, DataFrame][source]#

Sample a single image from the dataset. Image data is returned as a pandas Series, and corresponding annotations is returned as a DataFrame.

This equivalent to dataset.iloc[n] except the returned object is the bare image info and annotation dataframe. This can be useful when using lours as e.g. a pytorch dataset.

Note

The id of the image is the name of the image Series

Parameters:

n – row number of wanted image. Note that this does NOT use the index of self.images.

Returns:

tuple containing image data as Series and annotations as a (possibly empty) DataFrame.

Example

>>> from lours.utils.doc_utils import dummy_dataset
>>> example = dummy_dataset(2, 2, seed=1)
>>> example
Dataset object containing 2 images and 2 objects
Name :
    shake_effort_many
Images root :
    care/suggest
Images :
    width  height        relative_path  type  split
id
0     955     229  determine/story.jpg  .jpg  train
1     131     840       air/method.bmp  .bmp  train
Annotations :
    image_id category_str  category_id  ...   box_y_min   box_width  box_height
id                                      ...
0          1       listen           14  ...  276.974642    9.718823  184.684056
1          0        reach           22  ...    6.311037  123.141689  174.239136

[2 rows x 8 columns]
Label map :
{14: 'listen', 15: 'marriage', 22: 'reach'}
>>> frame, annotations = example.get_one_frame(0)
>>> frame
width                            955
height                           229
relative_path    determine/story.jpg
type                            .jpg
split                          train
Name: 0, dtype: object
>>> annotations
    image_id category_str  category_id  ... box_y_min   box_width  box_height
id                                      ...
1          0        reach           22  ...  6.311037  123.141689  174.239136

[1 rows x 8 columns]