How to quantize yolov3 model?

Midhilesh: <p>I am working on using yolov3 for end application. Since YOLOv3 is very huge I thought of using dynamic quantization. I have loaded the pre-trained weight and the model looks like below. Please help me with this problem.</p>
<p>Darknet(<br>
(module_list): ModuleList(<br>
(0): Sequential(<br>
(conv_0): Conv2d(3, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_0): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_0): LeakyReLU(negative_slope=0.1)<br>
)<br>
(1): Sequential(<br>
(conv_1): Conv2d(32, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)<br>
(batch_norm_1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_1): LeakyReLU(negative_slope=0.1)<br>
)<br>
(2): Sequential(<br>
(conv_2): Conv2d(64, 32, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_2): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_2): LeakyReLU(negative_slope=0.1)<br>
)<br>
(3): Sequential(<br>
(conv_3): Conv2d(32, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_3): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_3): LeakyReLU(negative_slope=0.1)<br>
)<br>
(4): Sequential(<br>
(shortcut_4): EmptyLayer()<br>
)<br>
(5): Sequential(<br>
(conv_5): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)<br>
(batch_norm_5): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_5): LeakyReLU(negative_slope=0.1)<br>
)<br>
(6): Sequential(<br>
(conv_6): Conv2d(128, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_6): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_6): LeakyReLU(negative_slope=0.1)<br>
)<br>
(7): Sequential(<br>
(conv_7): Conv2d(64, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_7): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_7): LeakyReLU(negative_slope=0.1)<br>
)<br>
(8): Sequential(<br>
(shortcut_8): EmptyLayer()<br>
)<br>
(9): Sequential(<br>
(conv_9): Conv2d(128, 64, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_9): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_9): LeakyReLU(negative_slope=0.1)<br>
)<br>
(10): Sequential(<br>
(conv_10): Conv2d(64, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_10): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_10): LeakyReLU(negative_slope=0.1)<br>
)<br>
(11): Sequential(<br>
(shortcut_11): EmptyLayer()<br>
)<br>
(12): Sequential(<br>
(conv_12): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)<br>
(batch_norm_12): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_12): LeakyReLU(negative_slope=0.1)<br>
)<br>
(13): Sequential(<br>
(conv_13): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_13): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_13): LeakyReLU(negative_slope=0.1)<br>
)<br>
(14): Sequential(<br>
(conv_14): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_14): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_14): LeakyReLU(negative_slope=0.1)<br>
)<br>
(15): Sequential(<br>
(shortcut_15): EmptyLayer()<br>
)<br>
(16): Sequential(<br>
(conv_16): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_16): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_16): LeakyReLU(negative_slope=0.1)<br>
)<br>
(17): Sequential(<br>
(conv_17): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_17): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_17): LeakyReLU(negative_slope=0.1)<br>
)<br>
(18): Sequential(<br>
(shortcut_18): EmptyLayer()<br>
)<br>
(19): Sequential(<br>
(conv_19): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_19): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_19): LeakyReLU(negative_slope=0.1)<br>
)<br>
(20): Sequential(<br>
(conv_20): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_20): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_20): LeakyReLU(negative_slope=0.1)<br>
)<br>
(21): Sequential(<br>
(shortcut_21): EmptyLayer()<br>
)<br>
(22): Sequential(<br>
(conv_22): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_22): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_22): LeakyReLU(negative_slope=0.1)<br>
)<br>
(23): Sequential(<br>
(conv_23): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_23): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_23): LeakyReLU(negative_slope=0.1)<br>
)<br>
(24): Sequential(<br>
(shortcut_24): EmptyLayer()<br>
)<br>
(25): Sequential(<br>
(conv_25): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_25): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_25): LeakyReLU(negative_slope=0.1)<br>
)<br>
(26): Sequential(<br>
(conv_26): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_26): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_26): LeakyReLU(negative_slope=0.1)<br>
)<br>
(27): Sequential(<br>
(shortcut_27): EmptyLayer()<br>
)<br>
(28): Sequential(<br>
(conv_28): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_28): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_28): LeakyReLU(negative_slope=0.1)<br>
)<br>
(29): Sequential(<br>
(conv_29): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_29): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_29): LeakyReLU(negative_slope=0.1)<br>
)<br>
(30): Sequential(<br>
(shortcut_30): EmptyLayer()<br>
)<br>
(31): Sequential(<br>
(conv_31): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_31): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_31): LeakyReLU(negative_slope=0.1)<br>
)<br>
(32): Sequential(<br>
(conv_32): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_32): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_32): LeakyReLU(negative_slope=0.1)<br>
)<br>
(33): Sequential(<br>
(shortcut_33): EmptyLayer()<br>
)<br>
(34): Sequential(<br>
(conv_34): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_34): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_34): LeakyReLU(negative_slope=0.1)<br>
)<br>
(35): Sequential(<br>
(conv_35): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_35): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_35): LeakyReLU(negative_slope=0.1)<br>
)<br>
(36): Sequential(<br>
(shortcut_36): EmptyLayer()<br>
)<br>
(37): Sequential(<br>
(conv_37): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)<br>
(batch_norm_37): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_37): LeakyReLU(negative_slope=0.1)<br>
)<br>
(38): Sequential(<br>
(conv_38): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_38): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_38): LeakyReLU(negative_slope=0.1)<br>
)<br>
(39): Sequential(<br>
(conv_39): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_39): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_39): LeakyReLU(negative_slope=0.1)<br>
)<br>
(40): Sequential(<br>
(shortcut_40): EmptyLayer()<br>
)<br>
(41): Sequential(<br>
(conv_41): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_41): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_41): LeakyReLU(negative_slope=0.1)<br>
)<br>
(42): Sequential(<br>
(conv_42): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_42): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_42): LeakyReLU(negative_slope=0.1)<br>
)<br>
(43): Sequential(<br>
(shortcut_43): EmptyLayer()<br>
)<br>
(44): Sequential(<br>
(conv_44): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_44): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_44): LeakyReLU(negative_slope=0.1)<br>
)<br>
(45): Sequential(<br>
(conv_45): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_45): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_45): LeakyReLU(negative_slope=0.1)<br>
)<br>
(46): Sequential(<br>
(shortcut_46): EmptyLayer()<br>
)<br>
(47): Sequential(<br>
(conv_47): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_47): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_47): LeakyReLU(negative_slope=0.1)<br>
)<br>
(48): Sequential(<br>
(conv_48): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_48): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_48): LeakyReLU(negative_slope=0.1)<br>
)<br>
(49): Sequential(<br>
(shortcut_49): EmptyLayer()<br>
)<br>
(50): Sequential(<br>
(conv_50): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_50): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_50): LeakyReLU(negative_slope=0.1)<br>
)<br>
(51): Sequential(<br>
(conv_51): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_51): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_51): LeakyReLU(negative_slope=0.1)<br>
)<br>
(52): Sequential(<br>
(shortcut_52): EmptyLayer()<br>
)<br>
(53): Sequential(<br>
(conv_53): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_53): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_53): LeakyReLU(negative_slope=0.1)<br>
)<br>
(54): Sequential(<br>
(conv_54): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_54): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_54): LeakyReLU(negative_slope=0.1)<br>
)<br>
(55): Sequential(<br>
(shortcut_55): EmptyLayer()<br>
)<br>
(56): Sequential(<br>
(conv_56): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_56): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_56): LeakyReLU(negative_slope=0.1)<br>
)<br>
(57): Sequential(<br>
(conv_57): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_57): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_57): LeakyReLU(negative_slope=0.1)<br>
)<br>
(58): Sequential(<br>
(shortcut_58): EmptyLayer()<br>
)<br>
(59): Sequential(<br>
(conv_59): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_59): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_59): LeakyReLU(negative_slope=0.1)<br>
)<br>
(60): Sequential(<br>
(conv_60): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_60): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_60): LeakyReLU(negative_slope=0.1)<br>
)<br>
(61): Sequential(<br>
(shortcut_61): EmptyLayer()<br>
)<br>
(62): Sequential(<br>
(conv_62): Conv2d(512, 1024, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False)<br>
(batch_norm_62): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_62): LeakyReLU(negative_slope=0.1)<br>
)<br>
(63): Sequential(<br>
(conv_63): Conv2d(1024, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_63): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_63): LeakyReLU(negative_slope=0.1)<br>
)<br>
(64): Sequential(<br>
(conv_64): Conv2d(512, 1024, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_64): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_64): LeakyReLU(negative_slope=0.1)<br>
)<br>
(65): Sequential(<br>
(shortcut_65): EmptyLayer()<br>
)<br>
(66): Sequential(<br>
(conv_66): Conv2d(1024, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_66): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_66): LeakyReLU(negative_slope=0.1)<br>
)<br>
(67): Sequential(<br>
(conv_67): Conv2d(512, 1024, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_67): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_67): LeakyReLU(negative_slope=0.1)<br>
)<br>
(68): Sequential(<br>
(shortcut_68): EmptyLayer()<br>
)<br>
(69): Sequential(<br>
(conv_69): Conv2d(1024, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_69): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_69): LeakyReLU(negative_slope=0.1)<br>
)<br>
(70): Sequential(<br>
(conv_70): Conv2d(512, 1024, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_70): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_70): LeakyReLU(negative_slope=0.1)<br>
)<br>
(71): Sequential(<br>
(shortcut_71): EmptyLayer()<br>
)<br>
(72): Sequential(<br>
(conv_72): Conv2d(1024, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_72): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_72): LeakyReLU(negative_slope=0.1)<br>
)<br>
(73): Sequential(<br>
(conv_73): Conv2d(512, 1024, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_73): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_73): LeakyReLU(negative_slope=0.1)<br>
)<br>
(74): Sequential(<br>
(shortcut_74): EmptyLayer()<br>
)<br>
(75): Sequential(<br>
(conv_75): Conv2d(1024, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_75): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_75): LeakyReLU(negative_slope=0.1)<br>
)<br>
(76): Sequential(<br>
(conv_76): Conv2d(512, 1024, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_76): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_76): LeakyReLU(negative_slope=0.1)<br>
)<br>
(77): Sequential(<br>
(conv_77): Conv2d(1024, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_77): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_77): LeakyReLU(negative_slope=0.1)<br>
)<br>
(78): Sequential(<br>
(conv_78): Conv2d(512, 1024, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_78): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_78): LeakyReLU(negative_slope=0.1)<br>
)<br>
(79): Sequential(<br>
(conv_79): Conv2d(1024, 512, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_79): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_79): LeakyReLU(negative_slope=0.1)<br>
)<br>
(80): Sequential(<br>
(conv_80): Conv2d(512, 1024, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_80): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_80): LeakyReLU(negative_slope=0.1)<br>
)<br>
(81): Sequential(<br>
(conv_81): Conv2d(1024, 255, kernel_size=(1, 1), stride=(1, 1))<br>
)<br>
(82): Sequential(<br>
(yolo_82): YOLOLayer(<br>
(mse_loss): MSELoss()<br>
(bce_loss): BCELoss()<br>
(ce_loss): CrossEntropyLoss()<br>
)<br>
)<br>
(83): Sequential(<br>
(route_83): EmptyLayer()<br>
)<br>
(84): Sequential(<br>
(conv_84): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_84): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_84): LeakyReLU(negative_slope=0.1)<br>
)<br>
(85): Sequential(<br>
(upsample_85): Upsample(scale_factor=2.0, mode=nearest)<br>
)<br>
(86): Sequential(<br>
(route_86): EmptyLayer()<br>
)<br>
(87): Sequential(<br>
(conv_87): Conv2d(768, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_87): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_87): LeakyReLU(negative_slope=0.1)<br>
)<br>
(88): Sequential(<br>
(conv_88): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_88): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_88): LeakyReLU(negative_slope=0.1)<br>
)<br>
(89): Sequential(<br>
(conv_89): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_89): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_89): LeakyReLU(negative_slope=0.1)<br>
)<br>
(90): Sequential(<br>
(conv_90): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_90): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_90): LeakyReLU(negative_slope=0.1)<br>
)<br>
(91): Sequential(<br>
(conv_91): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_91): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_91): LeakyReLU(negative_slope=0.1)<br>
)<br>
(92): Sequential(<br>
(conv_92): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_92): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_92): LeakyReLU(negative_slope=0.1)<br>
)<br>
(93): Sequential(<br>
(conv_93): Conv2d(512, 255, kernel_size=(1, 1), stride=(1, 1))<br>
)<br>
(94): Sequential(<br>
(yolo_94): YOLOLayer(<br>
(mse_loss): MSELoss()<br>
(bce_loss): BCELoss()<br>
(ce_loss): CrossEntropyLoss()<br>
)<br>
)<br>
(95): Sequential(<br>
(route_95): EmptyLayer()<br>
)<br>
(96): Sequential(<br>
(conv_96): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_96): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_96): LeakyReLU(negative_slope=0.1)<br>
)<br>
(97): Sequential(<br>
(upsample_97): Upsample(scale_factor=2.0, mode=nearest)<br>
)<br>
(98): Sequential(<br>
(route_98): EmptyLayer()<br>
)<br>
(99): Sequential(<br>
(conv_99): Conv2d(384, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_99): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_99): LeakyReLU(negative_slope=0.1)<br>
)<br>
(100): Sequential(<br>
(conv_100): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_100): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_100): LeakyReLU(negative_slope=0.1)<br>
)<br>
(101): Sequential(<br>
(conv_101): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_101): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_101): LeakyReLU(negative_slope=0.1)<br>
)<br>
(102): Sequential(<br>
(conv_102): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_102): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_102): LeakyReLU(negative_slope=0.1)<br>
)<br>
(103): Sequential(<br>
(conv_103): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False)<br>
(batch_norm_103): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_103): LeakyReLU(negative_slope=0.1)<br>
)<br>
(104): Sequential(<br>
(conv_104): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)<br>
(batch_norm_104): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)<br>
(leaky_104): LeakyReLU(negative_slope=0.1)<br>
)<br>
(105): Sequential(<br>
(conv_105): Conv2d(256, 255, kernel_size=(1, 1), stride=(1, 1))<br>
)<br>
(106): Sequential(<br>
(yolo_106): YOLOLayer(<br>
(mse_loss): MSELoss()<br>
(bce_loss): BCELoss()<br>
(ce_loss): CrossEntropyLoss()<br>
)<br>
)<br>
)<br>
)</p>

ptrblck: <p>Have a look at <a href="https://pytorch.org/tutorials/advanced/dynamic_quantization_tutorial.html">this experimental tutorial</a>.</p>

Midhilesh: <p>I have seen this tutorial. There they have mentioned nn.LSTM, nn.Linear layers for quantization. But in my model, all the deep learning layers are present inside modulelist. How can I mention that all the layers need to be quantized?.</p>

baheytharwat: <p>Hi <a class="mention" href="/u/ptrblck">@ptrblck</a>,<br>
I have a similar issue to quantize yolov3 model. I am working on this implementation: <a href="https://github.com/eriklindernoren/PyTorch-YOLOv3" rel="nofollow noopener">https://github.com/eriklindernoren/PyTorch-YOLOv3</a><br>
I followed the dynamic quantization tutorial and modified the inference code to become :<br>
“”"<br>
model = Darknet(opt.model_def, img_size=opt.img_size).to(device)</p>
<pre><code>if opt.weights_path.endswith(".weights"):
    # Load darknet weights
    model.load_darknet_weights(opt.weights_path)
else:
    # Load checkpoint weights
    model.load_state_dict(torch.load(opt.weights_path))

qmodel = torch.quantization.quantize_dynamic(model, dtype=torch.qint8)
</code></pre>
<p>“”"</p>
<p>But I got this error message:<br>
“For purely script modules use my_script_module.save() instead.”)<br>
_pickle.PickleError: ScriptModules cannot be deepcopied using copy.deepcopy or saved using torch.save. Mixed serialization of script and non-script modules is not supported. For purely script modules use my_script_module.save() instead.</p>
<p>Do you have any suggestions?</p>

ptrblck: <p>I don’t know, why this error is raised, but I would recommend to create a new topic with this post under the Quantization category, so that it gets a bit more visibility.</p>