Save the FashionMNIST dataset as a picture

This save is very simple, because after using pytorch to load the FashionMNIST data set, such a file will be generated

There are two files inside

So loading is very simple

import torch
import cv2
import numpy as np

train_data=torch.load("training.pt")[0].numpy()
test_data=torch.load("test.pt")[0].numpy()
print(train_data.shape)
print(test_data.shape)
#print(test_data[0])
for i  in range(train_data.shape[0]):     
    cv2.imwrite("train\\"+str(i)+".jpg",train_data[i][:,:,np.newaxis])
for i  in range(test_data.shape[0]):     
    cv2.imwrite("test\\"+str(i)+".jpg",test_data[i][:,:,np.newaxis])

 Create new train and test folders under the path before running

operation result

Friendly reminder: If you want to process the picture files and source files, you can go to my csdn resource to download

https://download.csdn.net/download/zhou_438/14040224

Guess you like

Origin blog.csdn.net/zhou_438/article/details/112318068