# Errror while predicting classes in fashion mnist

**URL:** <https://discuss.pytorch.org/t/errror-while-predicting-classes-in-fashion-mnist/138591>\
**Category:** vision\
**Created:** [December 5, 2021, 5:22pm UTC](https://discuss.pytorch.org/t/errror-while-predicting-classes-in-fashion-mnist/138591 "2021-12-05T17:22:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daneshwari\_Kankanwad](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/daneshwari_kankanwad/32/44615_2.png) [@Daneshwari\_Kankanwad](https://discuss.pytorch.org/u/Daneshwari_Kankanwad)\
**Post date:** [December 5, 2021, 5:22pm UTC](https://discuss.pytorch.org/t/errror-while-predicting-classes-in-fashion-mnist/138591/1 "2021-12-05T17:22:03Z")

</div>

I’m trying to predict cloth categories from fashion-mnist images. I referred code from [here](https://boscoj2008.github.io/customCNN/). I have created the whole model with architecture as in pic attached below and to get image pixels for prediction once the model is trained, I used the below code. The ‘images’ loaded is of size (10000,784) so I reshaped and created a new numpy.ndarray with shape (10000,28,28,1). I took 1st image from this(that is of type ndarray) and when I was trying to convert it to tensor(using transforms.ToTensor()) and then use it for prediction, I was facing dimension issues. So I referred this [discussion](https://discuss.pytorch.org/t/pytorch-1-0-how-to-predict-single-images-mnist-example/32394). But I’m facing a new error. I’m stuck at the last step and am unable to use the model to predict cloth category for a single image. Please suggest a solution, since I have tried every possible solution. Also please point where I might be wrong.

#for fashion-mnist images, got pixels as (10000,784) from here  
from mnist import MNIST  
mndata = MNIST(‘./FashionMNIST/raw/’)  
images, labels = mndata.load\_testing()

#tried this code from the discussion but its throwing another error  
single\_loaded\_img = test\_pred\_data\_loader.dataset.data[0]  
single\_loaded\_img = single\_loaded\_img[None, None]  
pred = cnn\_model(single\_loaded\_img)

# architecture diagram-

Network(  
(conv1): Conv2d(1, 6, kernel\_size=(5, 5), stride=(1, 1))  
(batchN1): BatchNorm2d(6, eps=1e-05, momentum=0.1, affine=True, track\_running\_stats=True)  
(conv2): Conv2d(6, 12, kernel\_size=(5, 5), stride=(1, 1))  
(fc1): Linear(in\_features=192, out\_features=120, bias=True)  
(batchN2): BatchNorm1d(120, eps=1e-05, momentum=0.1, affine=True, track\_running\_stats=True)  
(fc2): Linear(in\_features=120, out\_features=60, bias=True)  
(out): Linear(in\_features=60, out\_features=10, bias=True)  
)

 ![image](https://discuss.pytorch.org/uploads/default/original/3X/e/2/e2beb47cbb4cba189ad67bb177ae95ec68b0cd6c.png)

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [December 6, 2021, 1:04am UTC](https://discuss.pytorch.org/t/errror-while-predicting-classes-in-fashion-mnist/138591/2 "2021-12-06T01:04:19Z")

</div>

As the error message points out, the `numpy` array is invalid as the input to a conv layer, so you would need to transform them to PyTorch tensors.  
Add `transform=torchvision.transforms.ToTensor()` to the dataset and it should work.
