From 7703823f99d92813ce15517af39cf0f59273073e Mon Sep 17 00:00:00 2001 From: Alessandro Pappalardo Date: Tue, 11 Aug 2020 16:28:56 +0100 Subject: [PATCH] Examples (mobilenetv1): update to r2 w/ 4b first layer Signed-off-by: Alessandro Pappalardo --- README.md | 2 +- brevitas_examples/imagenet_classification/README.md | 2 +- .../cfg/quant_mobilenet_v1_4b.ini | 3 ++- .../imagenet_classification/models/mobilenetv1.py | 9 +++++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 44a959f5f..37613f2a1 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ Below a list of relevant pretrained models available, currently for evaluation o | Name | Scaling Type | First layer weights | Weights | Activations | Avg pool | Top1 | Top5 | Pretrained model | Retrained from | |--------------|----------------------------|---------------------|---------|-------------|----------|-------|-------|-------------------------------------------------------------------------------------------------|---------------------------------------------------------------| -| MobileNet V1 | Floating-point per channel | 8 bit | 4 bit | 4 bit | 4 bit | 71.14 | 90.10 | [Download](https://github.com/Xilinx/brevitas/releases/download/quant_mobilenet_v1_4b-r1/quant_mobilenet_v1_4b-0100a667.pth) | [link](https://github.com/osmr/imgclsmob/tree/master/pytorch) | +| MobileNet V1 | Floating-point per channel | 4 bit | 4 bit | 4 bit | 4 bit | 70.36 | 89.61 | [Download](https://github.com/Xilinx/brevitas/releases/download/quant_mobilenet_v1_4b-r2/quant_mobilenet_v1_4b-e75a094f.pth) | [link](https://github.com/osmr/imgclsmob/tree/master/pytorch) | | ProxylessNAS Mobile14 w/ Hadamard classifier | Floating-point per channel | 8 bit | 4 bit | 4 bit | 4 bit | 73.52 | 91.46 | [Download](https://github.com/Xilinx/brevitas/releases/download/quant_proxylessnas_mobile14_hadamard_4b-r0/quant_proxylessnas_mobile14_hadamard_4b-4acbfa9f.pth) | [link](https://github.com/osmr/imgclsmob/tree/master/pytorch) | | ProxylessNAS Mobile14 | Floating-point per channel | 8 bit | 4 bit | 4 bit | 4 bit | 74.42 | 92.04 | [Download](https://github.com/Xilinx/brevitas/releases/download/quant_proxylessnas_mobile14_4b-r0/quant_proxylessnas_mobile14_4b-e10882e1.pth) | [link](https://github.com/osmr/imgclsmob/tree/master/pytorch) | | ProxylessNAS Mobile14 | Floating-point per channel | 8 bit | 4 bit, 5 bit | 4 bit, 5 bit | 4 bit | 75.01 | 92.33 | [Download](https://github.com/Xilinx/brevitas/releases/download/quant_proxylessnas_mobile14_4b5b-r0/quant_proxylessnas_mobile14_4b5b-2bdf7f8d.pth) | [link](https://github.com/osmr/imgclsmob/tree/master/pytorch) | diff --git a/brevitas_examples/imagenet_classification/README.md b/brevitas_examples/imagenet_classification/README.md index a63367265..39bda6a2a 100644 --- a/brevitas_examples/imagenet_classification/README.md +++ b/brevitas_examples/imagenet_classification/README.md @@ -7,7 +7,7 @@ Below in the table is a list of example pretrained models made available for ref | Name | Cfg | Scaling Type | First layer weights | Weights | Activations | Avg pool | Top1 | Top5 | Pretrained model | Retrained from | |--------------|-----------------------|----------------------------|---------------------|---------|-------------|----------|-------|-------|-------------------------------------------------------------------------------------------------|---------------------------------------------------------------| -| MobileNet V1 | quant_mobilenet_v1_4b | Floating-point per channel | 8 bit | 4 bit | 4 bit | 4 bit | 71.14 | 90.10 | [Download](https://github.com/Xilinx/brevitas/releases/download/quant_mobilenet_v1_4b-r1/quant_mobilenet_v1_4b-0100a667.pth) | [link](https://github.com/osmr/imgclsmob/tree/master/pytorch) | +| MobileNet V1 | quant_mobilenet_v1_4b | Floating-point per channel | 4 bit | 4 bit | 4 bit | 4 bit | 70.36 | 89.61 | [Download](https://github.com/Xilinx/brevitas/releases/download/quant_mobilenet_v1_4b-r2/quant_mobilenet_v1_4b-e75a094f.pth) | [link](https://github.com/osmr/imgclsmob/tree/master/pytorch) | | ProxylessNAS Mobile14 w/ Hadamard classifier | quant_proxylessnas_mobile14_hadamard_4b | Floating-point per channel | 8 bit | 4 bit | 4 bit | 4 bit | 73.52 | 91.46 | [Download](https://github.com/Xilinx/brevitas/releases/download/quant_proxylessnas_mobile14_hadamard_4b-r0/quant_proxylessnas_mobile14_hadamard_4b-4acbfa9f.pth) | [link](https://github.com/osmr/imgclsmob/tree/master/pytorch) | | ProxylessNAS Mobile14 | quant_proxylessnas_mobile14_4b | Floating-point per channel | 8 bit | 4 bit | 4 bit | 4 bit | 74.42 | 92.04 | [Download](https://github.com/Xilinx/brevitas/releases/download/quant_proxylessnas_mobile14_4b-r0/quant_proxylessnas_mobile14_4b-e10882e1.pth) | [link](https://github.com/osmr/imgclsmob/tree/master/pytorch) | | ProxylessNAS Mobile14 | quant_proxylessnas_mobile14_4b5b | Floating-point per channel | 8 bit | 4 bit, 5 bit | 4 bit, 5 bit | 4 bit | 75.01 | 92.33 | [Download](https://github.com/Xilinx/brevitas/releases/download/quant_proxylessnas_mobile14_4b5b-r0/quant_proxylessnas_mobile14_4b5b-2bdf7f8d.pth) | [link](https://github.com/osmr/imgclsmob/tree/master/pytorch) | diff --git a/brevitas_examples/imagenet_classification/cfg/quant_mobilenet_v1_4b.ini b/brevitas_examples/imagenet_classification/cfg/quant_mobilenet_v1_4b.ini index 449dd2bda..b8b197924 100644 --- a/brevitas_examples/imagenet_classification/cfg/quant_mobilenet_v1_4b.ini +++ b/brevitas_examples/imagenet_classification/cfg/quant_mobilenet_v1_4b.ini @@ -1,10 +1,11 @@ [MODEL] ARCH: quant_mobilenet_v1 WIDTH_SCALE: 1.0 -PRETRAINED_URL: https://github.com/Xilinx/brevitas/releases/download/quant_mobilenet_v1_4b-r1/quant_mobilenet_v1_4b-0100a667.pth +PRETRAINED_URL: https://github.com/Xilinx/brevitas/releases/download/quant_mobilenet_v1_4b-r2/quant_mobilenet_v1_4b-e75a094f.pth [QUANT] BIT_WIDTH: 4 +FIRST_LAYER_BIT_WIDTH: 4 [PREPROCESS] MEAN_0: 0.485 diff --git a/brevitas_examples/imagenet_classification/models/mobilenetv1.py b/brevitas_examples/imagenet_classification/models/mobilenetv1.py index 3f189ee8a..2386dc52e 100644 --- a/brevitas_examples/imagenet_classification/models/mobilenetv1.py +++ b/brevitas_examples/imagenet_classification/models/mobilenetv1.py @@ -36,8 +36,6 @@ from .common import * -FIRST_LAYER_BIT_WIDTH = 8 - class DwsConvBlock(nn.Module): def __init__(self, @@ -109,6 +107,7 @@ class MobileNet(nn.Module): def __init__(self, channels, first_stage_stride, + first_layer_bit_width, bit_width, in_channels=3, num_classes=1000): @@ -120,7 +119,7 @@ def __init__(self, out_channels=init_block_channels, kernel_size=3, stride=2, - weight_bit_width=FIRST_LAYER_BIT_WIDTH, + weight_bit_width=first_layer_bit_width, activation_scaling_per_channel=True, act_bit_width=bit_width) self.features.add_module('init_block', init_block) @@ -162,13 +161,15 @@ def quant_mobilenet_v1(cfg): first_stage_stride = False width_scale = float(cfg.get('MODEL', 'WIDTH_SCALE')) bit_width = cfg.getint('QUANT', 'BIT_WIDTH') + first_layer_bit_width = cfg.getint('QUANT', 'FIRST_LAYER_BIT_WIDTH') if width_scale != 1.0: channels = [[int(cij * width_scale) for cij in ci] for ci in channels] net = MobileNet(channels=channels, first_stage_stride=first_stage_stride, - bit_width=bit_width) + bit_width=bit_width, + first_layer_bit_width=first_layer_bit_width) return net