Using Faster RCNN on other things than VOC/COCO


#1

Hi,
I’m trying to adapt this gluoncv code Train Faster-RCNN end-to-end on Pascal VOC to do object detection on the pikachu .rec datasets from https://gluon-cv.mxnet.io/build/examples_detection/finetune_detection.html

For some reason it’s far from trivial to adapt the Faster RCNN code to work on other things that VOC. Typically, when I’m using the pikachu .rec dataset, I’m having some error related to data shape (below). Can someone help making this gluoncv code more portable? For example, it would be great to hyper-parametrize the dataset so that it can do other things than VOC or COCO. In the meantime I’d be happy to receive help making faster rcnn work for pikachu
many thanks

Traceback (most recent call last):
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/dataloader.py", line 169, in worker_loop
    batch = batchify_fn([dataset[i] for i in samples])
Traceback (most recent call last):
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/dataloader.py", line 169, in <listcomp>
    batch = batchify_fn([dataset[i] for i in samples])
Traceback (most recent call last):
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/dataloader.py", line 169, in worker_loop
    batch = batchify_fn([dataset[i] for i in samples])
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/dataloader.py", line 169, in <listcomp>
    batch = batchify_fn([dataset[i] for i in samples])
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/dataset.py", line 131, in __getitem__
    item = self._data[idx]
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/dataset.py", line 131, in __getitem__
    item = self._data[idx]
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/gluoncv/data/recordio/detection.py", line 70, in __getitem__
    img, label = super(RecordFileDetection, self).__getitem__(idx)
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/gluoncv/data/recordio/detection.py", line 70, in __getitem__
    img, label = super(RecordFileDetection, self).__getitem__(idx)
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/dataloader.py", line 169, in worker_loop
    batch = batchify_fn([dataset[i] for i in samples])
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/vision/datasets.py", line 257, in __getitem__
    record = super(ImageRecordDataset, self).__getitem__(idx)
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/vision/datasets.py", line 257, in __getitem__
    record = super(ImageRecordDataset, self).__getitem__(idx)
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/dataloader.py", line 169, in <listcomp>
    batch = batchify_fn([dataset[i] for i in samples])
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/dataset.py", line 189, in __getitem__
    return self._record.read_idx(self._record.keys[idx])
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/recordio.py", line 265, in read_idx
    return self.read()
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/dataset.py", line 131, in __getitem__
    item = self._data[idx]
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/recordio.py", line 163, in read
    ctypes.byref(size)))
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/dataset.py", line 189, in __getitem__
    return self._record.read_idx(self._record.keys[idx])
mxnet.base.MXNetError: [21:06:47] src/recordio.cc:65: Check failed: header[0] == RecordIOWriter::kMagic Invalid RecordIO File

Stack trace returned 10 entries:
[bt] (0) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x36161a) [0x7fcaa66ee61a]
[bt] (1) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x3162eb3) [0x7fcaa94efeb3]
[bt] (2) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/libmxnet.so(MXRecordIOReaderReadRecord+0x2a) [0x7fcaa8d66eaa]
[bt] (3) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/lib-dynload/../../libffi.so.6(ffi_call_unix64+0x4c) [0x7fcaf5ed6ec0]
[bt] (4) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/lib-dynload/../../libffi.so.6(ffi_call+0x22d) [0x7fcaf5ed687d]
[bt] (5) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(_ctypes_callproc+0x2ce) [0x7fcaf60ebe2e]
[bt] (6) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(+0x12865) [0x7fcaf60ec865]
[bt] (7) /home/ec2-user/anaconda3/envs/mxnet_p36/bin/python(_PyObject_FastCallDict+0x8b) [0x564b7f865d7b]
[bt] (8) /home/ec2-user/anaconda3/envs/mxnet_p36/bin/python(+0x19e7ce) [0x564b7f8f57ce]
[bt] (9) /home/ec2-user/anaconda3/envs/mxnet_p36/bin/python(_PyEval_EvalFrameDefault+0x2fa) [0x564b7f917cba]


  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/base.py", line 252, in check_call
    raise MXNetError(py_str(_LIB.MXGetLastError()))
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/gluoncv/data/recordio/detection.py", line 70, in __getitem__
    img, label = super(RecordFileDetection, self).__getitem__(idx)
Process Process-13:
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/vision/datasets.py", line 257, in __getitem__
    record = super(ImageRecordDataset, self).__getitem__(idx)

  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/recordio.py", line 265, in read_idx
    return self.read()
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/recordio.py", line 163, in read
    ctypes.byref(size)))
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/base.py", line 252, in check_call
    raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: [21:06:47] src/recordio.cc:65: Check failed: header[0] == RecordIOWriter::kMagic Invalid RecordIO File

Stack trace returned 10 entries:
[bt] (0) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x36161a) [0x7fcaa66ee61a]
[bt] (1) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x3162eb3) [0x7fcaa94efeb3]
[bt] (2) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/libmxnet.so(MXRecordIOReaderReadRecord+0x2a) [0x7fcaa8d66eaa]
[bt] (3) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/lib-dynload/../../libffi.so.6(ffi_call_unix64+0x4c) [0x7fcaf5ed6ec0]
[bt] (4) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/lib-dynload/../../libffi.so.6(ffi_call+0x22d) [0x7fcaf5ed687d]
[bt] (5) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(_ctypes_callproc+0x2ce) [0x7fcaf60ebe2e]
[bt] (6) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(+0x12865) [0x7fcaf60ec865]
[bt] (7) /home/ec2-user/anaconda3/envs/mxnet_p36/bin/python(_PyObject_FastCallDict+0x8b) [0x564b7f865d7b]
[bt] (8) /home/ec2-user/anaconda3/envs/mxnet_p36/bin/python(+0x19e7ce) [0x564b7f8f57ce]
[bt] (9) /home/ec2-user/anaconda3/envs/mxnet_p36/bin/python(_PyEval_EvalFrameDefault+0x2fa) [0x564b7f917cba]


Traceback (most recent call last):
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
    self.run()
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/dataset.py", line 189, in __getitem__
    return self._record.read_idx(self._record.keys[idx])
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/multiprocessing/process.py", line 93, in run
    self._target(*self._args, **self._kwargs)
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/gluon/data/dataloader.py", line 169, in worker_loop
    batch = batchify_fn([dataset[i] for i in samples])
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/recordio.py", line 265, in read_idx
    return self.read()
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/recordio.py", line 163, in read
    ctypes.byref(size)))
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/gluoncv/data/batchify.py", line 347, in __call__
    ' {} elements, given {}.'.format(len(self._fn), len(data[0]))
  File "/home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/base.py", line 252, in check_call
    raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: [21:06:47] src/recordio.cc:65: Check failed: header[0] == RecordIOWriter::kMagic Invalid RecordIO File

Stack trace returned 10 entries:
[bt] (0) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x36161a) [0x7fcaa66ee61a]
[bt] (1) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/libmxnet.so(+0x3162eb3) [0x7fcaa94efeb3]
[bt] (2) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/site-packages/mxnet/libmxnet.so(MXRecordIOReaderReadRecord+0x2a) [0x7fcaa8d66eaa]
[bt] (3) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/lib-dynload/../../libffi.so.6(ffi_call_unix64+0x4c) [0x7fcaf5ed6ec0]
[bt] (4) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/lib-dynload/../../libffi.so.6(ffi_call+0x22d) [0x7fcaf5ed687d]
[bt] (5) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(_ctypes_callproc+0x2ce) [0x7fcaf60ebe2e]
[bt] (6) /home/ec2-user/anaconda3/envs/mxnet_p36/lib/python3.6/lib-dynload/_ctypes.cpython-36m-x86_64-linux-gnu.so(+0x12865) [0x7fcaf60ec865]
[bt] (7) /home/ec2-user/anaconda3/envs/mxnet_p36/bin/python(_PyObject_FastCallDict+0x8b) [0x564b7f865d7b]
[bt] (8) /home/ec2-user/anaconda3/envs/mxnet_p36/bin/python(+0x19e7ce) [0x564b7f8f57ce]
[bt] (9) /home/ec2-user/anaconda3/envs/mxnet_p36/bin/python(_PyEval_EvalFrameDefault+0x2fa) [0x564b7f917cba]


AssertionError: The number of attributes in each data sample should contains 2 elements, given 5.

#2

there seems to be an issue with the enumerate(train_data) in the train function. enum = list(enumerate(train_data)) returns an error AssertionError: The number of attributes in each data sample should contains 2 elements, given 5.


#3

I’m not really sure why you’re getting that error. From your logs, it seems like your .rec file is corrupted (“src/recordio.cc:65: Check failed: header[0] == RecordIOWriter::kMagic Invalid RecordIO File”). Did you by any chance interrupt the download of the .rec files?

For working with pikachu dataset, I made changes and created this PR on my repo. It does appear to converge with loss going down and accuracy going up. Didn’t spend anymore time making sure results are sane. Let me know if there are any issues with it. The command line arguments are:
--dataset custom --class-names pikachu --num-workers 0


#4

massive thanks! I’ll try that