Skip to content

Comments

Fix pixel normalization in inference engines; improve DirectML FFI bindings#4

Merged
tqmane merged 2 commits intomainfrom
copilot/fix-ai-image-test-functionality
Feb 18, 2026
Merged

Fix pixel normalization in inference engines; improve DirectML FFI bindings#4
tqmane merged 2 commits intomainfrom
copilot/fix-ai-image-test-functionality

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

Face recognition models (MobileFaceNet etc.) expect pixel input in [-1, 1], but all three engines were normalizing to [0, 1] — causing inference scores to saturate and making threshold changes have no observable effect.

Normalization fix (tflite_engine.dart, onnx_engine.dart, onnx_directml_engine.dart)

// Before — incorrect range [0, 1]
data.add(px.r / 255.0);

// After — correct range [-1, 1] for MobileFaceNet-style models
data.add((px.r - 127.5) / 127.5);

Applied to both NHWC (TFLite) and NCHW (ONNX) preprocessing paths.

DirectML FFI (onnx_directml_ffi.dart)

  • Prefers onnxruntime-directml.dll over the standard DLL; falls back gracefully when absent
  • Adds proper FFI type definitions and resolves OrtSessionOptions_AppendExecutionProvider_DML at runtime; exposes isDirectMLFunctionAvailable and appendExecutionProviderDML()

DirectML engine (onnx_directml_engine.dart)

Documents the blocker: onnxruntime v1.4.x does not expose the OrtSessionOptions* raw pointer, so the DirectML provider cannot be injected via the high-level Dart API even when the DLL is present. XNNPACK is retained as the best available fallback; DLL detection result is logged.

pubspec.yaml

Added a comment: true DirectML GPU support requires onnxruntime-directml.dll (from Microsoft.ML.OnnxRuntime.DirectML NuGet) placed beside the executable. No separate onnxruntime_directml pub.dev package exists as of v1.4.1.

Note on items already implemented: Test-order shuffling (pairs.shuffle(_random)) and Android GpuDelegateV2 were already in place from a prior session.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: tqmane <149690876+tqmane@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix functionality for ai_image_test benchmarking app Fix pixel normalization in inference engines; improve DirectML FFI bindings Feb 18, 2026
Copilot AI requested a review from tqmane February 18, 2026 13:26
@tqmane tqmane marked this pull request as ready for review February 18, 2026 13:45
@tqmane tqmane merged commit e5b16d4 into main Feb 18, 2026
13 checks passed
tqmane added a commit that referenced this pull request Feb 18, 2026
…lity

Fix pixel normalization in inference engines; improve DirectML FFI bindings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants