MXNet Forum

Gluon.data.vision transforms throws AssertionError


#1

I’ve implemented a image classification model that trains well. I have then moved onto doing image augmentation at training time via gluon.data.vision package a la

https://gluon-cv.mxnet.io/build/examples_classification/dive_deep_cifar10.html#sphx-glr-build-examples-classification-dive-deep-cifar10-py

transform_train = transforms.Compose([
# Randomly flip the image horizontally
transforms.RandomFlipLeftRight(),
# Randomly flip the image horizontally
transforms.RandomFlipTopBottom(),
# Randomly jitter the brightness, contrast and saturation of the image
transforms.RandomColorJitter(brightness=0.1, contrast=0.1, saturation=0.1),
# Randomly adding noise to the image
transforms.RandomLighting(0.1)
])
then

train_data = gluon.data.ArrayDataset(train_X, train_Y)
train_iter = gluon.data.DataLoader(train_data.transform_first(transform_train),
BATCHSIZE, shuffle=True)

When calling
for i (data, label) in enumerate(train_iter):
some_task()

I get the following error

AssertionError: HybridBlock requires the first argument to forward be either Symbol or NDArray, but got <class ‘numpy.ndarray’>

Any idea how to fix this?


#2

The problem is that your inputs (train_X, train_Y) are numpy arrays. You need to convert them to mx.nd.arrays. The following should work: train_data = gluon.data.ArrayDataset(mx.nd.array(train_X), mx.nd.array(train_Y))