资源简介
深度学习入门之Pytorch(带书签和源码)
代码片段和文件信息
from datetime import datetime
import torch
import torch.nn.functional as F
from torch import nn
from torch.autograd import Variable
def get_acc(output label):
total = output.shape[0]
_ pred_label = output.max(1)
num_correct = (pred_label == label).sum().data[0]
return num_correct / total
def train(net train_data valid_data num_epochs optimizer criterion):
if torch.cuda.is_available():
net = net.cuda()
prev_time = datetime.now()
for epoch in range(num_epochs):
train_loss = 0
train_acc = 0
net = net.train()
for im label in train_data:
if torch.cuda.is_available():
im = Variable(im.cuda()) # (bs 3 h w)
label = Variable(label.cuda()) # (bs h w)
else:
im = Variable(im)
label = Variable(label)
# forward
output = net(im)
loss = criterion(output label)
# backward
optimizer.zero_grad()
loss.backward()
optimizer.step()
train_loss += loss.data[0]
train_acc += get_acc(output label)
cur_time = datetime.now()
h remainder = divmod((cur_time - prev_time).seconds 3600)
m s = divmod(remainder 60)
time_str = “Time %02d:%02d:%02d“ % (h m s)
if valid_data is not None:
valid_loss = 0
valid_acc = 0
net = net.eval()
for im label in valid_data:
if torch.cuda.is_available():
im = Variable(im.cuda() volatile=True)
label = Variable(label.cuda() volatile=True)
else:
im = Variable(im volatile=True)
label = Variable(label volatile=True)
output = net(im)
loss = criterion(output label)
valid_loss += loss.data[0]
valid_acc += get_acc(output label)
epoch_str = (
“Epoch %d. Train Loss: %f Train Acc: %f Valid Loss: %f Valid Acc: %f “
% (epoch train_loss / len(train_data)
train_acc / len(train_data) valid_loss / len(valid_data)
valid_acc / len(valid_data)))
else:
epoch_str = (“Epoch %d. Train Loss: %f Train Acc: %f “ %
(epoch train_loss / len(train_data)
train_acc / len(train_data)))
prev_time = cur_time
print(epoch_str + time_str)
def conv3x3(in_channel out_channel stride=1):
return nn.Conv2d(
in_channel out_channel 3 stride=stride padding=1 bias=False)
class residual_block(nn.Module):
def __init__(self in_channel out_channel same_shape=True):
super(residual_block self).__init__()
self.same_shape = same_shape
stride
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-04-29 22:39 code-of-learn-deep-learning-with-pytorch\
目录 0 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\
文件 25 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.gitignore
文件 337 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\config
文件 73 2018-04-29 22:37 code-of-learn-deep-learning-with-pytorch\.git\desc
文件 23 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\HEAD
目录 0 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\hooks\
文件 478 2018-04-29 22:37 code-of-learn-deep-learning-with-pytorch\.git\hooks\applypatch-msg.sample
文件 896 2018-04-29 22:37 code-of-learn-deep-learning-with-pytorch\.git\hooks\commit-msg.sample
文件 3327 2018-04-29 22:37 code-of-learn-deep-learning-with-pytorch\.git\hooks\fsmonitor-watchman.sample
文件 189 2018-04-29 22:37 code-of-learn-deep-learning-with-pytorch\.git\hooks\post-update.sample
文件 424 2018-04-29 22:37 code-of-learn-deep-learning-with-pytorch\.git\hooks\pre-applypatch.sample
文件 1642 2018-04-29 22:37 code-of-learn-deep-learning-with-pytorch\.git\hooks\pre-commit.sample
文件 1348 2018-04-29 22:37 code-of-learn-deep-learning-with-pytorch\.git\hooks\pre-push.sample
文件 4898 2018-04-29 22:37 code-of-learn-deep-learning-with-pytorch\.git\hooks\pre-reba
文件 544 2018-04-29 22:37 code-of-learn-deep-learning-with-pytorch\.git\hooks\pre-receive.sample
文件 1492 2018-04-29 22:37 code-of-learn-deep-learning-with-pytorch\.git\hooks\prepare-commit-msg.sample
文件 3610 2018-04-29 22:37 code-of-learn-deep-learning-with-pytorch\.git\hooks\update.sample
文件 14291 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\index
目录 0 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\info\
文件 240 2018-04-29 22:37 code-of-learn-deep-learning-with-pytorch\.git\info\exclude
目录 0 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\logs\
文件 214 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\logs\HEAD
目录 0 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\logs\refs\
目录 0 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\logs\refs\heads\
文件 214 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\logs\refs\heads\master
目录 0 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\logs\refs\remotes\
目录 0 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\logs\refs\remotes\origin\
文件 214 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\logs\refs\remotes\origin\HEAD
目录 0 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\ob
目录 0 2018-04-29 22:38 code-of-learn-deep-learning-with-pytorch\.git\ob
............此处省略162个文件信息
- 上一篇:微机测控系统设计
- 下一篇:freeba
se的entity id到真实数据的映射
相关资源
- 基于深度学习的自然语言处理 中文
- 基于深度学习的中文自然语言处理工
- DL+SLAM近两年深度学习结合SLAM的一些研
- 机器学习与R语言 pdf
- 图解机器学习高清完整.pdf版
- Hands On Machine Learning中+英
- Machine Learning for Hackers中英文
- 机器学习英文论文
- 卷积神经网络实现车牌识别.zip
- tkinter+cv2+tensorflow车牌识别软件.zip
- 人脸-帽子数据集-1600.zip
- 深度学习之美-张玉宏
- cognex vidi深度学习图像处理软件使用说
- 有关深度学习的引导理论、案例和源
- 完整版基于OPENCV的车牌识别系统源码
- 李飞飞深度学习课件及作业PDF
- 基于深度学习的图像超分辨率paper集
- 中国科学院大学 深度学习完整课件
- 数据科学:理论、方法与R语言实践
- 细粒度用户评论情感分析数据集(2
- Hands-On Machine Learning with Scikit-Learn an
- PRML英文版+中文版
- 机器学习第二版
- Scikit-Learn与TensorFlow机器学习实用指南
- 《揭秘深度强化学习—彭伟》高清中
- 利用TensorFlow构建LSTM对多维数据进行拟
- 神经网络与深度学习-邱锡鹏,高清书
- 泰迪杯2019年A题题目pdf+参考文献pdf高
- 新闻文本分类数据集50000条
- 邹博机器学习ppt+code全
评论
共有 条评论