simplify trainer quickstart (official converter) + ONNX export config
Browse files- README.md +35 -12
- configs/4x_NERVE_onnx.yml +33 -0
README.md
CHANGED
|
@@ -51,27 +51,50 @@ Pick a model and run it:
|
|
| 51 |
|
| 52 |
### As a trainer (want to train your own)
|
| 53 |
|
|
|
|
|
|
|
|
|
|
| 54 |
```bash
|
| 55 |
-
# 1.
|
| 56 |
cp nerve_arch.py <traiNNer-redux>/traiNNer/archs/
|
| 57 |
|
| 58 |
-
# 2.
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
|
| 63 |
-
-
|
|
|
|
| 64 |
```
|
| 65 |
|
| 66 |
-
That
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
**Training tips** (all NERVE models follow these):
|
| 71 |
- bf16 AMP is fine; no gradient clipping needed (norm-free net).
|
| 72 |
- `--auto_resume` is recommended for long runs.
|
| 73 |
-
- For real-world input,
|
| 74 |
-
then the OTF GAN config — that's the chain the released models use.
|
| 75 |
|
| 76 |
---
|
| 77 |
|
|
@@ -190,7 +213,7 @@ because it has no attention ops.
|
|
| 190 |
|
| 191 |
```
|
| 192 |
nerve_arch.py the architecture (single file)
|
| 193 |
-
configs/ example training configs (
|
| 194 |
models/ pretrained checkpoints (see table above)
|
| 195 |
onnx/ dynamic fp32 ONNX (opset 20, onnxslim-optimized)
|
| 196 |
ncnn/ ncnn fp16 param/bin (fixed 256x256 input)
|
|
|
|
| 51 |
|
| 52 |
### As a trainer (want to train your own)
|
| 53 |
|
| 54 |
+
NERVE is a normal [traiNNer-redux](https://github.com/the-database/traiNNer-redux)
|
| 55 |
+
architecture — no special steps.
|
| 56 |
+
|
| 57 |
```bash
|
| 58 |
+
# 1. Add the architecture (auto-registers: traiNNer scans *_arch.py)
|
| 59 |
cp nerve_arch.py <traiNNer-redux>/traiNNer/archs/
|
| 60 |
|
| 61 |
+
# 2. Copy a training config and point it at your data
|
| 62 |
+
cp configs/4x_NERVE_release.yml <traiNNer-redux>/options/
|
| 63 |
+
# -> edit dataroot_gt / dataroot_lq in that file
|
| 64 |
+
|
| 65 |
+
# 3. Train
|
| 66 |
+
cd <traiNNer-redux>
|
| 67 |
+
python train.py -opt options/4x_NERVE_release.yml --auto_resume
|
| 68 |
|
| 69 |
+
# 4. Export to optimized dynamic ONNX (official converter)
|
| 70 |
+
cp configs/4x_NERVE_onnx.yml <traiNNer-redux>/options/
|
| 71 |
+
# -> set path.pretrain_network_g to your trained checkpoint
|
| 72 |
+
python convert_to_onnx.py -opt options/4x_NERVE_onnx.yml
|
| 73 |
```
|
| 74 |
|
| 75 |
+
That is the whole workflow. The net is one file, the config is one file, the
|
| 76 |
+
checkpoint is one file — **no fusion step, no paired fused/unfused weights.**
|
| 77 |
+
|
| 78 |
+
- `4x_NERVE_onnx.yml` exports dynamic-shape ONNX (opset 20) and can emit
|
| 79 |
+
`fp32`, `fp16`, or `bf16` (`onnx.dtype`), with OnnxSlim optimization and a
|
| 80 |
+
built-in PyTorch-vs-ONNX verify pass.
|
| 81 |
+
- Prefer no extra dependencies? `scripts/export_dynamic.py` is a tiny
|
| 82 |
+
standalone exporter (torch + onnxruntime only).
|
| 83 |
+
|
| 84 |
+
**Start from a released pretrain** (skip the expensive early training) by
|
| 85 |
+
setting `path.pretrain_network_g` in your training config to a file from
|
| 86 |
+
`models/`:
|
| 87 |
+
|
| 88 |
+
| training stage | warm-start from |
|
| 89 |
+
|---|---|
|
| 90 |
+
| `4x_NERVE_release.yml` | `models/4x_NERVE_release.safetensors` (or the 2x one with `strict_load_g: false`) |
|
| 91 |
+
| `4x_NERVE_OTF_fidelity.yml` | `models/4x_NERVE_release.safetensors` |
|
| 92 |
+
| `4x_NERVE_OTF_gan.yml` | your OTF fidelity checkpoint |
|
| 93 |
|
| 94 |
**Training tips** (all NERVE models follow these):
|
| 95 |
- bf16 AMP is fine; no gradient clipping needed (norm-free net).
|
| 96 |
- `--auto_resume` is recommended for long runs.
|
| 97 |
+
- For real-world input, follow the chain: clean release -> OTF fidelity -> OTF GAN.
|
|
|
|
| 98 |
|
| 99 |
---
|
| 100 |
|
|
|
|
| 213 |
|
| 214 |
```
|
| 215 |
nerve_arch.py the architecture (single file)
|
| 216 |
+
configs/ example training configs (+ 4x_NERVE_onnx.yml for ONNX export)
|
| 217 |
models/ pretrained checkpoints (see table above)
|
| 218 |
onnx/ dynamic fp32 ONNX (opset 20, onnxslim-optimized)
|
| 219 |
ncnn/ ncnn fp16 param/bin (fixed 256x256 input)
|
configs/4x_NERVE_onnx.yml
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# yaml-language-server: $schema=https://raw.githubusercontent.com/the-database/traiNNer-redux/refs/heads/master/schemas/redux-config.schema.json
|
| 2 |
+
####################
|
| 3 |
+
# General Settings
|
| 4 |
+
####################
|
| 5 |
+
name: 4x_NERVE
|
| 6 |
+
scale: 4 # 1, 2, 3, 4
|
| 7 |
+
num_gpu: auto
|
| 8 |
+
|
| 9 |
+
#####################
|
| 10 |
+
# Network Settings
|
| 11 |
+
#####################
|
| 12 |
+
network_g:
|
| 13 |
+
type: nerve
|
| 14 |
+
|
| 15 |
+
############################
|
| 16 |
+
# Pretrain and Resume Paths
|
| 17 |
+
############################
|
| 18 |
+
path:
|
| 19 |
+
# Set this to the checkpoint you trained (or a released model).
|
| 20 |
+
pretrain_network_g: experiments/4x_NERVE_release/models/net_g_ema_latest.safetensors
|
| 21 |
+
|
| 22 |
+
#########################
|
| 23 |
+
# ONNX conversion options
|
| 24 |
+
#########################
|
| 25 |
+
onnx:
|
| 26 |
+
dynamo: false # legacy exporter; NERVE also exports with dynamo: true if you prefer.
|
| 27 |
+
dtype: fp32 # fp32, fp16, or bf16.
|
| 28 |
+
bf16_exclude_depthwise: true
|
| 29 |
+
opset: 20
|
| 30 |
+
shape: 1x3xHxW # dynamic H/W. Use 1x3x256x256 for a fully static model.
|
| 31 |
+
wrap_5d_to_4d: true
|
| 32 |
+
verify: true # verify ONNX vs PyTorch after export
|
| 33 |
+
optimize: true # run OnnxSlim on the exported model
|