reset_index#
- Dataset.reset_index(start_image_id: int = 0, start_annotations_id: int = 0, sort_images_by: None | str | Sequence[str] = 'relative_path', sort_annotations_by: None | str | Sequence[str] = ('image_id', 'category_id', 'box_x_min', 'box_y_min', 'box_width', 'box_height')) Self[source]#
Reset index of
self.imagesdataframe, and reset index of self.annotations However, keep the ‘image_id’ column inself.annotationspointing to the right rows in theself.imagesdataframe.Note
Both images and annotations dataframes will be reorder according to specific columns. You can change them with the
sort_images_byandsort_annotations_byparameters, but the default behaviour is:images dataframe will be reordered according to
relative_pathannotations dataframe will be reordered according to
image_id,category_idand the bounding box coordinates, i.e.box_x_min,box_y_min,box_widthandbox_height
- Parameters:
start_image_id – Number at which the image index starts. This is used to construct two datasets without overlapping ids.
start_annotations_id – Similar to start_image_id, number at which the annotations index starts.
sort_images_by – columns to sort the images dataframe by. It is advised to chose a collection of columns that makes the sorting unique. If set to None or an empty sequence, will no sort the images dataframe before applying a range index to it. Defaults to
relative_pathsort_annotations_by – columns to sort the annotations dataframe by. It is advised to chose a collection of columns that makes the sorting unique. If set to None or an empty sequence, will not sort the annotations dataframe before applying a range index to it. Defaults to
("image_id", "category_id", "box_x_min", "box_y_min", "box_width", box_height").
- Returns:
Dataset with
self.imagesandself.annotationswith updated indexes
Example
>>> from lours.utils.doc_utils import dummy_dataset >>> example = dummy_dataset(10, 10, seed=2) >>> example.iloc[1::2] Dataset object containing 5 images and 4 objects Name : argue_be_structure Images root : what/way Images : width height relative_path type split id 1 472 892 also/policy.gif .gif train 3 506 602 increase/pull.jpg .jpg val 5 401 281 would/off.jpeg .jpeg train 7 831 375 ahead/truth.bmp .bmp train 9 993 334 husband/whatever.jpeg .jpeg eval Annotations : image_id category_str category_id ... box_y_min box_width box_height id ... 0 1 relationship 3 ... 606.391824 29.194750 194.387036 1 7 relationship 3 ... 313.193702 230.609055 5.269920 5 9 simply 25 ... 198.210135 474.192703 57.594892 9 9 table 7 ... 60.522880 425.022919 144.458578 [4 rows x 8 columns] Label map : {3: 'relationship', 7: 'table', 25: 'simply'} >>> example.iloc[1::2].reset_index(10, 5) Dataset object containing 5 images and 4 objects Name : argue_be_structure Images root : what/way Images : width height relative_path type split id 10 831 375 ahead/truth.bmp .bmp train 11 472 892 also/policy.gif .gif train 12 993 334 husband/whatever.jpeg .jpeg eval 13 506 602 increase/pull.jpg .jpg val 14 401 281 would/off.jpeg .jpeg train Annotations : image_id category_str category_id ... box_y_min box_width box_height id ... 5 10 relationship 3 ... 313.193702 230.609055 5.269920 6 11 relationship 3 ... 606.391824 29.194750 194.387036 7 12 table 7 ... 60.522880 425.022919 144.458578 8 12 simply 25 ... 198.210135 474.192703 57.594892 [4 rows x 8 columns] Label map : {3: 'relationship', 7: 'table', 25: 'simply'}