What is the PyTorch alternative for Keras input_shape, output_shape, get_weights, get_config and summary
In Keras, after creating a model, we can see its input and output shapes using model.input_shape, model.output_shape. For weights and config  we can use model.get_weights() and model.get_config(), respectively.

What are the similar alternatives for PyTorch? Also is there any other functions we need to know for inspecting a PyTorch model?

To get the summary in PyTorch, we print model print(model) but this gives lesser information than model.summary(). Is there a better summary for PyTorch? 

There is no "model.summary()" method in pytorch. You need to use built_in methods and fields of the model. 

For example, I have customized inception_v3 model. To get the information I need to use other many different fields. For instance: 

IN:

print(model) # print network architecture


OUT    

Inception3(
  (Conv2d_1a_3x3): BasicConv2d(
    (conv): Conv2d(3, 32, kernel_size=(3, 3), stride=(2, 2), bias=False)
    (bn): BatchNorm2d(32, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
  )
  (Conv2d_2a_3x3): BasicConv2d(
    (conv): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), bias=False)
    (bn): BatchNorm2d(32, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
  )
  (Conv2d_2b_3x3): BasicConv2d(
    (conv): Conv2d(32, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
    (bn): BatchNorm2d(64, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
  )
  (Conv2d_3b_1x1): BasicConv2d(
    (conv): Conv2d(64, 80, kernel_size=(1, 1), stride=(1, 1), bias=False)
    (bn): BatchNorm2d(80, eps=0.001, momentum=0.1, affine=True, track_running_stats=True)
  )
  (Conv2d_4a_3x3): BasicConv2d(
    (conv): Conv2d(80, 192, kernel_size=(3, 3), stride=(1, 1), bias=False)
   ...


IN:

for i in model.state_dict().keys():
    print(i) 
#print keys of dict with values of learned weights, bias, parameters


OUT:  

    Conv2d_1a_3x3.conv.weight
    Conv2d_1a_3x3.bn.weight
    Conv2d_1a_3x3.bn.bias
    Conv2d_1a_3x3.bn.running_mean
    Conv2d_1a_3x3.bn.running_var
    Conv2d_1a_3x3.bn.num_batches_tracked
    Conv2d_2a_3x3.conv.weight
    Conv2d_2a_3x3.bn.weight
    Conv2d_2a_3x3.bn.bias
    Conv2d_2a_3x3.bn.running_mean 
    ...


So if I would like to get weights for the layer CNN at Conv2d_1a_3x3, I look for the key "Conv2d_1a_3x3.conv.weight":

print("model.save_dict()["Conv2d_1a_3x3.conv.weight"])


OUT:    

tensor([[[[-0.2103, -0.3441, -0.0344],
          [-0.1420, -0.2520, -0.0280],
          [ 0.0736,  0.0183,  0.0381]],

         [[ 0.1417,  0.1593,  0.0506],
          [ 0.0828,  0.0854,  0.0186],
          [ 0.0283,  0.0144,  0.0508]],
...


If you want to see used hyperparameters from optimizer:

optimizer.param_groups


OUT:

[{'dampening': 0,
  'lr': 0.01,
  'momentum': 0.01,
  'nesterov': False,
  'params': [Parameter containing:
   tensor([[[[-0.2103, -0.3441, -0.0344],
             [-0.1420, -0.2520, -0.0280],
             [ 0.0736,  0.0183,  0.0381]],
          ...

