Attaching unique ID to recurring class labels for yolov8 detections

79 Views Asked by At

I have the following dataset with recurring classes that I would like to attach individual IDs to. The challenge is that these classes are dynamic, ranging from 0 to x (depending on how many objects of the same class I detect).

If I detect 5 people at a certain time, I will get/attach the classes [0, 1, 2, 3, 4] If I get 2 people at a later point of time, I will get/attach the classes [0, 1]

Whenever I get a new class, I would like to attach an individual ID to the individual classes, so that the first 4 classes keep their initial class label [0, 1, 2, 3], while the later classes follow with [4, 5], instead of [0, 1].

See the uniqueID for the desired output.

The data looks like this:

  class  datetime              uniqueID
   0      2023-11-24T15:45      1
   1      2023-11-24T15:45      2
   2      2023-11-24T15:45      3
   3      2023-11-24T15:45      4
   4      2023-11-24T15:45      5
   0      2023-11-24T15:46      1
   1      2023-11-24T15:46      2
   2      2023-11-24T15:46      3
   3      2023-11-24T15:46      4
   4      2023-11-24T15:46      5
   nan    2023-11-24T15:47      nan
   0      2023-11-24T15:48      6
   1      2023-11-24T15:48      7
   0      2023-11-24T15:49      6
   1      2023-11-24T15:49      7
   0      2023-11-24T15:50      6 
   1      2023-11-24T15:50      7
   2      2023-11-24T15:50      8
   3      2023-11-24T15:50      9
   4      2023-11-24T15:50      10
   0      2023-11-24T15:51      6
   1      2023-11-24T15:51      7
   nan    2023-11-24T15:52      nan
   0      2023-11-24T15:53      11
   1      2023-11-24T15:53      12
   2      2023-11-24T15:53      13
   3      2023-11-24T15:53      14
   4      2023-11-24T15:53      15
   0      2023-11-24T15:54      11
   1      2023-11-24T15:54      12
   2      2023-11-24T15:54      13
   3      2023-11-24T15:54      14
   0      2023-11-24T15:55      11
   1      2023-11-24T15:56      12
   2      2023-11-24T15:57      13
   3      2023-11-24T15:58      14
   nan    2023-11-24T15:59      nan
   nan    2023-11-24T16:00      nan
   0      2023-11-24T16:01      15
   0      2023-11-24T16:02      15

Whenever there is a nan, the classes are new and should be attached with a new unique ID. I tried to append the classes to a list, and work with the datetime to determine whether the unique classes are "new" or existing.

Any help how to achieve this?

0

There are 0 best solutions below