Add oknet-csd mirror (official weights, safetensors, config, card, demo)
#1
by dronefreak - opened
Files changed (8)
- .gitattributes+3
- README.mdAdded+147
- assets/demo_banner.mp4Added+3
- assets/demo_banner_poster.jpgAdded
- assets/examples.jpgAdded
- config.jsonAdded+27
- csd.pklAdded+3
- model.safetensorsAdded+3
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines33343536373832 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textassets/demo_banner.mp4 filter=lfs diff=lfs merge=lfs -textassets/demo_banner_poster.jpg filter=lfs diff=lfs merge=lfs -textassets/examples.jpg filter=lfs diff=lfs merge=lfs -text
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147---license: mitlibrary_name: pytorchpipeline_tag: image-to-imagetags:- image-restoration- desnowing- oknet- cnn- community-mirrordatasets:- dronefreak/CSD---
# OKNet trained on CSD
<p align="center"><video controls autoplay loop muted playsinline width="900" poster="https://huggingface.co/dronefreak/oknet-csd/resolve/main/assets/demo_banner_poster.jpg" src="https://huggingface.co/dronefreak/oknet-csd/resolve/main/assets/demo_banner.mp4"><img src="https://huggingface.co/dronefreak/oknet-csd/resolve/main/assets/demo_banner_poster.jpg" alt="OKNet desnowing CSD test images" width="900"></video></p>
*Demo: this checkpoint on 18 CSD test images, wiping from the snowy input to the model output, with each image's PSNR against the ground truth. Rendered with the official code.*
> **Unofficial mirror** of the official OKNet weights from [c-yn/OKNet](https://github.com/c-yn/OKNet). The weights are **unchanged**; this repository adds a weights-only `model.safetensors` copy, a `config.json`, an independent evaluation and rendered examples.
## Model
- **Architecture:** OKNet- **Task:** single image desnowing- **Trained on:** CSD train (8,000 synthetic snowy/clean pairs)- **Dataset on the Hub:** [CSD](https://huggingface.co/datasets/dronefreak/CSD) (our mirror)- **Parameters:** 4.72M- **Paper:** [Omni-Kernel Network for Image Restoration](https://ojs.aaai.org/index.php/AAAI/article/view/27907) (AAAI 2024)- **Code:** https://github.com/c-yn/OKNet- **License:** MIT (from the official repository)
OKNet (omni-kernel network) is a three-scale convolutional U-Net in the multi-input, multi-output style, returning outputs at 1/4, 1/2 and full resolution (the last one is the result). Its bottleneck, at the lowest resolution, holds the omni-kernel module with three branches: a large branch of 63x63, 1x63 and 63x1 depthwise convolutions, a global branch that reweights features in the frequency domain (FFT-based channel attention and a frequency gating step), and a local 1x1 branch. Keeping the large kernels at the bottleneck gives a wide receptive field at 4.72M parameters.
## Results
On CSD test (2,000 pairs):
| | PSNR (dB) | SSIM ||---|---|---|| Reported in the official README | not listed | not listed || Measured for this mirror | 37.99 | 0.988 |
The official README does not list per-dataset results (they are in the AAAI paper, which we have not transcribed here), so this card gives our measurement only. We ran the official checkpoint with the official model code and reproduced the official `eval.py`: the input is reflect-padded on the right and bottom to a multiple of 4 and the full-resolution output (the last of the three) is cropped back, PSNR is `10 * log10(1 / MSE)` on the clamped output and SSIM is [pytorch-msssim](https://github.com/VainF/pytorch-msssim) on images average-pooled by `round(min(H, W) / 256)` of the padded size, as the authors do. Evaluated on the test split of our [CSD mirror](https://huggingface.co/datasets/dronefreak/CSD).

## Files
| File | Content ||---|---|| `csd.pkl` | original checkpoint, exactly as released (`{"model": state_dict}`) || `model.safetensors` | the model weights, bit-exact, nothing else || `config.json` | architecture, data, results and provenance (including the SHA-256 of the original file) || `assets/` | demo video, poster and the examples grid above |
## Usage
The model code lives in the official repository; clone it:
```bashgit clone https://github.com/c-yn/OKNet```
```pythonimport sys
import numpy as npimport torchimport torch.nn.functional as Ffrom huggingface_hub import hf_hub_downloadfrom PIL import Imagefrom safetensors.torch import load_file
sys.path.insert(0, "OKNet/Desnowing")from models.OKNet import build_net
net = build_net()net.load_state_dict(load_file(hf_hub_download("dronefreak/oknet-csd", "model.safetensors")))net.eval()
img = np.asarray(Image.open("input.png").convert("RGB"), dtype=np.float32) / 255.0x = torch.from_numpy(img).permute(2, 0, 1)[None]h, w = x.shape[2:]x = F.pad(x, (0, -w % 4, 0, -h % 4), mode="reflect") # sides must be multiples of 4with torch.no_grad(): y = net(x)[2][:, :, :h, :w].clamp(0, 1) # outputs at 1/4, 1/2 and full size; keep the lastImage.fromarray((y[0].permute(1, 2, 0).numpy() * 255).round().astype(np.uint8)).save("output.png")```
To use the original file instead:
```pythonsd = torch.load(hf_hub_download("dronefreak/oknet-csd", "csd.pkl"), map_location="cpu")["model"]net.load_state_dict(sd)```
Models trained on synthetic data may not transfer well to real photographs.
## All mirrors of Yuning Cui's restoration models
PSNR / SSIM as measured by us with the authors' evaluation code on each checkpoint's test set (Y channel for deraining, shown on Rain100H).
| Repository | Model | Trained on | Task | Params | Test set | PSNR / SSIM ||---|---|---|---|---|---|---|| [convir-s-reside-its](https://huggingface.co/dronefreak/convir-s-reside-its) | ConvIR-S | RESIDE-ITS | dehazing | 5.53M | SOTS indoor | 41.53 / 0.996 || [convir-s-csd](https://huggingface.co/dronefreak/convir-s-csd) | ConvIR-S | CSD | desnowing | 5.53M | CSD test | 38.43 / 0.988 || [convir-s-dense-haze](https://huggingface.co/dronefreak/convir-s-dense-haze) | ConvIR-S | Dense-Haze | dehazing | 5.53M | Dense-Haze | 17.45 / 0.648 || [convir-s-nh-haze](https://huggingface.co/dronefreak/convir-s-nh-haze) | ConvIR-S | NH-Haze | dehazing | 5.53M | NH-Haze | 20.65 / 0.806 || [convir-s-i-haze](https://huggingface.co/dronefreak/convir-s-i-haze) | ConvIR-S | I-Haze | dehazing | 5.53M | I-Haze | 21.95 / 0.888 || [convir-s-o-haze](https://huggingface.co/dronefreak/convir-s-o-haze) | ConvIR-S | O-Haze | dehazing | 5.53M | O-Haze | 25.25 / 0.937 || [convir-b-reside-its](https://huggingface.co/dronefreak/convir-b-reside-its) | ConvIR-B | RESIDE-ITS | dehazing | 8.63M | SOTS indoor | 42.72 / 0.997 || [convir-b-csd](https://huggingface.co/dronefreak/convir-b-csd) | ConvIR-B | CSD | desnowing | 8.63M | CSD test | 39.10 / 0.990 || [convir-b-dense-haze](https://huggingface.co/dronefreak/convir-b-dense-haze) | ConvIR-B | Dense-Haze | dehazing | 8.63M | Dense-Haze | 16.86 / 0.621 || [convir-b-nh-haze](https://huggingface.co/dronefreak/convir-b-nh-haze) | ConvIR-B | NH-Haze | dehazing | 8.63M | NH-Haze | 20.66 / 0.802 || [convir-b-i-haze](https://huggingface.co/dronefreak/convir-b-i-haze) | ConvIR-B | I-Haze | dehazing | 8.63M | I-Haze | 22.45 / 0.887 || [convir-b-o-haze](https://huggingface.co/dronefreak/convir-b-o-haze) | ConvIR-B | O-Haze | dehazing | 8.63M | O-Haze | 25.35 / 0.934 || [convir-l-rain13k](https://huggingface.co/dronefreak/convir-l-rain13k) | ConvIR-L | Rain13K | deraining | 14.83M | Rain100H | 31.10 / 0.903 || [oknet-reside-its](https://huggingface.co/dronefreak/oknet-reside-its) | OKNet | RESIDE-ITS | dehazing | 4.72M | SOTS indoor | 40.79 / 0.996 || **oknet-csd** (this repo) | OKNet | CSD | desnowing | 4.72M | CSD test | 37.99 / 0.988 || [oknet-dense-haze](https://huggingface.co/dronefreak/oknet-dense-haze) | OKNet | Dense-Haze | dehazing | 4.72M | Dense-Haze | 16.92 / 0.643 || [oknet-nh-haze](https://huggingface.co/dronefreak/oknet-nh-haze) | OKNet | NH-Haze | dehazing | 4.72M | NH-Haze | 20.48 / 0.804 || [oknet-i-haze](https://huggingface.co/dronefreak/oknet-i-haze) | OKNet | I-Haze | dehazing | 4.72M | I-Haze | 21.72 / 0.870 || [oknet-o-haze](https://huggingface.co/dronefreak/oknet-o-haze) | OKNet | O-Haze | dehazing | 4.72M | O-Haze | 25.64 / 0.939 || [sfnet-reside-its](https://huggingface.co/dronefreak/sfnet-reside-its) | SFNet | RESIDE-ITS | dehazing | 13.27M | SOTS indoor | 41.24 / 0.996 || [sfnet-rain13k](https://huggingface.co/dronefreak/sfnet-rain13k) | SFNet | Rain13K | deraining | 13.27M | Rain100H | 31.86 / 0.908 |
## Citation
If you use these weights, please cite the original work:
```bibtex@inproceedings{cui2024omni, title = {Omni-Kernel Network for Image Restoration}, author = {Cui, Yuning and Ren, Wenqi and Knoll, Alois}, booktitle = {Proceedings of the AAAI Conference on Artificial Intelligence}, volume = {38}, number = {2}, pages = {1426--1434}, year = {2024}}```
## Disclaimer
This is not an official release. All credit goes to the original authors (Yuning Cui, Wenqi Ren, Alois Knoll). The weights are redistributed under the MIT license of the official repository (copyright Yuning Cui). If you are an author and want this mirror changed or removed, please open a discussion.123version https://git-lfs.github.com/spec/v1oid sha256:e46f723ba420df180de1a6800910c9306155ad919cbe1c8c99721888b0132fc0size 1214799123456789101112131415161718192021222324252627{ "architecture": "OKNet", "variant": "OKNet", "task": "single image desnowing", "dataset": "CSD", "training_data": "CSD train (8,000 synthetic snowy/clean pairs)", "test_set": "CSD test (2,000 pairs)", "model_code": "https://github.com/c-yn/OKNet/tree/main/Desnowing", "constructor": "models.OKNet.build_net()", "input": "RGB in [0, 1]; height and width padded (reflect) to a multiple of 4", "output": "list of 3 tensors (1/4, 1/2, full resolution); use the last, crop the padding, clamp to [0, 1]", "parameters": 4722857, "checkpoint": "csd.pkl", "checkpoint_sha256": "e5810d783ac2efd88dd533208db9aa3b69b96d6906cce04308d86376fca8daf4", "weights_key": "model", "official_repository": "https://github.com/c-yn/OKNet", "source": "official pretrained-model folder linked from the repository README", "license": "mit", "reported_results": null, "measured_results": { "PSNR": 37.99, "SSIM": 0.988, "images": 2000 }, "metric": "official eval.py: PSNR on the clamped output, SSIM (pytorch-msssim) on images average-pooled by round(min(H, W) / 256)", "paper": "https://ojs.aaai.org/index.php/AAAI/article/view/27907"}123version https://git-lfs.github.com/spec/v1oid sha256:e5810d783ac2efd88dd533208db9aa3b69b96d6906cce04308d86376fca8daf4size 18959609123version https://git-lfs.github.com/spec/v1oid sha256:465de4155e10969648adc64abab446bb1987af9573affcb31809b7ad40bfcd9csize 18908124.gitattributes+3
README.mdAdded+147
assets/demo_banner.mp4Added+3
assets/demo_banner_poster.jpgAdded

Large File Pointer Details
- SHA256: aefbfc2c37e3249496bae53e0dbb5b2651ef9a7f038dff30a5396001c5907f5f
- Pointer size: 131 Bytes
- Size of remote file: 180 kB
assets/examples.jpgAdded

Large File Pointer Details
- SHA256: fefacde6195e82d54796ae0436f918b6099ae8a635a77223bc30fb7a3a2c4924
- Pointer size: 131 Bytes
- Size of remote file: 274 kB
config.jsonAdded+27
csd.pklAdded+3
model.safetensorsAdded+3