使用 `torchsummary` pip 包获取模型摘要
Get Model Summary with `torchsummary` pip Package
我正在尝试对我的深度学习模型进行很好的总结,例如 Keras summary function (can be found in here)。
为此,我找到的是 torch-summary
pip 包(可以找到详细信息 here) is the best package I have found from .
我的pytorch模型是这样的-
class DeepLearningModel(Module):
# define model elements
def __init__(self, n_inputs=34):
super(DeepLearningModel, self).__init__()
# input to first hidden layer
self.hidden1 = Linear(n_inputs, 10)
kaiming_uniform_(self.hidden1.weight, nonlinearity='relu')
self.act1 = ReLU()
# second hidden layer
self.hidden2 = Linear(10, 8)
kaiming_uniform_(self.hidden2.weight, nonlinearity='relu')
self.act2 = ReLU()
# third hidden layer and output
self.hidden3 = Linear(8, 1)
xavier_uniform_(self.hidden3.weight)
self.act3 = Sigmoid()
# forward propagate input
def forward(self, X):
# input to the first hidden layer
X = self.hidden1(X)
X = self.act1(X)
# second hidden layer
X = self.hidden2(X)
X = self.act2(X)
# third hidden layer and output
X = self.hidden3(X)
X = self.act3(X)
return X
为了查看包中的模型摘要,我正在使用这个-
model_stats = summary(my_model, input_size=(1, 34, 8))
但是为此,我发现了这个错误-
Message=mat1 and mat2 shapes cannot be multiplied (68x8 and 34x10)
Source=D:\Education[=12=]. Research. Computer Science Knowledge Graph\Code\Terms Extractor\TermExtractor\BinaryClassifier\DeepLearningModel.py
StackTrace:
File "D:\Education[=12=]. Research. Computer Science Knowledge Graph\Code\Terms Extractor\TermExtractor\BinaryClassifier\DeepLearningModel.py", line 25, in forward (Current frame)
X = self.hidden1(X)
File "D:\Education[=12=]. Research. Computer Science Knowledge Graph\Code\Terms Extractor\TermExtractor\BinaryClassifier\DeepLearningClassifier.py", line 170, in printModel
model_stats = summary(self.model, (1, 34, 8))
File "D:\Education[=12=]. Research. Computer Science Knowledge Graph\Code\Terms Extractor\TermExtractor\BinaryClassifier\main-caller.py", line 11, in <module>
model.printModel()
所以,我不确定应该在 input_size
参数中输入什么值。任何人都可以帮我找到问题或找到我的模型的实际输入形状以获得摘要吗?
Linear
期望输入最后一个轴上的通道数为 in_features
.
model_stats = summary(my_model, input_size=(1, 8, 34))
我正在尝试对我的深度学习模型进行很好的总结,例如 Keras summary function (can be found in here)。
为此,我找到的是 torch-summary
pip 包(可以找到详细信息 here) is the best package I have found from
我的pytorch模型是这样的-
class DeepLearningModel(Module):
# define model elements
def __init__(self, n_inputs=34):
super(DeepLearningModel, self).__init__()
# input to first hidden layer
self.hidden1 = Linear(n_inputs, 10)
kaiming_uniform_(self.hidden1.weight, nonlinearity='relu')
self.act1 = ReLU()
# second hidden layer
self.hidden2 = Linear(10, 8)
kaiming_uniform_(self.hidden2.weight, nonlinearity='relu')
self.act2 = ReLU()
# third hidden layer and output
self.hidden3 = Linear(8, 1)
xavier_uniform_(self.hidden3.weight)
self.act3 = Sigmoid()
# forward propagate input
def forward(self, X):
# input to the first hidden layer
X = self.hidden1(X)
X = self.act1(X)
# second hidden layer
X = self.hidden2(X)
X = self.act2(X)
# third hidden layer and output
X = self.hidden3(X)
X = self.act3(X)
return X
为了查看包中的模型摘要,我正在使用这个-
model_stats = summary(my_model, input_size=(1, 34, 8))
但是为此,我发现了这个错误-
Message=mat1 and mat2 shapes cannot be multiplied (68x8 and 34x10)
Source=D:\Education[=12=]. Research. Computer Science Knowledge Graph\Code\Terms Extractor\TermExtractor\BinaryClassifier\DeepLearningModel.py
StackTrace:
File "D:\Education[=12=]. Research. Computer Science Knowledge Graph\Code\Terms Extractor\TermExtractor\BinaryClassifier\DeepLearningModel.py", line 25, in forward (Current frame)
X = self.hidden1(X)
File "D:\Education[=12=]. Research. Computer Science Knowledge Graph\Code\Terms Extractor\TermExtractor\BinaryClassifier\DeepLearningClassifier.py", line 170, in printModel
model_stats = summary(self.model, (1, 34, 8))
File "D:\Education[=12=]. Research. Computer Science Knowledge Graph\Code\Terms Extractor\TermExtractor\BinaryClassifier\main-caller.py", line 11, in <module>
model.printModel()
所以,我不确定应该在 input_size
参数中输入什么值。任何人都可以帮我找到问题或找到我的模型的实际输入形状以获得摘要吗?
Linear
期望输入最后一个轴上的通道数为 in_features
.
model_stats = summary(my_model, input_size=(1, 8, 34))