赞
踩
效果演示图如下:
代码按照顺序运行即可
vgg训练模型的代码如下:
- import torch
- from PIL import Image
- from torchvision import datasets, models, transforms,utils
- import torch.nn as nn
- import numpy as np
- import random
- import os
- import torchvision
- from tqdm import tqdm
-
- #设置随机种子
-
- def setup_seed(seed):
- torch.manual_seed(seed)
- torch.cuda.manual_seed(seed)
- torch.cuda.manual_seed_all(seed)
- np.random.seed(seed)
- random.seed(seed)
- torch.backends.cudnn.benchmark = False
- torch.backends.cudnn.deterministic = True
- torch.backends.cudnn.enabled = True
- os.environ['PYTHONHASHSEED'] = str(seed)
- setup_seed(20)
-
- root = './'
-
- # Hyper parameters
- num_epochs = 3 #循环次数
- batch_size = 2 #每次投喂数据量
- learning_rate = 0.00005 #学习率
- momentum = 0.9 #变化率
- num_classes = 2 #几分类
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。