Github 项目推荐 | 基于 PyTorch,面向 AI 系统加速研究与开发的深度学习框架

2018 年 6 月 12 日 AI研习社

TorchFusion 是一个深度学习框架,主要用于 AI 系统加速研究和开发。

TorchFusion 基于 PyTorch 并且完全兼容纯 PyTorch 和其他 PyTorch 软件包,它供了一个全面的可扩展训练框架,可以轻松用开发者的 PyTorch 模型进行训练,评估和运行推理。

该框架具有高度可扩展性,所以开发者可以根据自己特定的目的来进行训练。

Github 链接:

https://github.com/johnolafenwa/TorchFusion

  独特功能

  • 高度可扩展

  • 高度详细的汇总功能,不仅为您提供了有关参数,层数,输入和输出大小的详细信息,还为网络中的每个线性和卷积层提供了Flops(Multiply-Adds)的数量。 现在,只需一个功能就可以知道任何CNN架构的确切计算成本!

  • 实时指标和损失可视化,并可选择永久保存它们

  • 支持永久保存日志

  • 易于使用的回调

注意:这只是 TorchFusion 的预发布版本,未来的 TorchFusion 将会跨越更多的深度学习领域。

  安装

安装 TorchFusion

pip3 install https://github.com/johnolafenwa/TorchFusion/releases/download/0.1.1/torchfusion-0.1.1-py3-none-any.whl

在 Windows 上安装 PyTorch:

https://pytorch.org/

CPU Only

With Python 3.6

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp36-cp36m-win_amd64.whl torchvision

With Python 3.5

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp35-cp35m-win_amd64.whl torchvision

CUDA 支持

With Python 3.6

pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.0-cp36-cp36m-win_amd64.whl torchvision

With Python 3.5

pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.0-cp35-cp35m-win_amd64.whl

在 Linux 上安装 PyTorch:

https://pytorch.org/

CPU Only

With Python 3.6

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp36-cp36m-linux_x86_64.whl  torchvision

With Python 3.5

pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp35-cp35m-linux_x86_64.whl torchvision

CUDA 支持

pip3 install torch  torchvision

在 OSX 上安装 PyTorch:

https://pytorch.org/

CPU Only

pip3 install torch  torchvision

MNIST in Five Minutes

import torchfusion as tf
from torchvision.datasets.mnist import MNIST
from torch.utils.data import DataLoader
from torchvision.transforms import transforms
import torch.nn as nn
from torch.optim import Adam
import torch.cuda as cuda

#Define a the classifier network
net = nn.Sequential(
           tf.Flatten(),
           nn.Linear(784, 100),
           nn.ReLU(),
           nn.Linear(100, 100),
           nn.ReLU(),
           nn.Linear(100, 100),
           nn.ReLU(),
           nn.Linear(100, 10)
)
batch_size = 64

#Transformations and data augmentation
transformations = transforms.Compose([
   transforms.Resize(28),
   transforms.ToTensor(),
   transforms.Normalize((0.5,0.5,0.5),(0.5,0.5,0.5))
])

#Load the training and test sets
train_set = MNIST(root="./data",transform=transformations,download=True)
test_set = MNIST(root="./data",train=False,transform=transformations,download=True)

train_loader = DataLoader(train_set,shuffle=True,batch_size=batch_size,num_workers=4)
test_loader = DataLoader(test_set,shuffle=False,batch_size=batch_size,num_workers=4)

#Move to GPU if available
if cuda.is_available():
   net.cuda()

#Setup the optimize and a loss function
optimizer = Adam(net.parameters(),lr=0.001)
loss_fn = nn.CrossEntropyLoss()

#Top 1 Train accuracy
train_metrics = tf.Accuracy(topK=1)

#Top 1 and Top 2 test accuracy
test_metrics_top1 = tf.Accuracy(name="Top 1 Acc ",topK=1)
test_metrics_top2 = tf.Accuracy(name="Top 2 Acc ",topK=2)

#Create an instance of the StandardModel
model = tf.StandardModel(net)

def train():
   #print a summary of the network
   print(model.summary((1,28,28)))
   model.train(train_loader, loss_fn, optimizer, [train_metrics], test_loader,
               [test_metrics_top1, test_metrics_top2], num_epochs=20,
               model_dir="mnist_mlp_saved_models",save_logs="logs.txt")


if __name__ == "__main__":
   train()

GAN in Five Minutes

import torchfusion.gan as tfgan
from torchvision.datasets import MNIST
from torchvision.transforms import transforms
from torch.optim import Adam
from torch.utils.data import DataLoader
import torch.nn as nn
import torch.cuda as cuda

#Transformations and data augmentation
train_transformations = transforms.Compose([
   transforms.Resize(28),
   transforms.ToTensor(),
   transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])

batch_size = 64

# Load the training set
train_set = MNIST(root="./data", train=True, transform=train_transformations, download=True)

train_data = DataLoader(train_set,batch_size=batch_size,shuffle=True,num_workers=4)

#Create an instance of the NormalDistribution
source = tfgan.NormalDistribution(length=len(train_set),size=(100))
source_data = DataLoader(source,batch_size=batch_size,shuffle=True,num_workers=4)

#Create an instance of the Generator and Discriminator
G = tfgan.MLPGenerator(latent_size=100,output_size=(1,28,28))
D = tfgan.MLPDiscriminator(input_size=(1,28,28))

#Move the networks to GPU if available
if cuda.is_available():
   G.cuda()
   D.cuda()

#Setup the optimizers
g_optim = Adam(G.parameters(),lr=0.0002,betas=(0.5,0.999))
d_optim = Adam(D.parameters(),lr=0.0002,betas=(0.5,0.999))

#Define the loss function
loss_fn = nn.BCELoss()

if __name__ == "__main__":
   #Create an instance of the StandardGANModel
   trainer = tfgan.StandardGANModel(G,D,gen_loss_fn=loss_fn,disc_loss_fn=loss_fn)
   #Train the two models
   trainer.train(train_data,source_data,g_optim,d_optim,num_epochs=200,disc_steps=1,save_interval=3000)


机器学习开发者应该收藏的 DIY 计算机视觉和深度学习项目

登录查看更多
0

相关内容

FPGA加速系统开发工具设计:综述与实践
专知会员服务
62+阅读 · 2020年6月24日
专知会员服务
78+阅读 · 2020年6月20日
【硬核书】可扩展机器学习:并行分布式方法
专知会员服务
80+阅读 · 2020年5月23日
Yann Lecun 纽约大学《深度学习(PyTorch)》课程(2020)PPT
专知会员服务
178+阅读 · 2020年3月16日
一网打尽!100+深度学习模型TensorFlow与Pytorch代码实现集合
【GitHub实战】Pytorch实现的小样本逼真的视频到视频转换
专知会员服务
35+阅读 · 2019年12月15日
【书籍】深度学习框架:PyTorch入门与实践(附代码)
专知会员服务
160+阅读 · 2019年10月28日
TensorFlow 2.0 学习资源汇总
专知会员服务
66+阅读 · 2019年10月9日
PyTorch 官方推荐了一份 60 分钟的深度学习指南
技术最前线
19+阅读 · 2019年10月17日
Github 项目推荐 | PyTorch 实现的 GAN 文本生成框架
AI研习社
33+阅读 · 2019年6月10日
Github项目推荐 | Pytorch TVM 扩展
AI研习社
11+阅读 · 2019年5月5日
开发 | PyTorch重大更新,0.4.0版本支持Windows系统
AI科技评论
7+阅读 · 2018年4月25日
手把手教 | 深度学习库PyTorch(附代码)
数据分析
7+阅读 · 2018年3月20日
手把手教TensorFlow(附代码)
深度学习世界
15+阅读 · 2017年10月17日
手把手教你由TensorFlow上手PyTorch(附代码)
数据派THU
5+阅读 · 2017年10月1日
教程 | 如何从TensorFlow转入PyTorch
深度学习世界
38+阅读 · 2017年9月30日
Arxiv
7+阅读 · 2018年6月8日
Arxiv
13+阅读 · 2018年4月18日
Arxiv
9+阅读 · 2018年1月4日
VIP会员
相关VIP内容
FPGA加速系统开发工具设计:综述与实践
专知会员服务
62+阅读 · 2020年6月24日
专知会员服务
78+阅读 · 2020年6月20日
【硬核书】可扩展机器学习:并行分布式方法
专知会员服务
80+阅读 · 2020年5月23日
Yann Lecun 纽约大学《深度学习(PyTorch)》课程(2020)PPT
专知会员服务
178+阅读 · 2020年3月16日
一网打尽!100+深度学习模型TensorFlow与Pytorch代码实现集合
【GitHub实战】Pytorch实现的小样本逼真的视频到视频转换
专知会员服务
35+阅读 · 2019年12月15日
【书籍】深度学习框架:PyTorch入门与实践(附代码)
专知会员服务
160+阅读 · 2019年10月28日
TensorFlow 2.0 学习资源汇总
专知会员服务
66+阅读 · 2019年10月9日
相关资讯
PyTorch 官方推荐了一份 60 分钟的深度学习指南
技术最前线
19+阅读 · 2019年10月17日
Github 项目推荐 | PyTorch 实现的 GAN 文本生成框架
AI研习社
33+阅读 · 2019年6月10日
Github项目推荐 | Pytorch TVM 扩展
AI研习社
11+阅读 · 2019年5月5日
开发 | PyTorch重大更新,0.4.0版本支持Windows系统
AI科技评论
7+阅读 · 2018年4月25日
手把手教 | 深度学习库PyTorch(附代码)
数据分析
7+阅读 · 2018年3月20日
手把手教TensorFlow(附代码)
深度学习世界
15+阅读 · 2017年10月17日
手把手教你由TensorFlow上手PyTorch(附代码)
数据派THU
5+阅读 · 2017年10月1日
教程 | 如何从TensorFlow转入PyTorch
深度学习世界
38+阅读 · 2017年9月30日
Top
微信扫码咨询专知VIP会员