mlboydaisuke commited on
Commit
b55da55
·
verified ·
1 Parent(s): 3fca56c

Add minimal usage snippets (Kotlin + Python)

Browse files
Files changed (1) hide show
  1. README.md +37 -0
README.md CHANGED
@@ -29,6 +29,43 @@ face[1,3,256,256] (mmpose mean/std) →[GPU: RTMPose-m]→ simcc_x[1,98,512], si
29
 
30
  output[0] = simcc_x, output[1] = simcc_y; each landmark = `argmax` over its 1D SimCC (bins = pixels × 2).
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  ## How it converts (litert-torch) — the RTMPose recipe, unchanged
33
 
34
  Same model family as the human-pose RTMPose; only the config/checkpoint change to WFLW. The two on-device-only
 
29
 
30
  output[0] = simcc_x, output[1] = simcc_y; each landmark = `argmax` over its 1D SimCC (bins = pixels × 2).
31
 
32
+ ## Minimal usage
33
+
34
+ **Android (Kotlin, CompiledModel GPU)**
35
+
36
+ ```kotlin
37
+ val model = CompiledModel.create(context.assets, "rtm_face_fp16.tflite",
38
+ CompiledModel.Options(Accelerator.GPU), null)
39
+ val inputs = model.createInputBuffers()
40
+ val outputs = model.createOutputBuffers()
41
+ inputs[0].writeFloat(chw) // [1,3,256,256] mmpose mean/std (0-255 RGB), NCHW
42
+ model.run(inputs, outputs)
43
+ val simccX = outputs[0].readFloat() // [1,98,512]
44
+ val simccY = outputs[1].readFloat() // [1,98,512]; keypoint = argmax / 2
45
+ ```
46
+
47
+ **Python (desktop verification)**
48
+
49
+ ```python
50
+ MEAN = np.array([123.675, 116.28, 103.53], np.float32)
51
+ STD = np.array([58.395, 57.12, 57.375], np.float32)
52
+ import numpy as np
53
+ from PIL import Image
54
+ from ai_edge_litert.interpreter import Interpreter
55
+
56
+ img = Image.open("face.jpg").convert("RGB").resize((256, 256)) # centered subject crop
57
+ x = ((np.asarray(img, np.float32) - MEAN) / STD).transpose(2, 0, 1)[None]
58
+
59
+ it = Interpreter(model_path="rtm_face_fp16.tflite"); it.allocate_tensors()
60
+ it.set_tensor(it.get_input_details()[0]["index"], x); it.invoke()
61
+ od = it.get_output_details() # output 0 = simcc_x, 1 = simcc_y
62
+ sx = it.get_tensor(od[0]["index"])[0] # simcc_x [98,512]
63
+ sy = it.get_tensor(od[1]["index"])[0] # simcc_y [98,512]
64
+ kx, ky = sx.argmax(-1) / 2.0, sy.argmax(-1) / 2.0 # 98 keypoints, px in 256x256
65
+ for i, (a, b) in enumerate(zip(kx, ky)):
66
+ print(f"kp{i}: ({a:.1f}, {b:.1f})")
67
+ ```
68
+
69
  ## How it converts (litert-torch) — the RTMPose recipe, unchanged
70
 
71
  Same model family as the human-pose RTMPose; only the config/checkpoint change to WFLW. The two on-device-only