python pytorch库_PyTorch便捷工具库

Inferno

Inferno is a little library providing utilities and convenience functions/classes around PyTorch. It's a work-in-progress, but the releases from v0.4 on should be fairly stable!

Free software: Apache Software License 2.0

Features

Current features include:

a basic Trainer class to encapsulate the training boilerplate (iteration/epoch loops, validation and checkpoint creation),

a graph API for building models with complex architectures, powered by networkx.

a submodule for torch.nn.Module-level parameter initialization,

a submodule for data preprocessing / transforms,

a callback API to enable flexible interaction with the trainer,

a submodule for volumetric datasets, and more!

import torch.nn as nn

from inferno.io.box.cifar import get_cifar10_loaders

from inferno.trainers.basic import Trainer

from inferno.trainers.callbacks.logging.tensorboard import TensorboardLogger

from inferno.extensions.layers.convolutional import ConvELU2D

from inferno.extensions.layers.reshape import Flatten

# Fill these in:

LOG_DIRECTORY = '...'

SAVE_DIRECTORY = '...'

DATASET_DIRECTORY = '...'

DOWNLOAD_CIFAR = True

USE_CUDA = True

# Build torch model

model = nn.Sequential(

ConvELU2D(in_channels=3, out_channels=256, kernel_size=3),

nn.MaxPool2d(kernel_size=2, stride=2),

ConvELU2D(in_channels=256, out_channels=256, kernel_size=3),

nn.MaxPool2d(kernel_size=2, stride=2),

ConvELU2D(in_channels=256, out_channels=256, kernel_size=3),

nn.MaxPool2d(kernel_size=2, stride=2),

Flatten(),

nn.Linear(in_features=(256 * 4 * 4), out_features=10),

nn.LogSoftmax(dim=1)

)

# Load loaders

train_loader, validate_loader = get_cifar10_loaders(DATASET_DIRECTORY,

download=DOWNLOAD_CIFAR)

# Build trainer

trainer = Trainer(model) \

.build_criterion('NLLLoss') \

.build_metric('CategoricalError') \

.build_optimizer('Adam') \

.validate_every((2, 'epochs')) \

.save_every((5, 'epochs')) \

.save_to_directory(SAVE_DIRECTORY) \

.set_max_num_epochs(10) \

.build_logger(TensorboardLogger(log_scalars_every=(1, 'iteration'),

log_images_every='never'),

log_directory=LOG_DIRECTORY)

# Bind loaders

trainer \

.bind_loader('train', train_loader) \

.bind_loader('validate', validate_loader)

if USE_CUDA:

trainer.cuda()

# Go!

trainer.fit()

To visualize the training progress, navigate to LOG_DIRECTORY and fire up tensorboard with

$ tensorboard --logdir=${PWD} --port=6007

and navigate to localhost:6007 with your browser.

Installation

Conda packages for python >= 3.6 for all distributions are availaible on conda-forge:

$ conda install -c pytorch -c conda-forge inferno

Future Features:

Planned features include:

a class to encapsulate Hogwild! training over multiple GPUs,

minimal shape inference with a dry-run,

proper packaging and documentation,

cutting-edge fresh-off-the-press implementations of what the future has in store. :)

Credits

This package was partially generated with Cookiecutter and the audreyr/cookiecutter-pypackage project template + lots of work by Thorsten.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Python3.8是Python编程语言的一种版本,它于2019年10月发布。这个版本主要引入了许多新特性和改进,使得Python更加强大和易用。Python3.8带来了许多语法和语义的更改,并集成了新的和模块。 PyTorch是一个深度学习框架,它提供了丰富的工具来进行机器学习和人工智能相关的任务。它是由Facebook开发并于2017年开源发布。PyTorch提供了简单而灵活的API,使得构建和训练神经网络变得更加容易。 Python3.8和PyTorch可以很好地结合使用。Python作为PyTorch的支持语言,Python3.8版本的新特性可以使得使用PyTorch进行深度学习任务更加高效和便捷。例如,Python3.8引入的Walrus操作符(:=)可以简化代码的编写和读取,在处理数据时能够更加灵活地操作和处理。 另外,Python3.8对于并行处理和多线程编程提供了更好的支持,这对于在PyTorch中处理大规模的数据集和训练复杂模型非常重要。Python3.8的新特性使得开发者可以更好地利用并行计算的能力,提高运行效率和性能。 此外,Python3.8还为类型注释和类型检查提供了更强的支持,这对于构建可维护和可扩展的PyTorch代码非常重要。通过类型注释,开发者能够更好地理解代码的意图,并减少潜在的错误,提高代码的可读性和可维护性。 综上所述,Python3.8和PyTorch是一对很好的组合,Python3.8的新特性和改进使得使用PyTorch进行深度学习任务更加高效、便捷和可维护。它们的结合为开发者提供了更强大的工具,可以更好地构建和训练神经网络模型。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值