This repository was archived by the owner on Nov 17, 2023. It is now read-only.
Errro when running Conv model. #19780
Unanswered
Johnny-dai-git
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I am trying to run MNIST datset on Conv1d layer model. Based on my understanding, we will need to faltten the Mnist dataset in to 1D instead of 2D . Actually, the MNIST iterator has the flat label. But it still does not work.
Here is the code I am using:
"""Get the train and the val iterator , Flatten the data from(1,28,28) to (1,784)"""
train = mx.io.MNISTIter(
image = "data/train-images-idx3-ubyte",
label = "data/train-labels-idx1-ubyte",
batch_size = 20,
flat=True,
data_shape = (784, ))
val = mx.io.MNISTIter(
image="data/train-images-idx3-ubyte",
label="data/train-labels-idx1-ubyte",
batch_size=20,
flat=True,
data_shape=(784, ))
"""Here is my small model and I only do the forwarding """
net = nn.Sequential()
net.add(
nn.Conv1D(channels=1,kernel_size=1,in_channels=1),
nn.Dense(units=10)
)
net.initialize()
for i, batch in enumerate(train):
""" Here is the error message"""
/Users/xiangrenbaibaoxiang/Desktop/johnny_source_code/pcap/conv2d/tmp/venv/bin/python /Users/xiangrenbaibaoxiang/Desktop/johnny_source_code/souce_code/mxnet/example/gluon/imdb.py
[13:35:18] ../src/io/iter_mnist.cc:110: MNISTIter: load 60000 images, shuffle=1, shape=(20,784)
[13:35:20] ../src/io/iter_mnist.cc:110: MNISTIter: load 60000 images, shuffle=1, shape=(20,784)
DataBatch: data shapes: [(20, 784)] label shapes: [(20,)]
0
Traceback (most recent call last):
File "/Users/xiangrenbaibaoxiang/Desktop/johnny_source_code/souce_code/mxnet/example/gluon/imdb.py", line 54, in
z = net(x)
File "/Users/xiangrenbaibaoxiang/Desktop/johnny_source_code/pcap/conv2d/tmp/venv/lib/python3.9/site-packages/mxnet/gluon/block.py", line 682, in call
out = self.forward(*args)
File "/Users/xiangrenbaibaoxiang/Desktop/johnny_source_code/pcap/conv2d/tmp/venv/lib/python3.9/site-packages/mxnet/gluon/nn/basic_layers.py", line 55, in forward
x = block(x)
File "/Users/xiangrenbaibaoxiang/Desktop/johnny_source_code/pcap/conv2d/tmp/venv/lib/python3.9/site-packages/mxnet/gluon/block.py", line 682, in call
out = self.forward(*args)
File "/Users/xiangrenbaibaoxiang/Desktop/johnny_source_code/pcap/conv2d/tmp/venv/lib/python3.9/site-packages/mxnet/gluon/block.py", line 1258, in forward
return self.hybrid_forward(ndarray, x, *args, **params)
File "/Users/xiangrenbaibaoxiang/Desktop/johnny_source_code/pcap/conv2d/tmp/venv/lib/python3.9/site-packages/mxnet/gluon/nn/conv_layers.py", line 147, in hybrid_forward
act = getattr(F, self._op_name)(x, weight, bias, name='fwd', **self._kwargs)
File "", line 169, in Convolution
File "/Users/xiangrenbaibaoxiang/Desktop/johnny_source_code/pcap/conv2d/tmp/venv/lib/python3.9/site-packages/mxnet/_ctypes/ndarray.py", line 82, in _imperative_invoke
check_call(_LIB.MXImperativeInvokeEx(
File "/Users/xiangrenbaibaoxiang/Desktop/johnny_source_code/pcap/conv2d/tmp/venv/lib/python3.9/site-packages/mxnet/base.py", line 246, in check_call
raise get_last_ffi_error()
mxnet.base.MXNetError: Traceback (most recent call last):
File "../src/operator/nn/convolution.cc", line 103
MXNetError: Check failed: dshp.ndim() == 3U (2 vs. 3) : Input data should be 3D in batch-num_filter-x
"""My guess"""
It seems that after flatten, the Minister forget the channels information. after flatten, we only have(batch_size, 1D size), however, they require (batch_size, channel, 1D size). I have several questions:
(1), How can I get the right data from the Mnistiterator ?
(2), Can I reshape the iterator ?
(3). Any other way to figure it out?
Thank you!
Johnny
Beta Was this translation helpful? Give feedback.
All reactions