Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

mxnet.gluon.data.vision.ImageRecordDataset key error #8348

@qiliux

Description

@qiliux

Note: Providing complete information in the most concise form is the best way to get help. This issue template serves as the checklist for essential information to most of the technical issues.

If the issue is non-technical, feel free to present the information in what you believe is the best form.

Description

(Brief description of the problem in no more than 2 sentences.)

The gluon interface is so amazing so that i love it. But when i try to train my own dataset, error occurs.
use the mxnet.gluon.data.vision.ImageRecordDataset, return key error

Environment info (Required)

Python3, ubuntu64, gpu version

What to do:
1. Download the diagnosis script from https://raw.githubusercontent.com/apache/incubator-mxnet/master/tools/diagnose.py
2. Run the script using `python diagnose.py` and paste its output here.
----------Python Info----------
Version      : 3.6.2
Compiler     : GCC 7.2.0
Build        : ('default', 'Sep 22 2017 02:03:08')
Arch         : ('64bit', '')
------------Pip Info-----------
Version      : 9.0.1
Directory    : /home/qiliux/anaconda3/envs/mxnet/lib/python3.6/site-packages/pip
----------MXNet Info-----------
Version      : 0.11.1
Directory    : /home/qiliux/anaconda3/envs/mxnet/lib/python3.6/site-packages/mxnet
Commit Hash   : 3e3ac4c9b481b25fffae5d360125a477ba0a9ce2
----------System Info----------
Platform     : Linux-4.10.0-32-generic-x86_64-with-debian-stretch-sid
system       : Linux
node         : cbw-server
release      : 4.10.0-32-generic
version      : #36~16.04.1-Ubuntu SMP Wed Aug 9 09:19:02 UTC 2017
----------Hardware Info----------
machine      : x86_64
processor    : x86_64
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                16
On-line CPU(s) list:   0-15
Thread(s) per core:    1
Core(s) per socket:    8
Socket(s):             2
NUMA node(s):          2
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 79
Model name:            Intel(R) Xeon(R) CPU E5-2620 v4 @ 2.10GHz
Stepping:              1
CPU MHz:               2942.230
CPU max MHz:           3000.0000
CPU min MHz:           1200.0000
BogoMIPS:              4189.96
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              20480K
NUMA node0 CPU(s):     0-7
NUMA node1 CPU(s):     8-15
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss
 ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf pni pclmul
qdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_time
r aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cdp_l3 intel_ppin intel_pt tpr_shadow vnmi flexpriority ept vpid fs
gsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a rdseed adx smap xsaveopt cqm_llc cqm_occup_llc cqm_mbm_total cq
m_mbm_local dtherm ida arat pln pts
----------Network Test----------
Setting timeout: 10
Timing for MXNet: https://github.com/apache/incubator-mxnet, DNS: 0.0017 sec, LOAD: 1.6348 sec.
Timing for Gluon Tutorial(en): http://gluon.mxnet.io, DNS: 0.2842 sec, LOAD: 0.7031 sec.
Timing for Gluon Tutorial(cn): https://zh.gluon.ai, DNS: 0.5301 sec, LOAD: 1.5949 sec.
Timing for FashionMNIST: https://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/fashion-mnist/train-labels-idx1-ub
yte.gz, DNS: 0.5958 sec, LOAD: 2.0139 sec.
Timing for PYPI: https://pypi.python.org/pypi/pip, DNS: 0.0008 sec, LOAD: 1.6546 sec.
Timing for Conda: https://repo.continuum.io/pkgs/free/, DNS: 0.0009 sec, LOAD: 1.1777 sec.

Package used (Python/R/Scala/Julia):
(I'm using ...)
Python
For Scala user, please provide:

  1. Java version: (java -version)
  2. Maven version: (mvn -version)
  3. Scala runtime if applicable: (scala -version)

For R user, please provide R sessionInfo():

Build info (Required if built from source)

Compiler (gcc/clang/mingw/visual studio):

MXNet commit hash:
(Paste the output of git rev-parse HEAD here.)

Build config:
(Paste the content of config.mk, or the build command.)

Error Message:

(Paste the complete error message, including stack trace.)


KeyError                                  Traceback (most recent call last)
<ipython-input-105-b7fbd11d2e10> in <module>()
      4 
      5 for e in range(epochs):
----> 6     for i, (d, l) in enumerate(train_data):
      7         data = d.as_in_context(ctx)
      8         print(data.shape)

~/anaconda3/envs/mxnet/lib/python3.6/site-packages/mxnet/gluon/data/dataloader.py in __iter__(self)
     90     def __iter__(self):
     91         for batch in self._batch_sampler:
---> 92             yield _batchify([self._dataset[idx] for idx in batch])
     93 
     94     def __len__(self):

~/anaconda3/envs/mxnet/lib/python3.6/site-packages/mxnet/gluon/data/dataloader.py in <listcomp>(.0)
     90     def __iter__(self):
     91         for batch in self._batch_sampler:
---> 92             yield _batchify([self._dataset[idx] for idx in batch])
     93 
     94     def __len__(self):

~/anaconda3/envs/mxnet/lib/python3.6/site-packages/mxnet/gluon/data/vision.py in __getitem__(self, idx)
    226 
    227     def __getitem__(self, idx):
--> 228         record = super(ImageRecordDataset, self).__getitem__(idx)
    229         header, img = recordio.unpack(record)
    230         if self._transform is not None:

~/anaconda3/envs/mxnet/lib/python3.6/site-packages/mxnet/gluon/data/dataset.py in __getitem__(self, idx)
     80 
     81     def __getitem__(self, idx):
---> 82         return self._record.read_idx(idx)
     83 
     84     def __len__(self):

~/anaconda3/envs/mxnet/lib/python3.6/site-packages/mxnet/recordio.py in read_idx(self, idx)
    262         record_3
    263         """
--> 264         self.seek(idx)
    265         return self.read()
    266 

~/anaconda3/envs/mxnet/lib/python3.6/site-packages/mxnet/recordio.py in seek(self, idx)
    224         reader pointer position. It doesn't return anything."""
    225         assert not self.writable
--> 226         pos = ctypes.c_size_t(self.idx[idx])
    227         check_call(_LIB.MXRecordIOReaderSeek(self.handle, pos))
    228 

KeyError: 11

Minimum reproducible example

(If you are using your own code, please provide a short script that reproduces the error. Otherwise, please provide link to the existing example.)

def transform(data, label):
    return nd.transpose(data.astype(np.float32), (2,0,1))/255, label
train_data = mx.gluon.data.DataLoader(mx.gluon.data.vision.ImageRecordDataset(
    "./shape_images_train.rec", # the target record file
    flag = 1,
    transform=transform
    ),batch_size=batch_size,shuffle=False)
test_data = mx.gluon.data.DataLoader(mx.gluon.data.vision.ImageRecordDataset(
    "./shape_images_val.rec", # the target record file
    flag = 1,
    transform=transform
    ),batch_size=batch_size,shuffle=False)
net =xx..
for e in range(epochs):
    for i, (d, l) in enumerate(train_data):
        data = d.as_in_context(ctx)
        print(data.shape)
        label = l.as_in_context(ctx)
        with autograd.record():
            output = net(data)
            loss = softmax_cross_entropy(output, label)
        loss.backward()
        trainer.step(data.shape[0])

Steps to reproduce

(Paste the commands you ran that produced the error.)

  1. generate record file
  2. python ~/incubator-mxnet/tools/im2rec.py shape_images ./shape_1/
    --recursive=true --train-ratio=0.9 --list=true
  3. python ~/incubator-mxnet/tools/im2rec.py shape_images ./shape_1/
    4.Use any network to train your own record file, the error will show.

What have you tried to solve it?

  1. regenerate record file
  2. use python2.7 and python3 to generate record file

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions