#CIFAR-10直接训练的train11代码,拿过省赛二等奖
import time
import copy
import numpy as np
import torch
import torchvision.models
from tqdm import tqdm
from torchvision.transforms import transforms
from torch import nn, optim
from torch.utils.data import DataLoader
from torchvision.datasets import CIFAR10
from torch.utils.tensorboard import SummaryWriter
if __name__ == "__main__":
# 这里面的变量都相当于全局变量 !!
# GPU计算
# 定义是否使用GPU
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# 训练总轮数
total_epochs = 2
# 每次取出样本数
batch_size = 128
# 初始学习率
Lr = 0.1
DATASET_PATH = './'
SAVE_PATH = './'
filename = '{}best_cnn_model'.format(SAVE_PATH) # 文件扩展名在保存时添加
torch.backends.cudnn.benchmark = True
# 准备数据
data_transforms = {
'train': transforms.Compose([
transforms.ToTensor(),