I am trying to get a good summary of my deep learning model like Keras summary function (can be found in here).
For that, what I have found is torch-summary
pip package (details can be found here) is the best package I have found from this question.
My pytorch model is like this-
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
And to view the model's summary with the package, I am using this-
model_stats = summary(my_model, input_size=(1, 34, 8))
But for that, I am finding this error-
Message=mat1 and mat2 shapes cannot be multiplied (68x8 and 34x10)
Source=D:\Education\0. Research\1. Computer Science Knowledge Graph\Code\Terms Extractor\TermExtractor\BinaryClassifier\DeepLearningModel.py
StackTrace:
File "D:\Education\0. Research\1. Computer Science Knowledge Graph\Code\Terms Extractor\TermExtractor\BinaryClassifier\DeepLearningModel.py", line 25, in forward (Current frame)
X = self.hidden1(X)
File "D:\Education\0. Research\1. 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\0. Research\1. Computer Science Knowledge Graph\Code\Terms Extractor\TermExtractor\BinaryClassifier\main-caller.py", line 11, in <module>
model.printModel()
So, I am not sure what values should I put in the input_size
parameter. Can anyone please help me find the issue or find my actual input shape for the model for getting a summary?