hiddenlayer可视化工具--没有显示尺寸大小

参考网址:https://blog.csdn.net/qq_38159643/article/details/122043108

1.问题:可视化网络没有显示尺寸的大小

import torch
import hiddenlayer as h
from torchvision.models import alexnet  # 以 alexnet 为例

myNet = alexnet()  # 实例化 alexnet
x = torch.randn(1, 3, 224, 224)  # 随机生成一个输入
myNetGraph = h.build_graph(myNet, x)  # 建立网络模型图
# myNetGraph.theme = h.graph.THEMES['blue']  # blue 和 basic 两种颜色,可以不要
myNetGraph.save(path='./demoModel.png', format='png')  # 保存网络模型图,可以设置 png 和 pdf 等

 2.解决方案:修改底层源码

找到 pytorch_builder.py 文件,修改 get_shape(torch_node) 函数如下:

def get_shape(torch_node):
    """Return the output shape of the given Pytorch node."""
    # Extract node output shape from the node string representation
    # This is a hack because there doesn't seem to be an official way to do it.
    # See my quesiton in the PyTorch forum:
    # https://discuss.pytorch.org/t/node-output-shape-from-trace-graph/24351/2
    # TODO: find a better way to extract output shape
    # TODO: Assuming the node has one output. Update if we encounter a multi-output node.
    shape = torch_node.output().type().sizes()
    return shape

 3.处理后的结果:

4.安装hiddenlayer库

方法一、通过命令行cmd,然后输入pip install hiddenlayer(我已经安装过,所以下面显示已经安装)

 方法二、进入官网,进行下载源码,运行py文件实现

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值