前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Github 项目推荐 | 基于 PyTorch,面向 AI 系统加速研究与开发的深度学习框架

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

作者头像
AI研习社
发布2018-07-26 15:23:38
6480
发布2018-07-26 15:23:38
举报
文章被收录于专栏:AI研习社

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

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

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

Github 链接:

https://github.com/johnolafenwa/TorchFusion

独特功能

  • 高度可扩展
  • 高度详细的汇总功能,不仅为您提供了有关参数,层数,输入和输出大小的详细信息,还为网络中的每个线性和卷积层提供了Flops(Multiply-Adds)的数量。 现在,只需一个功能就可以知道任何CNN架构的确切计算成本!
  • 实时指标和损失可视化,并可选择永久保存它们
  • 支持永久保存日志
  • 易于使用的回调

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

安装

安装 TorchFusion

代码语言:javascript
复制
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

代码语言:javascript
复制
pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp36-cp36m-win_amd64.whl torchvision

With Python 3.5

代码语言:javascript
复制
pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp35-cp35m-win_amd64.whl torchvision

CUDA 支持

With Python 3.6

代码语言:javascript
复制
pip3 install http://download.pytorch.org/whl/cu80/torch-0.4.0-cp36-cp36m-win_amd64.whl torchvision

With Python 3.5

代码语言:javascript
复制
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

代码语言:javascript
复制
pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp36-cp36m-linux_x86_64.whl  torchvision

With Python 3.5

代码语言:javascript
复制
pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp35-cp35m-linux_x86_64.whl torchvision

CUDA 支持

代码语言:javascript
复制
pip3 install torch  torchvision

在 OSX 上安装 PyTorch:

https://pytorch.org/

CPU Only

代码语言:javascript
复制
pip3 install torch  torchvision

MNIST in Five Minutes

代码语言:javascript
复制
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

代码语言:javascript
复制
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)
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2018-06-13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 AI研习社 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 独特功能
  • 安装
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档