# Train

> Connect before (Source) and after (Target) frames, list the frames, press Train.

Connect before (Source) and after (Target) frames, list the frames, press Train. Our own UNet trains in the AI worker on float frames in a log encoding (ACEScct / log2), so highlights and negatives survive. Modes: fix (learns only the change), direct, matte (Target alpha). Checkpoints are .ocat files; View shows the contact sheet or a preview. Dataset adds more shots (show-level). Training runs in the AI worker, so the app stays usable while it runs.

| Node | Train |
|---|---|
| Menu | AI › Train |
| **Names in each format** | |
| .oink comp (JSON) | `"type": "OC_N_aitrain"` |
| .nk script | none: written as an Oink node |
| Python | `nuke.createNode("OC_N_aitrain")` |
| Assistant (MCP) | `create_node(type="Train")` |
| Tab search | `train` |

![Train properties](/shots/nodes/aitrain@2x.webp)

## Inputs and outputs

| Port | Name | Type |
|---|---|---|
| input 0 | Source | image |
| input 1 | Target | image |
| output 0 | Image | image |

## Knobs

Panel tab **Aitrain**, in panel order.

| Knob | Label | Type | Default | Range / values | .nk knob | Description |
|---|---|---|---|---|---|---|
| `mode` | mode | menu | `fix` | fix (fix (residual)), direct, matte |  |  |
| `preset` | model | menu | `small` | small (UNet small), medium (UNet medium), large (UNet large) |  |  |
| `encoding` | encoding | menu | `acescct` | acescct (ACEScct), log2 (log2 shaper), linear |  |  |
| `frames` | frames | text |  |  |  | Training frames, e.g. 1001-1005, 1020, 1030-1060x10 |
| `val_frames` | validation frames | text |  |  |  | Held-out frames for the PSNR / IoU readout and the contact sheet |
| `dataset_data` | dataset (shots) | text | `[]` |  |  | More shots (BigCat): JSON [{"name", "source", "target", "frames", "val_frames"}], source/target = node name or file pattern (####) |
| `steps` | steps | float | `2000` | 1 to 1000000 (integer) |  |  |
| `batch_size` | batch | float | `8` | 1 to 256 (integer) |  |  |
| `patch_size` | patch | float | `128` | 32 to 1024 (integer) |  |  |
| `learning_rate` | learning rate | float | `0.001` | 0.000001 to 1 |  |  |
| `lr_schedule` | schedule | menu | `cosine` | cosine, constant, step |  |  |
| `warmup` | warmup | float | `100` | 0 to 100000 (integer) |  |  |
| `loss` | loss | menu | `auto` | auto, l1 (L1), charbonnier (Charbonnier), l2 (L2), bce (BCE) |  |  |
| `grad_weight` | gradient loss (-1 auto) | float | `-1` | -1 to 10 |  | Edge (gradient) loss weight; -1 = auto (0.5 matte, 0 otherwise) |
| `focus` | focus (-1 auto) | float | `-1` | -1 to 1 |  | Share of patches centred on changed pixels / matte edges; -1 = auto (0.5) |
| `aug_flip` | flip | bool | `true` |  |  |  |
| `aug_rotate` | rotate 90 | bool | `false` |  |  |  |
| `aug_exposure` | exposure jitter (stops) | float | `0` | 0 to 4 |  | Stops (sigma), applied in the log encoding to source and target |
| `aug_wb` | white balance jitter | float | `0` | 0 to 2 |  |  |
| `precision` | precision | menu | `fp32` | fp32 (fp32 (TF32)), bf16 (bf16 mixed) |  |  |
| `checkpoint` | checkpoint | file |  |  |  | Model file (.ocat). Empty = new file in $OPENCOMP_TRAIN_DIR or /mnt/apps/opencomp/train |
| `overwrite` | overwrite | bool | `true` |  |  | Train (not Resume) replaces an existing checkpoint |
| `val_every` | validate every | float | `200` | 1 to 100000 (integer) |  |  |
| `save_every` | save every | float | `500` | 0 to 100000 (integer) |  |  |
| `seed` | seed | float | `0` | 0 to 2147483647 (integer) |  |  |
| `view` | view | menu | `source` | source, target, preview, contact (contact sheet) |  |  |
| `tile_size` | tile | float | `1024` | 64 to 8192 (integer) |  |  |
| `overlap` | overlap | float | `64` | 0 to 512 (integer) |  |  |

### Other knobs (Python, .nk and the assistant; not on the panel)

| Knob | Label | Type | Default | Range / values | .nk knob | Description |
|---|---|---|---|---|---|---|
| `gl_color` | Viewer Controls Color | float ×3 | `0, 0, 0` | 0 to 1 |  |  |
| `postage_stamp_frame` | Static Frame | int | `1` | -2147483648 to 2147483647 |  |  |
| `lifetimeStart` | Lifetime Start | int | `0` | -2147483648 to 2147483647 |  |  |
| `lifetimeEnd` | Lifetime End | int | `100` | -2147483648 to 2147483647 |  |  |
| `useLifetime` | Use Lifetime | boolean | `false` |  |  |  |
| `cached` | Cached | boolean | `false` |  |  |  |
| `bookmark` | Bookmark | boolean | `false` |  |  |  |
| `dope_sheet` | Dope Sheet | boolean | `false` |  |  |  |
| `clone_group` | Clone Group | string |  |  |  |  |
| `link_source` | Link Source | string |  |  |  |  |
| `link_overrides` | Link Overrides | string |  |  |  |  |
| `split_views` | Split Views | string |  |  |  |  |
| `generation` | Generation | int | `0` | -2147483648 to 2147483647 |  |  |
| `trained_steps` | Trained Steps | int | `0` | -2147483648 to 2147483647 |  |  |


---
Sources: opencomp_core/nodes/ai/aitrain.py, opencomp_electron/src/components/properties/knobSchema.ts, opencomp_core/nodes/help/aitrain.md
