Infer_shape error when trying to feed images to my network

hello,
when trying to feed my data into my network for training, i get this error:

infer_shape error. Arguments:
  data0: (3, 160, 160)
  data1: (32, 32, 64)
  data2: (32, 32, 64)
Traceback (most recent call last):
  File "E:\projects\python\captcha_solver\lib\site-packages\mxnet\gluon\block.py", line 811, in _call_cached_op
    for is_arg, i in self._cached_op_args]
  File "E:\projects\python\captcha_solver\lib\site-packages\mxnet\gluon\block.py", line 811, in <listcomp>
    for is_arg, i in self._cached_op_args]
  File "E:\projects\python\captcha_solver\lib\site-packages\mxnet\gluon\parameter.py", line 543, in data
    return self._check_and_get(self._data, ctx)
  File "E:\projects\python\captcha_solver\lib\site-packages\mxnet\gluon\parameter.py", line 234, in _check_and_get
    "num_features, etc., for network layers."%(self.name))
mxnet.gluon.parameter.DeferredInitializationError: Parameter 'seq2seq0_encoder0_conv0_weight' has not been initialized yet because initialization was deferred. Actual initialization happens during the first forward pass. Please pass one batch of data through the network before accessing Parameters. You can also avoid deferred initialization by specifying in_units, num_features, etc., for network layers.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\projects\python\captcha_solver\lib\site-packages\mxnet\gluon\block.py", line 797, in _deferred_infer_shape
    self.infer_shape(*args)
  File "E:\projects\python\captcha_solver\lib\site-packages\mxnet\gluon\block.py", line 870, in infer_shape
    self._infer_attrs('infer_shape', 'shape', *args)
  File "E:\projects\python\captcha_solver\lib\site-packages\mxnet\gluon\block.py", line 859, in _infer_attrs
    **{i.name: getattr(j, attr) for i, j in zip(inputs, args)})
  File "E:\projects\python\captcha_solver\lib\site-packages\mxnet\symbol\symbol.py", line 1076, in infer_shape
    res = self._infer_shape_impl(False, *args, **kwargs)
  File "E:\projects\python\captcha_solver\lib\site-packages\mxnet\symbol\symbol.py", line 1210, in _infer_shape_impl
    ctypes.byref(complete)))
  File "E:\projects\python\captcha_solver\lib\site-packages\mxnet\base.py", line 253, in check_call
    raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: Error in operator seq2seq0_encoder0_conv0_fwd: [11:02:23] C:\Jenkins\workspace\mxnet-tag\mxnet\src\operator\nn\convolution.cc:152: Check failed: dshp.ndim() == 4U (3 vs. 4) : Input data should be 4D in batch-num_filter-y-x

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "train.py", line 78, in <module>
    o = m(xt, yt)
  File "E:\projects\python\captcha_solver\lib\site-packages\mxnet\gluon\block.py", line 548, in __call__
    out = self.forward(*args)
  File "E:\projects\python\captcha_solver\seq2seq.py", line 22, in forward
    encoder_outputs, state = self.encoder(source[i], state)
  File "E:\projects\python\captcha_solver\lib\site-packages\mxnet\gluon\block.py", line 548, in __call__
    out = self.forward(*args)
  File "E:\projects\python\captcha_solver\lib\site-packages\mxnet\gluon\block.py", line 915, in forward
    return self._call_cached_op(x, *args)
  File "E:\projects\python\captcha_solver\lib\site-packages\mxnet\gluon\block.py", line 813, in _call_cached_op
    self._deferred_infer_shape(*args)
  File "E:\projects\python\captcha_solver\lib\site-packages\mxnet\gluon\block.py", line 801, in _deferred_infer_shape
    raise ValueError(error_msg)
ValueError: Deferred initialization failed because shape cannot be inferred. Error in operator seq2seq0_encoder0_conv0_fwd: [11:02:23] C:\Jenkins\workspace\mxnet-tag\mxnet\src\operator\nn\convolution.cc:152: Check failed: dshp.ndim() == 4U (3 vs. 4) : Input data should be 4D in batch-num_filter-y-x

I don’t know what is the problem
this is the code which loads the data:

with open("data/train.csv", "r", encoding="utf-8", newline="\n") as f:
	max_lines = len(f.readlines())

with open("data/train.csv", "r", encoding="utf-8", newline="\n") as f:
	r = csv.reader(f)
	x_train = nd.zeros((max_lines, 3, 160, 160), dtype=np.float32)
	y_train = nd.zeros((max_lines, 32, 65))
	for i, row in enumerate(r):
		img = cv2.imread("data/train/"+row[0])
		img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
		img = img.astype(np.float32)/255
		x_train[i] = nd.array(img).transpose((2, 0, 1))
		y_train[i] = string_to_array(row[1], 32)
		print("image {0} of {1} loaded".format(i, max_lines))

this part loads the images and it’s textual data (y) to feed into the network
now, for turning them into batches, i use DataLoader along with an array dataset
but, i don’t know what is wrong with this because when i print the x’s shape when loaded into batches, it’s shape is (batch_size, channels, y, x)
thanks.

hi,
I’ve managed to fix that.
the error was result of my mistake.
(I ran a for loop during my forward pass in the model and that was the result).