跳转到主要内容

实用函数,用于打印模型的摘要。

项目描述

torch-inspect

https://travis-ci.cn/jettify/pytorch-inspect.svg?branch=master https://codecov.io/gh/jettify/pytorch-inspect/branch/master/graph/badge.svg https://img.shields.io/pypi/pyversions/torch-inspect.svg https://img.shields.io/pypi/v/torch-inspect.svg

torch-inspect – PyTorch(PyTorch)的低级神经网络信息检查的实用函数集合

特性

  • 提供助手函数 summary,用于打印Keras风格的模型摘要。

  • 提供助手函数 inspect,用于返回包含网络摘要信息的对象,以便程序访问。

  • RNN/LSTM支持。

  • 库有测试和合理的代码覆盖率。

简单示例

import torch.nn as nn
import torch.nn.functional as F
import torch_inspect as ti

class SimpleNet(nn.Module):
    def __init__(self):
        super(SimpleNet, self).__init__()
        self.conv1 = nn.Conv2d(1, 6, 3)
        self.conv2 = nn.Conv2d(6, 16, 3)
        self.fc1 = nn.Linear(16 * 6 * 6, 120)
        self.fc2 = nn.Linear(120, 84)
        self.fc3 = nn.Linear(84, 10)

    def forward(self, x):
        x = F.max_pool2d(F.relu(self.conv1(x)), (2, 2))
        x = F.max_pool2d(F.relu(self.conv2(x)), 2)
        x = x.view(-1, self.num_flat_features(x))
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return x

    def num_flat_features(self, x):
        size = x.size()[1:]
        num_features = 1
        for s in size:
            num_features *= s
        return num_features


  net = SimpleNet()
  ti.summary(net, (1, 32, 32))

将产生以下输出

----------------------------------------------------------------
        Layer (type)               Output Shape         Param #
================================================================
            Conv2d-1           [100, 6, 30, 30]              60
            Conv2d-2          [100, 16, 13, 13]             880
            Linear-3                 [100, 120]          69,240
            Linear-4                  [100, 84]          10,164
            Linear-5                  [100, 10]             850
================================================================
Total params: 81,194
Trainable params: 81,194
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 0.39
Forward/backward pass size (MB): 6.35
Params size (MB): 0.31
Estimated Total Size (MB): 7.05
----------------------------------------------------------------

要程序化访问网络信息,存在 inspect 函数

info = ti.inspect(net, (1, 32, 32))
print(info)
[LayerInfo(name='Conv2d-1', input_shape=[100, 1, 32, 32], output_shape=[100, 6, 30, 30], trainable_params=60, non_trainable_params=0),
 LayerInfo(name='Conv2d-2', input_shape=[100, 6, 15, 15], output_shape=[100, 16, 13, 13], trainable_params=880, non_trainable_params=0),
 LayerInfo(name='Linear-3', input_shape=[100, 576], output_shape=[100, 120], trainable_params=69240, non_trainable_params=0),
 LayerInfo(name='Linear-4', input_shape=[100, 120], output_shape=[100, 84], trainable_params=10164, non_trainable_params=0),
 LayerInfo(name='Linear-5', input_shape=[100, 84], output_shape=[100, 10], trainable_params=850, non_trainable_params=0)]

安装

安装过程简单,只需

$ pip install torch-inspect

要求

参考和感谢

此包基于 pytorch-summary 和 PyTorch 问题 。与 pytorch-summary 相比,pytorch-inspect 支持RNN/LSTMs,并提供对网络摘要信息的程序访问。由于其更模块化的结构和测试的存在,它更容易扩展并支持更多功能。

变更

0.0.3 (2019-09-22)

  • 添加LSTM支持

  • 修复了多输入/输出支持

  • 添加了更多的网络测试用例

  • 批量大小不再默认为-1

0.0.2 (2019-09-22)

  • 增加了批归一化支持

  • 移除了设备参数

0.0.1 (2019-09-1)

  • 初始版本。

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

torch-inspect-0.0.3.tar.gz (14.5 kB 查看哈希值)

上传时间

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面