Project-MONAI / MONAI

AI Toolkit for Healthcare Imaging
https://monai.io/
Apache License 2.0
5.82k stars 1.07k forks source link

Add support to print out network summary #2586

Closed Nic-Ma closed 3 years ago

Nic-Ma commented 3 years ago

Is your feature request related to a problem? Please describe. A feature request from Clara users: it is useful to print out the network architecture for this we need to: pip install torchsummary summary( trainer.network.cuda(), ) Help on function summary in module torchsummary.torchsummary:

summary(model, input_size, batch_size=-1, device='cuda')

----------------------------------------------------------------
        Layer (type)               Output Shape         Param #
================================================================
            Conv2d-1           [32, 64, 55, 55]          23,296
              ReLU-2           [32, 64, 55, 55]               0
         MaxPool2d-3           [32, 64, 27, 27]               0
            Conv2d-4          [32, 192, 27, 27]         307,392
              ReLU-5          [32, 192, 27, 27]               0
         MaxPool2d-6          [32, 192, 13, 13]               0
            Conv2d-7          [32, 384, 13, 13]         663,936
              ReLU-8          [32, 384, 13, 13]               0
            Conv2d-9          [32, 256, 13, 13]         884,992
             ReLU-10          [32, 256, 13, 13]               0
           Conv2d-11          [32, 256, 13, 13]         590,080
             ReLU-12          [32, 256, 13, 13]               0
        MaxPool2d-13            [32, 256, 6, 6]               0
AdaptiveAvgPool2d-14            [32, 256, 6, 6]               0
          Dropout-15                 [32, 9216]               0
           Linear-16                 [32, 4096]      37,752,832
             ReLU-17                 [32, 4096]               0
          Dropout-18                 [32, 4096]               0
           Linear-19                 [32, 4096]      16,781,312
             ReLU-20                 [32, 4096]               0
           Linear-21                 [32, 1000]       4,097,000
================================================================
Total params: 61,100,840
Trainable params: 61,100,840
Non-trainable params: 0
----------------------------------------------------------------
Input size (MB): 18.38

CC @IsaacYangSLA

Nic-Ma commented 3 years ago

I will try to develop the utility API and a ignite handler for this feature request.

Thanks.

rijobro commented 3 years ago

Great idea, this would be a good addition.

Nic-Ma commented 3 years ago

Hi @rijobro @wyli @ericspod ,

Seems no need to develop a handler for this feature, users can call the TorchInfo directly? Close this ticket.

Thanks.