Views
No views yet
| File | Size | Purpose |
|---|---|---|
drunet_color.ncnn.param | ~11 KB | Network topology (text format, 125 layers) |
drunet_color.ncnn.bin | ~65 MB | fp16-quantized weights |
.pth; visually-perceptible differences vs fp32 are
within noise on a real image at σ ≤ 50.1#include "net.h"
2
3ncnn::Net net;
4net.opt.use_vulkan_compute = true; // ~5× faster than CPU on a real GPU
5net.load_param("drunet_color.ncnn.param");
6net.load_model("drunet_color.ncnn.bin");
7
8// Input layout: 4-channel float, (1, 4, H, W)
9// ch0..2 = RGB normalized to [0, 1]
10// ch3 = σ/255 broadcast as a constant plane
11// H and W must be multiples of 8 (4 downscale stages in the UNet).
12// Pad with cv::BORDER_REPLICATE and crop the result back.
13
14ncnn::Mat in(W, H, 4);
15// ...fill RGB and σ plane...
16
17ncnn::Extractor ex = net.create_extractor();
18ex.input("in0", in);
19ncnn::Mat out;
20ex.extract("out0", out); // 3-channel float RGB in [0, 1]1# python3, in a venv with torch + pnnx + opencv-python
2import sys, torch
3sys.path.insert(0, "DPIR") # clone of github.com/cszn/DPIR
4from models.network_unet import UNetRes
5
6model = UNetRes(in_nc=4, out_nc=3, nc=[64,128,256,512], nb=4,
7 act_mode="R", downsample_mode="strideconv",
8 upsample_mode="convtranspose")
9model.load_state_dict(torch.load("drunet_color.pth", weights_only=True))
10model.eval()
11
12x = torch.randn(1, 4, 256, 256)
13torch.jit.trace(model, x, check_trace=False).save("drunet_color.pt")
14
15import pnnx
16pnnx.convert("drunet_color.pt", inputs=x, fp16=True)
17# → drunet_color.ncnn.param + drunet_color.ncnn.binconvert_drunet.py in the
sibling repo.| Backend | Wall time | Notes |
|---|---|---|
| Vulkan, Apple M2 Ultra (MoltenVK) | 1.3 s | warm; first run ~44 s (shader JIT) |
| Vulkan, NVIDIA RTX 3060 (Windows) | 3.66 s | warm avg of 3; cold 3.49 s (5.7× over same-box CPU) |
| CPU, Apple M2 Ultra (4 threads) | 3.1 s | native arm64, AppleClang + libomp |
| CPU, AMD Ryzen 7 2700X (4 threads, AVX2) | 21 s | RTX 3060 box, MLC_NCNN_CPU=1 forced |
| CPU, Intel Xeon (4 threads, AVX2) | 23 s | Linux box without hardware Vulkan |
| Vulkan, Mesa llvmpipe (software) | 127 s | 5× slower than CPU — filter this out |
ncnn::get_gpu_info() only reports llvmpipe (Mesa software
Vulkan on headless Linux), prefer CPU — software Vulkan is a
slowdown for this model size, not a speedup. The companion C++
wrapper auto-detects this and falls back to CPU.@article{zhang2021plug,
title={Plug-and-Play Image Restoration with Deep Denoiser Prior},
author={Zhang, Kai and Li, Yawei and Zuo, Wangmeng and Zhang, Lei and
Van Gool, Luc and Timofte, Radu},
journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
year={2021}
}denoise Tool Plugin in
mlc OpticScript — JS scripts can call
Engine.tool('denoise').apply(img, {strength: 20}) and the runtime
spawns the bundled C++ binary that loads these weights.