Views
No views yet

.tflite — including the conv-based CQT front-end
(9 octaves, shared 36×256 kernel banks, lowpass downsample chain, no FFT). Bit-exact torch
re-implementation of the official ONNX (corr 1.000000). FP32, 0.84 MB.[1, 43844] float32 — 2 s @ 22 050 Hz mono, [-1, 1] (official window; overlap windows by
7 680 samples and keep center frames when stitching).contour [1,172,264], note [1,172,88], onset [1,172,88] — sigmoid posteriorgrams
(~11.6 ms frames; note/onset bins = MIDI 21–108).1import numpy as np, soundfile as sf
2from ai_edge_litert.interpreter import Interpreter
3
4wav, _ = sf.read("audio_22050.wav", dtype="float32") # mono 22.05 kHz
5x = np.zeros(43844, np.float32); n = min(len(wav), 43844); x[:n] = wav[:n]
6it = Interpreter(model_path="basicpitch.tflite"); it.allocate_tensors()
7it.set_tensor(it.get_input_details()[0]["index"], x[None]); it.invoke()
8contour, note, onset = (it.get_tensor(o["index"])[0] for o in
9 sorted(it.get_output_details(), key=lambda o: o["index"]))
10active = np.argwhere(note > 0.5) # (frame, key); midi = key + 21, t = frame * 256/220501// implementation("com.google.ai.edge.litert:litert:2.1.5")
2val model = CompiledModel.create(File(ctx.filesDir, "basicpitch.tflite").absolutePath,
3 CompiledModel.Options(Accelerator.GPU), null)
4val inBuf = model.createInputBuffers(); val outBuf = model.createOutputBuffers()
5inBuf[0].writeFloat(window43844) // 2 s @ 22.05 kHz mono
6model.run(inBuf, outBuf)
7val note = outBuf[1].readFloat() // [172 * 88], frame-major; midi = bin + 21
8val onset = outBuf[2].readFloat() // onset-triggered decoding -> note eventsnmp.onnx (102 constants; no TensorFlow). Reflect-pad →
anti-diagonal-constant FULLY_CONNECTED; PACK → concat + static slices. Two fp16-on-GPU fixes,
both exact: post-log clamp clamp(10·log10(p+1e-10), min=-100) (recovers log(0) from the
fp16-flushed floor; desktop no-op) and the per-bin CQT norm folded into per-octave kernel copies
(magnitude is linear in kernel scale). FP32 flatbuffer (fp16 weights cost ~0.005 corr on the tiny
CQT kernels).benchmark_model tool — 10 warm-up runs then 50 timed runs, reported as the tool's mean.| Runtime | Backend | Graph on GPU | Latency |
|---|---|---|---|
LiteRT CompiledModel (LITERT_CL) | GPU | 241 / 241 | ~4.4 ms |
TFLite benchmark_model (TfLiteGpuDelegateV2) | GPU (OpenCL) | 241 / 241 | did not run |
LITERT_CL figure is the one recorded when this model shipped, taken through LiteRT's own CompiledModel accelerator — the path the Kotlin sample app and the LiteRT API use. The TfLiteGpuDelegateV2 figure is the classic TFLite OpenCL delegate, measured with a tool anyone can download and re-run. They agree on how much of the graph the GPU takes; they disagree on speed, and the classic delegate is the slower of the two here. Read the TfLiteGpuDelegateV2 row as a reproducible floor, not as this model's speed on LiteRT.