AI_NR applies deep learning to denoise Bayer RAW data. Compared with traditional denoising, AI denoising removes noise more thoroughly and leaves a finer noise texture, and it delivers a higher signal-to-noise ratio in dark scenes or at very high gain, so the image stays legible.
The AI_NR tool follows a "large-model distillation + small-model fine-tuning" design. Using the calibrated FPN (fixed pattern noise) and noise parameters together with a general-purpose denoising large model, it processes captured noisy RAW data to produce noisy-clean RAW pairs. Those pairs train the small model, which is then quantized and deployed on the device.
The complete workflow has six stages:
ai_nr.The following data must be ready before training:
again must be at maximum, ispdgain=1, and sensor dgain=1. Note that a shorter exposure exposes fewer FPN defect pixels, so the label learns less about defect removal. Replacing the sensor requires replacing the FPN data too.***.raw, ***.txt, awb.txt, and ccm.txt.Each stage is driven by editing config.yml.
Generate noise-clean RAW pairs for the current distillation data with the large model.
state: "preprocess", substate: "preprocess_sm".bit, max_dgain, max_iso, bayer_pattern, and sensor_id under data.fpn_dir (FPN), data_dir (distillation data), dump_pre_root (output), and the teacher model path.dump_pre_root to confirm preprocessing worked.Two-stage training of the small floating-point model.
state: "float", substate: "float_finetune".stage (1 or 2), learning_rate, batch_size, and so on under train.net_name under model, nearest to your sensor resolution (for example, 3M picks "4M", 6M picks "8M").input, label, and predict images to train_dump; check that color and brightness correspond. Training for 60+ epochs is recommended. If the loss becomes NaN, check the FPN/sensor bit settings, or try a smaller learning rate and a larger batch size.Visually verify the floating-point model.
state: "float", substate: "float_inference".pth with the higher PSNR from float_finetune.select_iso can target a specific ISO.Convert the floating-point model to a quantized model in two stages.
state: "quant", substate: "quant_finetune".best_float_model to the floating-point model path. Running produces quant_finetune_stage1.pth.best_quant_model at the stage-1 pth and keep training to produce quant_finetune_stage2.pth. Training for 10+ epochs is recommended. If you add data, regenerate the .h5 files and update the train_name list.Validate the quantized model: its output must be visually indistinguishable from the floating-point model, with no obvious loss of detail or color shift.
state: "quant", substate: "quant_inference".quant_finetune_stage2 pth.Export the ONNX model and deployment files for the TVM compiler.
state: "quant", substate: "quant_deploy".padding_w: fixed at 32 (16 when deploying for 7206_8M).padding_h: computed as \text{padding_h} = \frac{\left(\left|\frac{h}{(\text{row_num} * 32)}\right| + p_s_ h\right) \times 16 - \frac{h}{(\text{row_num} * 2)}}one_step_deploy: set to True to run all three stages at once._tvm.encrypted model, a weights txt file, and the corresponding bin file.Note
If deployment reports "The model has overflow!!!!", determine whether the overflow comes from Quant1 or Quant2, and test deployment with the model from the stage that did not overflow.
| Parameter | Range | Description |
|---|---|---|
state |
"preprocess", "float", "quant" |
Controls the tool's operating mode: preprocess for data processing, float for floating-point model work, quant for quantized model work. |
substate |
"float_finetune", "float_inference", "quant_finetune", "quant_inference", "quant_deploy", "preprocess_sm" |
The specific substate. For float operations set state to float; for quant operations set state to quant. |
| Parameter | Description | Range |
|---|---|---|
net_name |
Model resolution, chosen nearest to the sensor resolution | "2M_3g", "2M_5g", "4M_8g", "4M_12g", "8M_19g" |
best_float_model |
Pretrained floating-point model, or the floating-point model used for quantization | user-defined path |
best_quant_model |
Pretrained quantized model, or the initial model for quantization stage 2 | user-defined path |
| Parameter | Description | Range |
|---|---|---|
stage |
Training stage for floating-point or quantized models | 1 / 2 |
learning_rate |
Training learning rate | 0.000001 ~ 0.01 |
batch_size |
Training batch size | 1 ~ 16 |
| Parameter | Description | Range |
|---|---|---|
one_step_deploy |
Quantized model deployment switch | True / False |
deploy_version |
Deployment target version | "7206", "7606" |
layer_bit |
Quantization bit width | 10 / 12 |
Calibration accuracy directly affects pipeline quality. Points to watch:
After the conventional pipeline is tuned, load the AI model and fine-tune:
ainrposswitch and coringposswitch to post.switchthlow and switchthhigh. Recommended: thdhigh > thdlow >= againmax for ISO.| Symptom | Likely cause and checks |
|---|---|
| Float Finetune loss is NaN | 1. Check the small images in train_dump for anomalies; 2. Check the FPN/sensor bit settings in the YML; 3. Check that input and label contents, colors, and brightness correspond; 4. Try a smaller learning rate and a larger batch size (for example 24, 32). |
| Bleed-through at very high ISO | Usually caused by temporal filtering being too strong. Disable YUVTNR first and see whether the bleed-through correlates with BayerTNR; if it does, lower the tnrmd threshold slightly. If disabling YUVTNR helps, check tnrmd and Mdwinsize in YUVTNR. |
| Moving objects look blurry | 1. Check whether YNR strength in STNR is too high; 2. Adjust the motion ghosting noise strength in BNR; 3. Adjust the K/B gain in the AINR module to tune AI denoising strength. |
| Quant Deploy reports overflow | Determine whether the overflow is in Quant1 or Quant2. Deploy the Quant1 result; if there is no overflow, the Quant2 training caused it. |
| Dead pixels, flicker, false texture | These are over-enhanced detail artifacts; enabling smooth_on mitigates them, and dead pixels can be tuned with the bpc strength. |
| Color cast | Check whether the training pairs have a color cast; if not, compare the test scene with the training scenes and add data for scenes that differ significantly. |
- Step 1: Build
# run from the SDK root:
source build/env.sh
make clean
make build -j
make sample
- Step 2: Copy the executable and the neuron_network.xmm model to the board
Model path: /tools/linux/pq_board/arm-gcc12.2.0-linux-uclibceabi/configs/sc465sl/neuron_network.xmm
Important
The model file and the executable must be placed on the board in a specific relative layout: the executable looks for the model at
../../tools/linux/pq_board/arm-gcc12.2.0-linux-uclibceabi/configs/sc465sl/neuron_network.xmm.
You can change the three lines in sample_comm_isp.c(56-80):

- Running sample_ainr
Parameters
Usage: ./sample_ainr [scene_mode]
scene_mode:0: single-stream linear ainr, 15fps 1: dual-stream linear ainr, 7fps (switch) 2: dual-stream linear ainr, 7fps 3: dual-stream linear ainr, 7fps (external switch) stream_mode: VENC output¶ e.g: ./sample_vio 0