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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jacke121/article/details/82356585

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

pip3installhttp://download.pytorch.org/whl/cpu/torch-0.4.0-cp36-cp36m-win_amd64.whl torchvision

With Python 3.5

pip3installhttp://download.pytorch.org/whl/cpu/torch-0.4.0-cp35-cp35m-win_amd64.whl torchvision

CUDA 支持

With Python 3.6

pip3installhttp://download.pytorch.org/whl/cu80/torch-0.4.0-cp36-cp36m-win_amd64.whl torchvision

With Python 3.5

pip3installhttp://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

pip3installhttp://download.pytorch.org/whl/cpu/torch-0.4.0-cp36-cp36m-linux_x86_64.whl  torchvision

With Python 3.5

pip3installhttp://download.pytorch.org/whl/cpu/torch-0.4.0-cp35-cp35m-linux_x86_64.whl torchvision

CUDA 支持

pip3installtorch  torchvision

在 OSX 上安装 PyTorch:

https://pytorch.org/

CPU Only

pip3installtorch  torchvision

MNIST in Five Minutes

importtorchfusionastf

fromtorchvision.datasets.mnistimportMNIST

fromtorch.utils.dataimportDataLoader

fromtorchvision.transformsimporttransforms

importtorch.nnasnn

fromtorch.optimimportAdam

importtorch.cudaascuda

#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

ifcuda.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)

deftrain():

   #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

importtorchfusion.ganastfgan

fromtorchvision.datasetsimportMNIST

fromtorchvision.transformsimporttransforms

fromtorch.optimimportAdam

fromtorch.utils.dataimportDataLoader

importtorch.nnasnn

importtorch.cudaascuda

#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

ifcuda.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,sa

猜你喜欢

转载自blog.csdn.net/jacke121/article/details/82356585