text: 
  import torch,math
  from pathlib import Path
  import pandas as pd
  import numpy as np
  import matplotlib.pyplot as plt  
  from torchvision import datasets as dsets, transforms
  from torch.utils.data import Dataset, DataLoader
  
  import torch.nn.functional as F
  import torch.nn as NN
  torch.__version__
  
  DATA_PATH=Path('./data/fashion_mnist')
  
  train = pd.read_csv(DATA_PATH / "fashion-mnist_train.csv");
  print(train.head(10))
  
  test = pd.read_csv(DATA_PATH / "fashion-mnist_test.csv");
  print(test.head(10))
  
  print(train.max())
  
  
  import struct
  
  # with open(DATA_PATH / "train-images-idx3-ubyte", 'rb') as file_object:
  #     raw_img = file_object.read(28*28)
  #     img = struct.unpack(">784B",raw_img)
  #     image = np.asarray(img)
  #     image = image.reshape((28,28))
  #     print(image.shape)
  #     plt.imshow(image,cmap = plt.cm.gray)
  #     plt.show()
  
  
  class FashionMNISTDataset(Dataset):
      def __init__(self, csv_file, transform=None):
          data = pd.read_csv(csv_file)
          self.X = np.array(data.iloc[:, 1:]).reshape(-1, 1, 28, 28).astype(float)
          self.Y = np.array(data.iloc[:, 0]);
          del data;  #结束data对数据的引用,节省空间
          self.len=len(self.X)
  
      def __len__(self):
          #return len(self.X)
          return self.len
          
      
      def __getitem__(self, idx):
          item = self.X[idx]
          label = self.Y[idx]
          return (item, label)
  train_dataset = FashionMNISTDataset(csv_file=DATA_PATH / "fashion-mnist_train.csv")
  test_dataset = FashionMNISTDataset(csv_file=DATA_PATH / "fashion-mnist_test.csv")
  BATCH_SIZE=256
  train_loader = torch.utils.data.DataLoader(dataset=train_dataset,
                                             batch_size=BATCH_SIZE,
                                             shuffle=True) # shuffle 标识要打乱顺序
  test_loader = torch.utils.data.DataLoader(dataset=test_dataset,
                                             batch_size=BATCH_SIZE,
                                             shuffle=False) # shuffle 标识要打乱顺序，测试集不需要打乱
  
  a=iter(train_loader)
  data=next(a)
  img=data[0][0].reshape(28,28)
  print(data[0][0].shape,img.shape)
  
  plt.imshow(img,cmap = plt.cm.gray)
  plt.show()
  
  class CNN(NN.Module):
      def __init__(self):
          super(CNN, self).__init__()
          self.layer1 = NN.Sequential(   
              NN.Conv2d(1, 16, kernel_size=5, padding=2),
              NN.BatchNorm2d(16), 
              NN.ReLU()) #16, 28, 28
          self.pool1=NN.MaxPool2d(2) #16, 14, 14
          self.layer2 = NN.Sequential(
              NN.Conv2d(16, 32, kernel_size=3),
              NN.BatchNorm2d(32),
              NN.ReLU())#32, 12, 12
          self.layer3 = NN.Sequential(
              NN.Conv2d(32, 64, kernel_size=3),
              NN.BatchNorm2d(64),
              NN.ReLU()) #64, 10, 10
          self.pool2=NN.MaxPool2d(2)  #64, 5, 5
          self.fc = NN.Linear(5*5*64, 10)
      def forward(self, x):
          out = self.layer1(x)
          #print(out.shape)
          out=self.pool1(out)
          #print(out.shape)
          out = self.layer2(out)
          #print(out.shape)
          out=self.layer3(out)
          #print(out.shape)
          out=self.pool2(out)
          #print(out.shape)
          out = out.view(out.size(0), -1)
          #print(out.shape)
          out = self.fc(out)
          return out
  cnn = CNN();
  DEVICE=torch.device("cpu")
  if torch.cuda.is_available():
          DEVICE=torch.device("cuda")
  print(DEVICE)
  cnn=cnn.to(DEVICE)
  criterion = NN.CrossEntropyLoss().to(DEVICE)
  LEARNING_RATE=0.01
  para = list(cnn.parameters())
  print(para)
  optimizer = torch.optim.Adam(cnn.parameters(), lr=LEARNING_RATE)
  TOTAL_EPOCHS=50
  
  losses = [];
  for epoch in range(TOTAL_EPOCHS):
      for i, (images, labels) in enumerate(train_loader):
          images = images.float().to(DEVICE)
          labels = labels.to(DEVICE)
          #清零
          optimizer.zero_grad()
          outputs = cnn(images)
          #计算损失函数
          loss = criterion(outputs, labels)
          loss.backward()
          optimizer.step()
          losses.append(loss.cpu().data.item());
          if (i+1) % 100 == 0:
              print ('Epoch : %d/%d, Iter : %d/%d,  Loss: %.4f'%(epoch+1, TOTAL_EPOCHS, i+1, len(train_dataset)//BATCH_SIZE, loss.data.item()))