Skip to content

‍‍‍‍CocoDetection accepts slice as argument to its __getitem__ and returns wrong result #7824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sadra-barikbin opened this issue Aug 11, 2023 · 0 comments · Fixed by #8227

Comments

@sadra-barikbin
Copy link

sadra-barikbin commented Aug 11, 2023

Hi, although CocoDetection declares its __getitem__ argument to be of type int, it actually accepts slice as well. However it returns a wrong result. As this might be confusing for some users, I suggest to add a type check at the beginning of the __getitem__.

def __getitem__(self, index: int) -> Tuple[Any, Any]:
id = self.ids[index]
image = self._load_image(id)
target = self._load_target(id)

ds[:2]
(tensor([[[0.3373, 0.3373, 0.3373,  ..., 0.2863, 0.2863, 0.2863],
          [0.3373, 0.3373, 0.3373,  ..., 0.2863, 0.2863, 0.2863],
          [0.3373, 0.3373, 0.3373,  ..., 0.2863, 0.2863, 0.2863],
          ...,
          [0.4196, 0.4196, 0.4196,  ..., 0.4137, 0.3980, 0.3235],
          [0.4196, 0.4196, 0.4196,  ..., 0.4137, 0.3980, 0.3235],
          [0.4196, 0.4196, 0.4196,  ..., 0.4137, 0.3980, 0.3235]],
 
         [[0.1608, 0.1608, 0.1608,  ..., 0.1216, 0.1216, 0.1216],
          [0.1608, 0.1608, 0.1608,  ..., 0.1216, 0.1216, 0.1216],
          [0.1608, 0.1608, 0.1608,  ..., 0.1216, 0.1216, 0.1216],
          ...,
          [0.5686, 0.5686, 0.5686,  ..., 0.5333, 0.5137, 0.4353],
          [0.5686, 0.5686, 0.5686,  ..., 0.5333, 0.5137, 0.4353],
          [0.5686, 0.5686, 0.5686,  ..., 0.5333, 0.5137, 0.4353]],
 
         [[0.1412, 0.1412, 0.1412,  ..., 0.1608, 0.1608, 0.1608],
          [0.1412, 0.1412, 0.1412,  ..., 0.1608, 0.1608, 0.1608],
          [0.1412, 0.1412, 0.1412,  ..., 0.1608, 0.1608, 0.1608],
          ...,
          [0.0902, 0.0902, 0.0902,  ..., 0.1333, 0.1451, 0.1020],
          [0.0902, 0.0902, 0.0902,  ..., 0.1333, 0.1451, 0.1020],
          [0.0902, 0.0902, 0.0902,  ..., 0.1333, 0.1451, 0.1020]]]),
 {'category_id': tensor([2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3,
          1]),
  'bbox': tensor([[ 390,  240,   58,   92],
          [ 391,  319,   66,   99],
          [ 663,  331,   54,  106],
          [ 796,  324,   50,  102],
          [1245,  276,   35,  117],
          [ 599,  265,   58,   91],
          [ 755,  228,   42,   91],
          [ 788,  261,   61,   97],
          [ 250,  374,   73,  105],
          [ 224,  449,   29,   28],
          [  12,   85,   13,   32],
          [  88,   70,   13,   27],
          [ 102,   99,   14,   33],
          [ 100,  132,   14,   32],
          [ 151,  160,   13,   34],
          [ 177,  115,   18,   32],
          [ 214,   73,   12,   28],
          [ 267,   58,   13,   23],
          [ 358,   71,   14,   33],
          [ 356,  160,   17,   36],
          [ 231,  132,   14,   33],
          [ 234,   88,   16,   29],
          [ 248,   90,   13,   25],
          [  60,  109,   13,   32],
          [ 243,   75,    7,    5]]),
  'iscrowd': tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
          0])})

The image in the returned tuple is that of the ds[0] and the target is the combined annotations of ds[0] and ds[1] which is wrong. This is due to the fact that ds.coco could work with a list of inputs in its getAnnIds().

cc @pmeier

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants