remap_from_dataframe#

Dataset.remap_from_dataframe(df: DataFrame, remove_not_mapped: bool = True, remove_emptied_images: bool = False) Self[source]#

Same as class remap, but instead of taking a dictionary, you give a dataframe.

Dataframe must have at least these two columns:

  • input_category_id

  • output_category_id

Optional columns for category names:

  • input_category_name

  • output_category_name

Parameters:
  • df – dataframe with aforementioned columns

  • remove_not_mapped – If set to True, will remove classes that are not in class mapping. Otherwise, keep them as is (with potential class fusion). Defaults to True.

  • remove_emptied_images – If set to True, will remove from self.images the images that are now empty of annotation. Note that it will keep the images that were empty before the remapping. Defaults to False.

Returns:

new dataset object with remapped classes according to the given table in the 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'}
>>> remap_df = pd.DataFrame(
...     data={
...         "input_category_id": [14, 22],
...         "output_category_id": [0, 1],
...         "output_category_name": ["new_listen", "new_reach"],
...     }
... )
>>> remap_df
   input_category_id  output_category_id output_category_name
0                 14                   0           new_listen
1                 22                   1            new_reach
>>> example.remap_from_dataframe(remap_df)
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   new_listen            0  ...  276.974642    9.718823  184.684056
1          0    new_reach            1  ...    6.311037  123.141689  174.239136

[2 rows x 8 columns]
Label map :
{0: 'new_listen', 1: 'new_reach'}