Incubator-mxnet: AttributeError: 'list' object has no attribute 'shape'

Created on 22 Oct 2016  路  10Comments  路  Source: apache/incubator-mxnet

10-22 22:43:18 Start training with [gpu(1)]
Traceback (most recent call last):
File "/home/xiaomin/wxm/Code/KaggleSeizure2016/ex_mxnet.py", line 229, in
fitter.fit()
File "/home/xiaomin/wxm/Code/KaggleSeizure2016/ex_mxnet.py", line 220, in fit
batch_end_callback=call_back,
File "/home/xiaomin/MXNet/mxnet/python/mxnet/model.py", line 829, in fit
sym_gen=self.sym_gen)
File "/home/xiaomin/MXNet/mxnet/python/mxnet/model.py", line 234, in _train_multi_device
executor_manager.load_data_batch(data_batch)
File "/home/xiaomin/MXNet/mxnet/python/mxnet/executor_manager.py", line 447, in load_data_batch
self.curr_execgrp.load_data_batch(data_batch)
File "/home/xiaomin/MXNet/mxnet/python/mxnet/executor_manager.py", line 281, in load_data_batch
_load_data(data_batch, self.data_arrays)
File "/home/xiaomin/MXNet/mxnet/python/mxnet/executor_manager.py", line 93, in _load_data
_load_general(batch.data, targets)
File "/home/xiaomin/MXNet/mxnet/python/mxnet/executor_manager.py", line 84, in _load_general
if d_src[slice_idx].shape != d_dst.shape:
AttributeError: 'list' object has no attribute 'shape'

seems somethings wrong with the mxnet's python source code?

Most helpful comment

Another thing I did to sovle the problem is that I reinstalled mxnet. it works surprisely!

All 10 comments

your data iter must return mx.io.DataIter(data=[mx.nd.array(...)],...)

IMO, I think there is a bug with the source code, since I am following the rnn example to construct a cnn+rnn symbol. It goes well when I just run the cnn while the error raised when I add RNN to cnn. As using RNN we need to pass the init state from the DataIter, So d_src[slice_idx] is actually a list of [data, init_h, init_cell] rather than a mx.nd array(which is the data used in cnn experiements)

Please post your data iter

`

class DataLoader(mx.io.DataIter):
"""Data loader for lane detection."""
def init(self, data_list, input_args, init_states=None):
super(DataLoader, self).init()
self.input_args = input_args

    self.data_list = read_list(data_list)
    random.shuffle(self.data_list)
    self.data_path = input_args.get('data_path')
    self.data_shape = input_args.get('data_shape')
    self.multi_thread = input_args.get('multi_thread', False)
    self.n_thread = input_args.get('n_thread', 5)
    self.stop_word = input_args.get('stop_word', '==STOP--')
    self.batch_size = input_args.get('batch_size', 10)
    self.stride = input_args.get('stride')

    # Image pre-process options
    self.im_size = input_args.get('im_size')

    self.current_batch = None
    self.data_num = None
    self.current = None
    self.worker_proc = None

    # for rnn
    self.init_states = init_states
    self.init_state_arrays = [mx.nd.zeros(x[1]) for x in init_states]

    if self.multi_thread:
        self.stop_flag = mp.Value('b', False)
        self.result_queue = mp.Queue(maxsize=self.batch_size*5)
        self.data_queue = mp.Queue()

def _insert_queue(self):
    for item in self.data_list:
        self.data_queue.put(item)
    for i in range(self.n_thread):
        self.data_queue.put(self.stop_word)

def _thread_start(self):
    self.stop_flag = False
    self.worker_proc = [mp.Process(target=DataLoader._worker,
                                   args=[self.data_queue,
                                         self.result_queue,
                                         self.stop_word,
                                         self.stop_flag,
                                         self.input_args
                                         ]) for i in range(self.n_thread)]
    [item.start() for item in self.worker_proc]

    def cleanup():
        self.shutdown()
    atexit.register(cleanup)

@staticmethod
def _worker(data_queue, result_queue, stop_word, stop_flag, input_args):
    count = 0
    for item in iter(data_queue.get, stop_word):
        if stop_flag == 1:
            break
        image, cls_label, index = DataLoader._get_single(item, input_args)
        result_queue.put((image, cls_label, index))
        count += 1

@property
def provide_label(self):
    return [('label', tuple([self.batch_size] + list(self.data_shape[1])))]

@property
def provide_data(self):
    return [('data', tuple([self.batch_size] + list(self.data_shape[0])))] + self.init_states

def reset(self):
    self.data_num = len(self.data_list)
    self.current = 0
    self.shuffle()
    if self.multi_thread:
        self.shutdown()            # Shutdown data-reading threads
        self._insert_queue()       # Initialize data_queue
        self._thread_start()       # Start multi thread

def shutdown(self):
    if self.multi_thread:
        # clean queue
        while True:
            try:
                self.result_queue.get(timeout=1)
            except Queue.Empty:
                break
        while True:
            try:
                self.data_queue.get(timeout=1)
            except Queue.Empty:
                break
        # stop worker
        self.stop_flag = True
        if self.worker_proc:
            for i, worker in enumerate(self.worker_proc):
                worker.join(timeout=1)
                if worker.is_alive():
                    logging.error('worker {} fails to join'.format(i))
                    worker.terminate()

def shuffle(self):
    random.shuffle(self.data_list)
    pass

def next(self):
    if self._get_next():
        return self.current_batch
    else:
        raise StopIteration

def _get_next(self):
    batch_size = self.batch_size
    if self.current + batch_size > self.data_num:
        return False

    x = np.zeros(tuple([self.batch_size] + list(self.data_shape[0])))
    y = np.zeros(tuple([self.batch_size] + list(self.data_shape[1])))
    indexs = []
    items = self.data_list
    cnt = 0
    for i in range(self.current, self.current + batch_size):
        if self.multi_thread:
            image, cls_label, index = self.result_queue.get()
        else:
            image, cls_label, index = DataLoader._get_single(items[i], self.input_args)
        x[cnt, :, :, :] = image
        y[cnt, :] = cls_label
        indexs.append(index)
        cnt += 1
    x = [mx.ndarray.array(x)] + self.init_state_arrays
    y = mx.ndarray.array(y)
    self.current_batch = mx.io.DataBatch(data=[x], label=[y], pad=0, index=None)
    self.current += batch_size
    return True

@staticmethod
def _get_single(item, input_args):
    return get_single_wav(item, input_args)`

data=[x] -> data=x

@piiswrong Thanks a lot!
However another error just occurs:
[10:17:17] /home/xiaomin/MXNet/mxnet/dmlc-core/include/dmlc/logging.h:235: [10:17:17] /home/xiaomin/MXNet/mxnet/mshadow/mshadow/tensor_blob.h:664: Check failed: Device::kDevMask == dev_mask_ TBlob.get: device type do not match specified type
[10:17:17] /home/xiaomin/MXNet/mxnet/dmlc-core/include/dmlc/logging.h:235: [10:17:17] src/engine/./threaded_engine.h:306: [10:17:17] /home/xiaomin/MXNet/mxnet/mshadow/mshadow/tensor_blob.h:664: Check failed: Device::kDevMask == dev_mask_ TBlob.get: device type do not match specified type
An fatal error occurred in asynchronous engine operation. If you do not know what caused this error, you can try set environment variable MXNET_ENGINE_TYPE to NaiveEngine and run with debugger (i.e. gdb). This will force all operations to be synchronous and backtrace will give you the series of calls that lead to this error. Remember to set MXNET_ENGINE_TYPE back to empty after debugging.
terminate called after throwing an instance of 'dmlc::Error'
what(): [10:17:17] src/engine/./threaded_engine.h:306: [10:17:17] /home/xiaomin/MXNet/mxnet/mshadow/mshadow/tensor_blob.h:664: Check failed: Device::kDevMask == dev_mask_ TBlob.get: device type do not match specified type
An fatal error occurred in asynchronous engine operation. If you do not know what caused this error, you can try set environment variable MXNET_ENGINE_TYPE to NaiveEngine and run with debugger (i.e. gdb). This will force all operations to be synchronous and backtrace will give you the series of calls that lead to this error. Remember to set MXNET_ENGINE_TYPE back to empty after debugging.

And I set an issue up here[https://github.com/dmlc/mxnet/issues/3600]

Also I tried data=[x] -> data=x and label = [y] -> label = y;
Then:
[10:25:22] /home/xiaomin/MXNet/mxnet/dmlc-core/include/dmlc/logging.h:235: [10:25:22] include/mxnet/ndarray.h:231: Check failed: (shape_[0]) >= (end) Slice end index out of range
Traceback (most recent call last):
File "/home/xiaomin/wxm/Code/KaggleSeizure2016/ex_mxnet.py", line 229, in
fitter.fit()
File "/home/xiaomin/wxm/Code/KaggleSeizure2016/ex_mxnet.py", line 220, in fit
batch_end_callback=call_back,
File "/home/xiaomin/MXNet/mxnet/python/mxnet/model.py", line 829, in fit
sym_gen=self.sym_gen)
File "/home/xiaomin/MXNet/mxnet/python/mxnet/model.py", line 234, in _train_multi_device
executor_manager.load_data_batch(data_batch)
File "/home/xiaomin/MXNet/mxnet/python/mxnet/executor_manager.py", line 446, in load_data_batch
self.curr_execgrp.load_data_batch(data_batch)
File "/home/xiaomin/MXNet/mxnet/python/mxnet/executor_manager.py", line 281, in load_data_batch
_load_label(data_batch, self.label_arrays)
File "/home/xiaomin/MXNet/mxnet/python/mxnet/executor_manager.py", line 96, in _load_label
_load_general(batch.label, targets)
File "/home/xiaomin/MXNet/mxnet/python/mxnet/executor_manager.py", line 83, in _load_general
if d_src[slice_idx].shape != d_dst.shape:
File "/home/xiaomin/MXNet/mxnet/python/mxnet/ndarray.py", line 236, in __getitem__
return self._slice(in_slice.start, in_slice.stop)
File "/home/xiaomin/MXNet/mxnet/python/mxnet/ndarray.py", line 276, in _slice
self.handle, start, stop, ctypes.byref(handle)))
File "/home/xiaomin/MXNet/mxnet/python/mxnet/base.py", line 77, in check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: [10:25:22] include/mxnet/ndarray.h:231: Check failed: (shape_[0]) >= (end) Slice end index out of range

I think you should print the provided data shape and the feed data shape. Make sure they are matched.

Thank U guys @piiswrong @shuokay . It finally works.
Actually Mxnet need list input for mx.io.DataBatch:
x = [mx.ndarray.array(x)] + self.init_state_arrays
y = [mx.ndarray.array(y)]
self.current_batch = mx.io.DataBatch(data=x, label=y, pad=0, index=None)

When it come to:
x = [mx.ndarray.array(x)] + self.init_state_arrays
y = mx.ndarray.array(y)
self.current_batch = mx.io.DataBatch(data=x, label=y, pad=0, index=None)
Then:
Check failed: (shape[0]) >= (end) Slice end index out of range

Another thing I did to sovle the problem is that I reinstalled mxnet. it works surprisely!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JonBoyleCoding picture JonBoyleCoding  路  3Comments

xzqjack picture xzqjack  路  3Comments

xzqjack picture xzqjack  路  3Comments

yuconglin picture yuconglin  路  3Comments

ranti-iitg picture ranti-iitg  路  3Comments