torch-summary / tensorboard 无法使用

问题

torch-summary的无效输出

==========================================================================================
Layer (type:depth-idx)                   Output Shape              Param #
==========================================================================================
└─Generator: 0-1                         [-1, 3, 256, 256]         --
==========================================================================================
Total params: 0
Trainable params: 0
Non-trainable params: 0
Total mult-adds (M): 0.00
==========================================================================================
Input size (MB): 0.00
Forward/backward pass size (MB): 0.00
Params size (MB): 0.00
Estimated Total Size (MB): 0.00
=========================================================================================

tensorboard 报错

Cannot insert a Tensor that requires grad as a constant. Consider making it a parameter or input, or detaching the gradient

原因

参考 博客
构建模型时,不应使用的是python原生 list ,而应使用 nn.ModuleList
构建完后使用 self.layers = nn.ModuleList(self.layers) 将原生 list 转换为 nn.ModuleList 即可。


效果

====================================================================================================
Layer (type:depth-idx)                             Output Shape              Param #
====================================================================================================
├─ModuleList: 1                                    []                        --
|    └─Sequential: 2-1                             [-1, 512, 4, 4]           --
|    |    └─ParametrizedConvTranspose2d: 3-1       [-1, 512, 4, 4]           819,712
|    |    └─BatchNorm2d: 3-2                       [-1, 512, 4, 4]           1,024
|    |    └─ReLU: 3-3                              [-1, 512, 4, 4]           --
|    └─Sequential: 2-2                             [-1, 256, 8, 8]           --
|    |    └─ParametrizedConvTranspose2d: 3-4       [-1, 256, 8, 8]           2,097,408
|    |    └─BatchNorm2d: 3-5                       [-1, 256, 8, 8]           512
|    |    └─ReLU: 3-6                              [-1, 256, 8, 8]           --
|    └─Sequential: 2-3                             [-1, 128, 16, 16]         --
|    |    └─ParametrizedConvTranspose2d: 3-7       [-1, 128, 16, 16]         524,416
|    |    └─BatchNorm2d: 3-8                       [-1, 128, 16, 16]         256
|    |    └─ReLU: 3-9                              [-1, 128, 16, 16]         --
|    └─Sequential: 2-4                             [-1, 64, 32, 32]          --
|    |    └─ParametrizedConvTranspose2d: 3-10      [-1, 64, 32, 32]          131,136
|    |    └─BatchNorm2d: 3-11                      [-1, 64, 32, 32]          128
|    |    └─ReLU: 3-12                             [-1, 64, 32, 32]          --
|    └─Sequential: 2-5                             [-1, 32, 64, 64]          --
|    |    └─ParametrizedConvTranspose2d: 3-13      [-1, 32, 64, 64]          32,800
|    |    └─BatchNorm2d: 3-14                      [-1, 32, 64, 64]          64
|    |    └─ReLU: 3-15                             [-1, 32, 64, 64]          --
|    |    └─Self_Attn: 3-16                        [-1, 32, 64, 64]          1,321
|    └─Sequential: 2-6                             [-1, 16, 128, 128]        --
|    |    └─ParametrizedConvTranspose2d: 3-17      [-1, 16, 128, 128]        8,208
|    |    └─BatchNorm2d: 3-18                      [-1, 16, 128, 128]        32
|    |    └─ReLU: 3-19                             [-1, 16, 128, 128]        --
|    |    └─Self_Attn: 3-20                        [-1, 16, 128, 128]        341
|    └─Sequential: 2-7                             [-1, 3, 256, 256]         --
|    |    └─ParametrizedConvTranspose2d: 3-21      [-1, 3, 256, 256]         771
|    |    └─Tanh: 3-22                             [-1, 3, 256, 256]         --
====================================================================================================
Total params: 3,618,129
Trainable params: 3,618,129
Non-trainable params: 0
Total mult-adds (M): 17.72
====================================================================================================
Input size (MB): 0.00
Forward/backward pass size (MB): 7.69
Params size (MB): 13.80
Estimated Total Size (MB): 21.49
====================================================================================================

tensorboard也不再报错

D:\anaconda\envs\pytorch\python.exe C:\Users\23896\Desktop\bev-lane-det_dachaung-master\tools\train_openlane.py Traceback (most recent call last): File "C:\Users\23896\Desktop\bev-lane-det_dachaung-master\tools\train_openlane.py", line 18, in <module> from torch.utils.tensorboard import SummaryWriter File "D:\anaconda\envs\pytorch\lib\site-packages\torch\utils\tensorboard\__init__.py", line 13, in <module> from .writer import FileWriter, SummaryWriter # noqa: F401 File "D:\anaconda\envs\pytorch\lib\site-packages\torch\utils\tensorboard\writer.py", line 9, in <module> from tensorboard.compat.proto.event_pb2 import SessionLog File "D:\anaconda\envs\pytorch\lib\site-packages\tensorboard\compat\proto\event_pb2.py", line 17, in <module> from tensorboard.compat.proto import summary_pb2 as tensorboard_dot_compat_dot_proto_dot_summary__pb2 File "D:\anaconda\envs\pytorch\lib\site-packages\tensorboard\compat\proto\summary_pb2.py", line 17, in <module> from tensorboard.compat.proto import tensor_pb2 as tensorboard_dot_compat_dot_proto_dot_tensor__pb2 File "D:\anaconda\envs\pytorch\lib\site-packages\tensorboard\compat\proto\tensor_pb2.py", line 16, in <module> from tensorboard.compat.proto import resource_handle_pb2 as tensorboard_dot_compat_dot_proto_dot_resource__handle__pb2 File "D:\anaconda\envs\pytorch\lib\site-packages\tensorboard\compat\proto\resource_handle_pb2.py", line 16, in <module> from tensorboard.compat.proto import tensor_shape_pb2 as tensorboard_dot_compat_dot_proto_dot_tensor__shape__pb2 File "D:\anaconda\envs\pytorch\lib\site-packages\tensorboard\compat\proto\tensor_shape_pb2.py", line 36, in <module> _descriptor.FieldDescriptor( File "D:\anaconda\envs\pytorch\lib\site-packages\google\protobuf\descriptor.py", line 561, in __new__ _message.Message._CheckCalledFromGeneratedFile() TypeError: Descriptors cannot not be created directly. If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0. If you cannot immediately regenerate your protos, some other possible workarounds are: 1. Downgrade the protobuf package to 3.20.x or lower. 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

什鲤子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值