initial upload: MobileNetV3-small binary head, codec corruption classifier
Browse files- README.md +83 -0
- config.json +18 -0
- model.safetensors +3 -0
README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- image-classification
|
| 5 |
+
- quality-assessment
|
| 6 |
+
- codec-corruption
|
| 7 |
+
- mobilenet
|
| 8 |
+
library_name: pytorch
|
| 9 |
+
pipeline_tag: image-classification
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# codec-corruption-classifier
|
| 13 |
+
|
| 14 |
+
Binary image classifier that predicts whether a video frame contains severe **codec corruption** — block tearing, frame freezes, or other compression-artifact damage typically seen in low-bandwidth WiFi video streams (e.g. DJI Tello drone telemetry).
|
| 15 |
+
|
| 16 |
+
Trained on hand-labelled frames from indoor drone-mapping footage. Intended as a preprocessing filter for downstream SfM / 3D reconstruction pipelines, where a single severely-corrupted frame can pollute feature matching.
|
| 17 |
+
|
| 18 |
+
## Architecture
|
| 19 |
+
|
| 20 |
+
- Backbone: `torchvision.models.mobilenet_v3_small` (ImageNet-pretrained, IMAGENET1K_V1)
|
| 21 |
+
- Head: replace the final `nn.Linear` in `classifier` with `nn.Linear(in_features, 1)`
|
| 22 |
+
- Output: single logit; apply `torch.sigmoid` for P(corrupted)
|
| 23 |
+
- Suggested threshold: `0.5`
|
| 24 |
+
- Params: 1.5M
|
| 25 |
+
|
| 26 |
+
## Preprocessing
|
| 27 |
+
|
| 28 |
+
Frames are letterboxed (preserve aspect, pad with black) to 224×224, then normalized with ImageNet statistics.
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
from PIL import Image
|
| 32 |
+
|
| 33 |
+
def letterbox(img: Image.Image, size: int = 224) -> Image.Image:
|
| 34 |
+
w, h = img.size
|
| 35 |
+
scale = size / max(w, h)
|
| 36 |
+
new_w, new_h = int(w * scale), int(h * scale)
|
| 37 |
+
img = img.resize((new_w, new_h), Image.BILINEAR)
|
| 38 |
+
padded = Image.new("RGB", (size, size), (0, 0, 0))
|
| 39 |
+
padded.paste(img, ((size - new_w) // 2, (size - new_h) // 2))
|
| 40 |
+
return padded
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
## Usage
|
| 44 |
+
|
| 45 |
+
```python
|
| 46 |
+
import torch
|
| 47 |
+
from torch import nn
|
| 48 |
+
from torchvision import transforms
|
| 49 |
+
from torchvision.models import mobilenet_v3_small
|
| 50 |
+
from huggingface_hub import hf_hub_download
|
| 51 |
+
from safetensors.torch import load_file
|
| 52 |
+
from PIL import Image
|
| 53 |
+
|
| 54 |
+
weights_path = hf_hub_download(
|
| 55 |
+
repo_id="callum-sh/codec-corruption-classifier",
|
| 56 |
+
filename="model.safetensors",
|
| 57 |
+
)
|
| 58 |
+
state = load_file(weights_path)
|
| 59 |
+
|
| 60 |
+
model = mobilenet_v3_small(weights=None)
|
| 61 |
+
in_features = model.classifier[-1].in_features
|
| 62 |
+
model.classifier[-1] = nn.Linear(in_features, 1)
|
| 63 |
+
model.load_state_dict(state)
|
| 64 |
+
model.eval()
|
| 65 |
+
|
| 66 |
+
tx = transforms.Compose([
|
| 67 |
+
transforms.Lambda(lambda im: letterbox(im, 224)),
|
| 68 |
+
transforms.ToTensor(),
|
| 69 |
+
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
|
| 70 |
+
])
|
| 71 |
+
|
| 72 |
+
img = Image.open("frame.jpg").convert("RGB")
|
| 73 |
+
with torch.no_grad():
|
| 74 |
+
logit = model(tx(img).unsqueeze(0))
|
| 75 |
+
p_corrupted = torch.sigmoid(logit).item()
|
| 76 |
+
print(f"P(corrupted) = {p_corrupted:.3f}")
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
## Intended use
|
| 80 |
+
|
| 81 |
+
Filter out frames before structure-from-motion. A frame with `P(corrupted) > 0.5` should be excluded from the SfM input set.
|
| 82 |
+
|
| 83 |
+
Not intended as a general-purpose image-quality predictor — it specifically targets *codec* artifacts, not blur, exposure, or motion noise.
|
config.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architecture": "mobilenet_v3_small",
|
| 3 |
+
"num_classes": 1,
|
| 4 |
+
"input_size": 224,
|
| 5 |
+
"image_mean": [
|
| 6 |
+
0.485,
|
| 7 |
+
0.456,
|
| 8 |
+
0.406
|
| 9 |
+
],
|
| 10 |
+
"image_std": [
|
| 11 |
+
0.229,
|
| 12 |
+
0.224,
|
| 13 |
+
0.225
|
| 14 |
+
],
|
| 15 |
+
"preprocessing": "letterbox",
|
| 16 |
+
"output": "logit (single value); apply sigmoid for P(codec_corrupted)",
|
| 17 |
+
"threshold": 0.5
|
| 18 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:83c48902cae1a337484234897dabd45208752c9ff3bd99e7761373e3c8ce91f6
|
| 3 |
+
size 6147500
|