没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
关于关于ResNeXt网络的网络的pytorch实现实现
今天小编就为大家分享一篇关于ResNeXt网络的pytorch实现,具有很好的参考价值,希望对大家有所帮助。一
起跟随小编过来看看吧
此处需要此处需要pip install pretrainedmodels
"""
Finetuning Torchvision Models
"""
from __future__ import print_function
from __future__ import division
import torch
import torch.nn as nn
import torch.optim as optim
import numpy as np
import torchvision
from torchvision import datasets, models, transforms
import matplotlib.pyplot as plt
import time
import os
import copy
import argparse
import pretrainedmodels.models.resnext as resnext
print("PyTorch Version: ",torch.__version__)
print("Torchvision Version: ",torchvision.__version__)
# Top level data directory. Here we assume the format of the directory conforms
# to the ImageFolder structure
#data_dir = "./data/hymenoptera_data"
data_dir = "/media/dell/dell/data/13/"
# Models to choose from [resnet, alexnet, vgg, squeezenet, densenet, inception]
model_name = "resnext"
# Number of classes in the dataset
num_classes = 171
# Batch size for training (change depending on how much memory you have)
batch_size = 16
# Number of epochs to train for
num_epochs = 1000
# Flag for feature extracting. When False, we finetune the whole model,
# when True we only update the reshaped layer params
feature_extract = False
# 参数设置,使得我们能够手动输入命令行参数,就是让风格变得和Linux命令行差不多
parser = argparse.ArgumentParser(description='PyTorch seresnet')
parser.add_argument('--outf', default='/home/dell/Desktop/zhou/train7', help='folder to output images and model checkpoints') #输出结果保存路径
parser.add_argument('--net', default='/home/dell/Desktop/zhou/train7/resnext.pth', help="path to net (to continue training)") #恢复训练时的模型路径
args = parser.parse_args()
def train_model(model, dataloaders, criterion, optimizer, num_epochs=25,is_inception=False):
#def train_model(model, dataloaders, criterion, optimizer, num_epochs=25,scheduler, is_inception=False):
since = time.time()
val_acc_history = []
best_model_wts = copy.deepcopy(model.state_dict())
best_acc = 0.0
print("Start Training, resnext!") # 定义遍历数据集的次数
with open("/home/dell/Desktop/zhou/train7/acc.txt", "w") as f1:
with open("/home/dell/Desktop/zhou/train7/log.txt", "w")as f2:
for epoch in range(num_epochs):
print('Epoch {}/{}'.format(epoch+1, num_epochs))
print('*' * 10)
# Each epoch has a training and validation phase
for phase in ['train', 'val']:
if phase == 'train':
#scheduler.step()
model.train() # Set model to training mode
else:
model.eval() # Set model to evaluate mode
资源评论
weixin_38617413
- 粉丝: 7
- 资源: 927
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于 Java的扫雷程序毕业设计
- axure9 里面有码 axure9 里面有码
- 551-2404242311-1.amr
- 自己搭建的关于springboot整合mybatis的框架.zip
- 这是一个保存Springboot+MyBaits项目的仓库.zip
- tensorflow-gpu-2.7.2-cp39-cp39-manylinux2010-x86-64.whl
- tensorflow-2.7.4-cp38-cp38-manylinux2010-x86-64.whl
- tensorflow-gpu-2.7.4-cp38-cp38-manylinux2010-x86-64.whl
- 詹佳 陈敏 口语2.mp3
- 图书管理系统毕业设计Java语言实现
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功