File size: 1,756 Bytes
6fa070a
 
 
3fd3263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
---
license: mit
---

# MobileNetV3 Backbone

A feature extractor based on [MobileNetV3](https://arxiv.org/abs/1905.02244), refactored from https://github.com/xiaolai-sqlai/mobilenetv3: **backbone only — the classification head is removed**, with unified naming.

## Models

| Model | Variant | Output features | Weight file |
| --- | --- | --- | --- |
| `MobileNetV3` | small / large (auto) | 1280 | detected from checkpoint |
| `MobileNetV3_Small` | Small | 1280 | `mobilenetv3_small.safetensors` |
| `MobileNetV3_Large` | Large | 1280 | `mobilenetv3_large.safetensors` |

Input: `(B, 3, H, W)` images. Output: `(B, 1280)` feature vectors (migrated from ImageNet-pretrained weights).

## Weight naming

The naming differences between the old and the new code are mapped automatically during migration:

| Old name | New name |
| --- | --- |
| `bn1/bn2/bn3` | `norm1/norm2/norm3` |
| `linear3` | `proj` |
| `Block.se.se.*` | `Block.se.features.*` |
| `linear4` (classification head) | removed |

## Usage

```python
from mobile_net import MobileNetV3_Small, MobileNetV3_Large

fe = MobileNetV3_Large().load_pretrained('./mobilenetv3_large.safetensors')
fe.eval()

fe.save_pretrained('./backbone.safetensors')
fe.save_pretrained('./backbone.pth')

import torch
x = torch.randn(2, 3, 224, 224)
feat = fe(x) # (2, 1280)
```

### Auto backend detection

`MobileNetV3.from_pretrained` inspects the checkpoint and picks Small / Large automatically:

```python
from mobile_net import MobileNetV3

fe = MobileNetV3.from_pretrained('./mobilenetv3_large.safetensors')  # -> Large, weights loaded
print(fe.backend)   # 'large'
```

Calling it on a pinned class (`MobileNetV3_Large` / `MobileNetV3_Small`) raises if the checkpoint backend disagrees with the class.