---
title: cv_bnext-small_image-classification_ImageNet-labels
canonical_url: "https://www.modelscope.cn/models/damo/cv_bnext-small_image-classification_ImageNet-labels"
md_url: "https://www.modelscope.cn/models/damo/cv_bnext-small_image-classification_ImageNet-labels.md"
repository: damo/cv_bnext-small_image-classification_ImageNet-labels
chinese_name: "BNext二值化图像分类-英文-通用-small"
last_updated: 2023-02-03
license: "Apache License 2.0"
pipeline_tag: image-classification
tasks:
  - image-classification
library_name:
  - pytorch
frameworks:
  - pytorch
domain:
  - cv
downloads: 9804
stars: 2
tags:
  - Alibaba
  - "Image classification"
  - "Binary Neural Network"
  - Quantization
  - "Fixed Point"
---

# cv_bnext-small_image-classification_ImageNet-labels

> cv_bnext-small_image-classification_ImageNet-labels - damo 在 ModelScope 开源的模型。本模型适用于部署在二值加速的硬件上，支持ImageNet 1000类物体识别，也可作为下游任务的预训练backbone

damo/cv_bnext-small_image-classification_ImageNet-labels 是 ModelScope 魔搭社区上的image-classification模型，采用 Apache License 2.0 许可。

- **Repository**: damo/cv_bnext-small_image-classification_ImageNet-labels
- **License**: Apache License 2.0
- **Tasks**: image-classification
- **Tags**: Alibaba, Image classification, Binary Neural Network, Quantization, Fixed Point
- **Downloads**: 9804
- **Stars**: 2
- **Last updated**: 2023-02-03

Source: https://www.modelscope.cn/models/damo/cv_bnext-small_image-classification_ImageNet-labels

---

# 二值化网络介绍
神经网络二值化是模型量化的极限情况，将神经网络中原本 32 位浮点数参数量化至 1 位定点数。通常神经网络计算量集中在乘加操作，二值权重使该操作只靠位运算就能完成，极大加速了神经网络的推断过程，同时能够最大程度地减小模型的存储占用和模型的计算量，[WRPN](https://arxiv.org/abs/1709.01134) 指出在定制化的FPGA 和ASIC 上，BNN 对比全精度可获得1000倍的功耗节省。但二值化会不可避免地导致严重的信息损失，其量化函数不连续性也给深度网络的优化带来了困难。模型结构采用最新的BNext二值化网络结构，首次让二值网络在ILSVRC-2012 ImageNet 上取得超过80%的Top-1精度。

## 模型描述
采用最新提出的[BNext-S](https://arxiv.org/abs/2211.12933)结构。其结构如下图所示。  
<img src="./assets/bnext_arch.jpeg" alt="Bext模型结构"/>

## 使用方式和范围

使用方式：
- 支持CPU/GPU 推理，适合imagenet-1k 支持的标签集上进行直接推理。

使用范围:
- 本模型适用于部署在二值优化加速的硬件，适合2D image 输入的任务。

目标场景:
- imagenet-1k 支持的标签集上进行直接推理
- 作为通用backbone 可以被集成到各种任务中作为特征提取器部署到端侧设备

### 如何使用

在ModelScope框架上，提供输入图片，即可通过简单的Pipeline调用来使用。

#### 代码范例
```python
from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks

img_path = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/bird.JPEG'
image_classification = pipeline(Tasks.image_classification, 
                                model='damo/cv_bnext-small_image-classification_ImageNet-labels')
result = image_classification(img_path)
print(result)
```

### 模型局限性以及可能的偏差

- 模型在非高密集型操作(如PReLU等)时权重不会量化到1bit, 而是依旧使用fp32进行推理，考虑硬件设备的不同，可能带来一定性能差异，请用户自行评测后决定如何使用。


## 训练数据介绍

- 使用标准 imagenet-1k 数据集


### 预处理

测试时主要的预处理如下：
- Resize：先将原始图片的短边缩放至256
- Normalize：图像归一化，减均值除以标准差
- CenterCrop：裁切为224x224

## 数据评估及结果

模型在ImageNet1K的测试集进行测试，结果如下:  

| Model | top-1 acc | #params | 
|:--------:|:-------:|--------------|
|  BNext-T  | 72.3   | 5.3M   | 
|  BNext-S  | 76.1   | 11.1M   |
|  BNext-M  | 78.3   | 20.4M   |
|  BNext-L  | 80.5   | 47.6M   |

## 引用

```latex
@article{guo2022join,
  title={Join the High Accuracy Club on ImageNet with A Binary Neural Network Ticket},
  author={Guo, Nianhui and Bethge, Joseph and Meinel, Christoph and Yang, Haojin},
  journal={arXiv preprint arXiv:2211.12933},
  year={2022}
}
```
