AI Logic

Architectures

SqueezeNet

Updated:

SqueezeNet architecture. Left: the overall flow (conv1, three max-pooling layers, Fire 2–9, dropout, the 1Γ—1 convolution conv10, global average pooling, softmax) with the output shape of each layer. Right: inside a Fire module (the squeeze layer reduces to 16 channels with a 1Γ—1 convolution, the expand layer splits into 1Γ—1 and 3Γ—3 convolutions, and their outputs are concatenated)

Background and Overview

SqueezeNet is a small convolutional neural network that reaches roughly the accuracy of AlexNet with 50x fewer parameters. It was published in 2016 by Iandola et al. at UC Berkeley and Stanford University. It is built by stacking "Fire modules", which first squeeze the number of input channels with 1Γ—1 convolutions and then expand them again.

Until then, CNN research had focused mainly on raising accuracy. The paper points out, however, that at equal accuracy a model with fewer parameters has three advantages.

  • Faster distributed training: When training across multiple servers, the amount of data exchanged between servers is proportional to the number of parameters, so smaller models need less communication.
  • Easier deployment: Updating a model over the air, for example in self-driving cars, requires sending 240MB for AlexNet. A small model can be updated frequently.
  • Easier to fit on small hardware such as FPGAs: Many FPGAs have less than 10MB of on-chip memory. If the model fits there, the latency of reading from off-chip memory disappears.

The paper's main results are as follows.

  • On ImageNet, it matched the accuracy of AlexNet (about 60 million parameters, 240MB), reaching 57.5% top-1 and 80.3% top-5, with about 1.25 million parameters (4.8MB).
  • Applying the model compression method Deep Compression (pruning and quantization) shrank it further to 0.47MB without losing accuracy, 510x smaller than AlexNet.

The name comes from the fact that the squeeze layer of each Fire module has only 1/8 as many channels as the expand layer (a low squeeze ratio).

Theory: Three Design Strategies and the Fire Module

SqueezeNet is designed around three strategies for reducing parameters while preserving as much accuracy as possible (Section 3.1 of the paper).

  1. Replace 3Γ—3 filters with 1Γ—1 filters: A 1Γ—1 filter has 9x fewer parameters than a 3Γ—3 filter. Most filters are made 1Γ—1.
  2. Reduce the number of input channels to 3Γ—3 filters: The parameter count of a 3Γ—3 convolutional layer is (number of input channels) Γ— (number of filters) Γ— (3Γ—3). Not only the number of filters but also the number of input channels is reduced.
  3. Downsample late in the network: Moving layers with stride 2 or more toward the end lets many layers operate on large feature maps. The idea is that, other things being equal, larger feature maps lead to higher accuracy.

Strategies 1 and 2 reduce parameters, while strategy 3 maximizes accuracy under a limited parameter budget.

The Fire module

The Fire module puts strategies 1 and 2 into practice (right side of the figure at the top of the article).

  1. Squeeze layer: A 1Γ—1 convolution (s1Γ—1s_{1\times1} filters) reduces the number of input channels.
  2. Expand layer: A 1Γ—1 convolution (e1Γ—1e_{1\times1} filters) and a 3Γ—3 convolution (e3Γ—3e_{3\times3} filters) are applied in parallel to the squeezed output. The 3Γ—3 branch is zero-padded by one pixel (padding) so that its spatial size matches the 1Γ—1 branch.
  3. Concatenation: The two outputs are concatenated along the channel dimension, giving e1Γ—1+e3Γ—3e_{1\times1} + e_{3\times3} output channels.

A ReLU follows both the squeeze layer and the expand layer. Setting s1Γ—1<e1Γ—1+e3Γ—3s_{1\times1} < e_{1\times1} + e_{3\times3} keeps the number of channels entering the 3Γ—3 convolution small (strategy 2).

How many parameters are saved

Fire 2 squeezes a 96-channel input to s1Γ—1=16s_{1\times1} = 16 and outputs 128 channels with e1Γ—1=e3Γ—3=64e_{1\times1} = e_{3\times3} = 64. The number of weights (including biases) is:

96β‹…16+16⏟squeeze+16β‹…64+64⏟expandΒ 1Γ—1+3β‹…3β‹…16β‹…64+64⏟expandΒ 3Γ—3=11,920\underbrace{96 \cdot 16 + 16}_{\text{squeeze}} + \underbrace{16 \cdot 64 + 64}_{\text{expand } 1\times1} + \underbrace{3 \cdot 3 \cdot 16 \cdot 64 + 64}_{\text{expand } 3\times3} = 11{,}920

A standard 3Γ—3 convolution mapping the same 96 channels to 128 channels has 3β‹…3β‹…96β‹…128+128=110,7203 \cdot 3 \cdot 96 \cdot 128 + 128 = 110{,}720 parameters, so the Fire module uses about 1/9 as many. The savings come from cutting the channels entering the 3Γ—3 convolution from 96 to 16 (strategy 2) and from making half of the outputs 1Γ—1 (strategy 1).

Reducing dimensions with a 1Γ—1 convolution before applying a 3Γ—3 convolution is also used in Network In Network and GoogLeNet (Inception). SqueezeNet is distinctive in focusing this idea squarely on reducing parameters and in studying the ratio between the squeeze and expand layers as a design metric.

Overall Architecture and Training Setup

SqueezeNet consists of one convolutional layer (conv1), eight Fire modules (fire2–9), and a final convolutional layer (conv10) (Table 1 and Figure 2 of the paper; left side of the figure at the top of the article). Later Fire modules have more filters.

LayerOutput sizeSettingsParameters
conv1111Γ—111Γ—967Γ—7, stride 2, 96 filters14,208
maxpool155Γ—55Γ—963Γ—3, stride 20
fire255Γ—55Γ—128s1Γ—1s_{1\times1} 16, e1Γ—1e_{1\times1} 64, e3Γ—3e_{3\times3} 6411,920
fire355Γ—55Γ—12816, 64, 6412,432
fire455Γ—55Γ—25632, 128, 12845,344
maxpool427Γ—27Γ—2563Γ—3, stride 20
fire527Γ—27Γ—25632, 128, 12849,440
fire627Γ—27Γ—38448, 192, 192104,880
fire727Γ—27Γ—38448, 192, 192111,024
fire827Γ—27Γ—51264, 256, 256188,992
maxpool813Γ—13Γ—5123Γ—3, stride 20
fire913Γ—13Γ—51264, 256, 256197,184
conv1013Γ—13Γ—10001Γ—1, 1000 filters513,000
avgpool101Γ—1Γ—100013Γ—13 average0
Total1,248,424

Max pooling is placed only after conv1, fire4, and fire8, delaying downsampling (strategy 3). The other settings are as follows (Section 3.3.1 of the paper).

  • No fully connected layers: Following Network In Network, the 1Γ—1 convolution in conv10 produces one channel per class (1000), and global average pooling turns each into a per-class score. Since fully connected layers accounted for most of AlexNet's parameters, this alone cuts the count substantially.
  • Dropout: Dropout with a rate of 50% is applied after fire9.
  • Learning rate: It starts at 0.04 and decreases linearly during training (equivalent to polynomial decay with power 1). The mini-batch size, initialization, and other details are in the published Caffe configuration files.
  • Implementing the expand layer: Caffe at the time could not mix 1Γ—1 and 3Γ—3 filters in one layer, so the computation is split into two convolutional layers whose outputs are concatenated. This is numerically identical to computing them in a single layer.

Why Accuracy Holds Up with Few Parameters

The paper trains SqueezeNet-like models while varying the design knobs and studies how model size relates to accuracy (Sections 5–6).

How the knobs are set

Each Fire module has three numbers (s1Γ—1s_{1\times1}, e1Γ—1e_{1\times1}, e3Γ—3e_{3\times3}), giving 24 for eight modules. The paper defines the following metaparameters that determine them together.

  • baseebase_e: the number of expand filters in the first Fire module (128 in SqueezeNet)
  • increincr_e and freqfreq: every freqfreq Fire modules, the number of expand filters increases by increincr_e (128 and 2 in SqueezeNet)
  • pct3Γ—3pct_{3\times3}: the fraction of 3Γ—3 filters in the expand layer (0.5 in SqueezeNet)
  • SRSR (squeeze ratio): the ratio of the number of squeeze filters to the number of expand filters (0.125 in SqueezeNet)

The number of expand filters in the ii-th Fire module is ei=basee+increβ‹…βŒŠi/freqβŒ‹e_i = base_e + incr_e \cdot \lfloor i / freq \rfloor, and the number of squeeze filters is si,1Γ—1=SRβ‹…eis_{i,1\times1} = SR \cdot e_i.

Raising the squeeze ratio (Figure 3(a))

Raising SRSR from 0.125 increased ImageNet top-5 accuracy from 80.3% (4.8MB) to 86.0% (19MB). Accuracy plateaued at SR=0.75SR = 0.75, and SR=1.0SR = 1.0 only made the model larger. SqueezeNet can be seen as the smallest point that reaches AlexNet's accuracy.

Varying the fraction of 3Γ—3 filters (Figure 3(b), SR=0.5SR = 0.5)

Varying the fraction of 3Γ—3 filters from 1% to 99%, top-5 accuracy plateaued at 85.6% with 50% 3Γ—3 filters; adding more 3Γ—3 filters only made the model larger. Not every filter needs to be 3Γ—3, and half of them can be 1Γ—1 (supporting strategy 1).

Adding connections that skip layers (Table 3)

Following ResNet, adding connections that bypass Fire modules improved accuracy.

Architecturetop-1top-5Model size
SqueezeNet57.5%80.3%4.8MB
+ Simple bypass (identity around fire3, 5, 7, 9)60.4%82.5%4.8MB
+ Complex bypass (1Γ—1 convolution bypasses around the rest as well)58.8%82.0%7.7MB

The paper reasons that squeezing channels to 1/8 in the squeeze layer limits how much information can pass, so the bypass provides a route around the squeeze layer. The simple bypass, which adds no parameters, did better than the complex one.

As an everyday analogy, a Fire module is like a meeting that summarizes before discussing. Instead of debating everyone's long reports (many channels) as they are, the group first condenses them into a short summary (the squeeze layer), then splits into people who look at details (3Γ—3) and people who look at the whole (1Γ—1) to give their views. Making the summary too short loses information, but keeping the original report on the table (the bypass) makes up for it.

Experimental Results

Comparison with model compression methods (ImageNet; Table 2 of the paper)

The paper compares against prior work that compressed AlexNet. Model size is the number of bytes needed to store all trained parameters.

ModelCompression methodData typeModel sizeReduction vs. AlexNettop-1top-5
AlexNetNone (baseline)32-bit240MB1x57.2%80.3%
AlexNetSingular value decomposition (SVD)32-bit48MB1/556.0%79.4%
AlexNetPruning32-bit27MB1/957.2%80.3%
AlexNetDeep Compression5–8-bit6.9MB1/3557.2%80.3%
SqueezeNetNone32-bit4.8MB1/5057.5%80.3%
SqueezeNetDeep Compression8-bit0.66MB1/36357.5%80.3%
SqueezeNetDeep Compression6-bit0.47MB1/51057.5%80.3%

The table shows the following.

  • Architecture alone beats compression: Even uncompressed 32-bit SqueezeNet is 1.4x smaller than the previously smallest result, AlexNet with Deep Compression (6.9MB), with equal or better accuracy.
  • Small models can be compressed further: Against the concern that an already small model needs all its parameters and cannot be compressed, applying Deep Compression to SqueezeNet (pruning to keep 33% of weights plus 6-bit or 8-bit quantization) did not reduce accuracy.
  • Architecture plus compression gives 510x: The SqueezeNet architecture gives 1/50, and Deep Compression a further ~1/10, for a total of 1/510 of AlexNet.

Improvements after publication (Section 7 of the paper)

According to the paper, after publication Han et al. used Dense-Sparse-Dense (DSD), which uses compression as a regularizer during training, to raise ImageNet accuracy by 1.2 points for compressed SqueezeNet and by 4.3 points for uncompressed SqueezeNet. Gschwend also implemented a SqueezeNet-like model on an FPGA and stored all parameters in the FPGA's on-chip memory.

Practical Considerations

Keep the following points in mind when using SqueezeNet.

  • It is small in parameters, not in computation: What the paper reduced is model size (number of parameters); it does not compare computational cost. As strategy 3 prescribes, many Fire modules run on large 55Γ—55 or 27Γ—27 feature maps, so computation is not necessarily low. torchvision also includes SqueezeNet 1.1 (an official release), an improved version with 2.4x less computation.
  • Quantization does not automatically mean speedups: Deep Compression stores weights as indices into a "codebook" (a table of representative values). The paper notes that achieving the 4x speedup for 8-bit or 5.3x for 6-bit directly in this format on ordinary processors is not straightforward. Dedicated hardware (EIE) or linear 8-bit quantization (Ristretto) is used instead.
  • Accuracy is at AlexNet level: SqueezeNet's goal is AlexNet-level accuracy, and it falls short of later, larger models. When accuracy is insufficient, the paper tries raising the squeeze ratio (which makes the model larger) or adding simple bypasses.

Lowering the squeeze ratio too far limits the information that can pass through the squeeze layer and reduces accuracy. In the paper's experiments, accuracy rose as the ratio increased from 0.125 (top-5 from 80.3% to 86.0%) and plateaued at 0.75. When building your own Fire modules, do not make the squeeze layer's channel count extremely small.

Comparison with Other Models

Comparing SqueezeNet with other ways of reducing parameters on the same terms gives the following.

MethodWhat it doesParameters (ImageNet)Accuracy (top-1)Constraints and costs
AlexNet (baseline)A CNN with large fully connected layers~60M (240MB)57.2%Large
AlexNet + Deep CompressionPrunes and quantizes a trained modelEquivalent to 6.9MB57.2%Requires a compression pipeline; speed depends on implementation
SqueezeNetMakes the architecture itself small (Fire modules, no fully connected layers)~1.25M (4.8MB)57.5%Computation is not necessarily low
SqueezeNet + Deep CompressionCompresses the small architecture furtherEquivalent to 0.47MB57.5%Same as above
MobileNetReduces both parameters and computation with depthwise separable convolutionsβ€”β€”Not compared in the SqueezeNet paper

The difference between compressing AlexNet and SqueezeNet is whether you build a large model and then trim it, or start with a small architecture. The paper showed that the two are not in conflict, and combining them makes models even smaller.

Network In Network and GoogLeNet also use 1Γ—1 convolutions and global average pooling, but their goals are accuracy and computational efficiency, and they do not focus on parameter count as narrowly as SqueezeNet does.

Rough guidelines for choosing:

  • Storage or transmission size is tightly constrained (FPGAs, over-the-air updates, etc.): SqueezeNet combined with Deep Compression is a candidate.
  • Fast inference on smartphones and similar devices: Measure and compare models designed to reduce computation as well, such as MobileNet, on the actual device.
  • Accuracy higher than AlexNet is required: Add bypasses to SqueezeNet, or consider newer lightweight models.

PyTorch example

Show code
python
import torch
import torch.nn as nn
from torchvision.models import squeezenet1_0, SqueezeNet1_0_Weights

"""
1. Build a Fire module as in Figure 1 and Section 3.2 of the paper
2. Use torchvision's pretrained SqueezeNet 1.0 (the architecture in Table 1 of the paper)
"""


class Fire(nn.Module):
  def __init__(self, in_ch, s1x1, e1x1, e3x3):
    super().__init__()
    self.squeeze = nn.Sequential(nn.Conv2d(in_ch, s1x1, 1), nn.ReLU(inplace=True))          # squeeze channels with 1Γ—1
    self.expand1x1 = nn.Sequential(nn.Conv2d(s1x1, e1x1, 1), nn.ReLU(inplace=True))
    self.expand3x3 = nn.Sequential(nn.Conv2d(s1x1, e3x3, 3, padding=1), nn.ReLU(inplace=True))   # padding 1 keeps the spatial size

  def forward(self, x):
    x = self.squeeze(x)
    return torch.cat([self.expand1x1(x), self.expand3x3(x)], dim=1)   # concatenate along channels: e1x1 + e3x3 channels


fire2 = Fire(96, 16, 64, 64)
print(sum(p.numel() for p in fire2.parameters()))   # 11920 (matches fire2 in Table 1 of the paper)
print(fire2(torch.randn(1, 96, 55, 55)).shape)      # [1, 128, 55, 55]

# A standard 3Γ—3 convolution for comparison (96 β†’ 128 channels)
print(sum(p.numel() for p in nn.Conv2d(96, 128, 3, padding=1).parameters()))   # 110720 (about 9x)

# --- torchvision's pretrained SqueezeNet 1.0 ---
weights = SqueezeNet1_0_Weights.IMAGENET1K_V1
model = squeezenet1_0(weights=weights)              # no fully connected layers; classifier is Dropout β†’ conv10 (1Γ—1) β†’ ReLU β†’ global average pooling
print(sum(p.numel() for p in model.parameters()))   # about 1.25 million
model.eval()                                        # disable dropout (after fire9, 50%)
with torch.no_grad():
  logits = model(torch.randn(1, 3, 224, 224))       # [1, 1000]

FAQ

Q. Why is SqueezeNet so much smaller than AlexNet?
A.

Mainly because of three design choices. First, it removes the fully connected layers that held most of the parameters and produces class scores with a 1Γ—1 convolution and global average pooling. Second, the squeeze layer of each Fire module reduces the number of channels entering the 3Γ—3 convolution (96 β†’ 16 in Fire 2). Third, half of the expand filters are 1Γ—1, which need only 1/9 the parameters of 3Γ—3 filters. Together these cut the parameter count from about 60 million to about 1.25 million (about 1/50).

Q. Is SqueezeNet also fast to compute?
A.

What the paper reduced is the number of parameters (model size); it does not report computational cost. Because the design delays downsampling and runs many layers on large feature maps, computation is not necessarily low. torchvision also includes SqueezeNet 1.1, an officially released improved version that needs 2.4x less computation than 1.0. When speed matters, measure on the actual device before choosing.

Q. What do the squeeze and expand layers of a Fire module do?
A.

The squeeze layer is a 1Γ—1 convolution that reduces the number of input channels. The expand layer applies parallel 1Γ—1 and 3Γ—3 convolutions to the squeezed features and concatenates their outputs along the channel dimension, widening the channels again. Because the parameters of a 3Γ—3 convolution grow in proportion to its input channels, squeezing first cuts parameters substantially. In SqueezeNet, the squeeze layer has 1/8 as many filters as the expand layer in total.

References

  1. Iandola, F. N., Han, S., Moskewicz, M. W., Ashraf, K., Dally, W. J., & Keutzer, K. (2016). SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and <0.5MB model size. arXiv:1602.07360.
  2. Han, S., Mao, H., & Dally, W. J. (2016). Deep Compression: Compressing Deep Neural Networks with Pruning, Trained Quantization and Huffman Coding. ICLR 2016. arXiv:1510.00149.
  3. Official release (Caffe configuration files and pretrained models, SqueezeNet 1.1): forresti/SqueezeNet.
  4. PyTorch. torchvision/models/squeezenet.py (source code).