pytorch檢視網路引數視訊記憶體佔用量等

2021-10-11 19:06:06 字數 814 閱讀 4707

1.使用torchstat

pip install torchstat

from torchstat import stat

import torchvision.models as models

model = models.resnet152()

stat(model, (3, 224, 224))

關於stat函式的引數,第乙個應該是模型,第二個則是輸入尺寸,3為通道數。我沒有調研該函式的詳細引數,也不知道為什麼使用的時候並不提示相應的引數。

2.使用torchsummary

pip install torchsummary

from torchsummary import summary

summary(model.cuda(),input_size=(3,32,32),batch_size=-1)

使用該函式直接對引數進行提示,可以發現直接有顯式輸入batch_size的地方,我自己的感覺好像該函式更好一些。但是!!!不知道為什麼,該函式在我的機器上一直報錯!!!typeerror: can't convert cuda tensor to numpy. use tensor.cpu() to copy the tensor to host memory first.

update:經過論壇諮詢,報錯的原因找到了,只需要把

pip install torchsummary
修改為

pip install torch-summary

檢視模型各層引數(Pytorch

這個實驗用到的資料集是mnist資料集,維度是1 28 28 import torch.nn as nn class cnn nn.module def init self super cnn,self init 卷積層 self.conv1 nn.sequential in channels 1,...

Linux如何檢視視訊記憶體

以下內容由參看資料總結而來,若有不對,望指出 用ctrl alt t開啟終端,輸入命令 lspci,得到如下 部分 00 1f.6 signal processing controller intel corporation 5 series 3400 series chipset thermal ...

PyTorch上限制GPU視訊記憶體的函式

pytorch版本 1.8.0 torch.cuda.set per process memory fraction 0.5,0 引數1 fraction 限制的上限比例,如0.5 就是總gpu視訊記憶體的一半,可以是0 1的任意float大小 引數2 device 裝置號 如0 表示gpu卡 0號...