mlboydaisuke commited on
Commit
c2ceda0
·
verified ·
1 Parent(s): 5d103d6

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +24 -2
README.md CHANGED
@@ -93,8 +93,30 @@ for n, frame in enumerate(video_frames, start=1): # frame: [1,3,172,172], RGB,
93
  print("top-1:", int(logits.argmax()))
94
  ```
95
 
96
- A full Kotlin implementation (camera per-frame → top-5) is in the sample app's
97
- `ActionRecognizer.kt`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
  ## Conversion
100
 
 
93
  print("top-1:", int(logits.argmax()))
94
  ```
95
 
96
+ ### Kotlin (Android, LiteRT CompiledModel GPU)
97
+
98
+ ```kotlin
99
+ val options = CompiledModel.Options(Accelerator.GPU)
100
+ val model = CompiledModel.create(context.assets, "movinet_a0_stream.tflite", options, null)
101
+ val inBufs = model.createInputBuffers() // [0]=frame, [1..28]=stream, [29..44]=pool sums, [45]=inv_count, [46]=1.0
102
+ val outBufs = model.createOutputBuffers() // [0]=logits, [1..11]=current frames, [12..27]=fresh means
103
+
104
+ inBufs[46].writeFloat(floatArrayOf(1f)) // constant decoupler
105
+ // reset recurrent state (zeros) at the start of a clip; keep host-side stream buffers + pool sums
106
+
107
+ for ((n, frameNCHW) in videoFrames.withIndex()) { // frame: [1,3,172,172], RGB, 0..1
108
+ inBufs[0].writeFloat(frameNCHW)
109
+ inBufs[45].writeFloat(floatArrayOf(1f / (n + 1))) // inv_count
110
+ // (stream inputs 1..28 and pool inputs 29..44 already staged from the previous frame)
111
+ model.run(inBufs, outBufs)
112
+ val logits = outBufs[0].readFloat() // [600] Kinetics-600
113
+ // host-side: shift each stream buffer with the emitted current frame (outBufs[1..11]),
114
+ // and accumulate poolSum[i] += outBufs[12+i], then write both back to inBufs for the next frame.
115
+ }
116
+ ```
117
+
118
+ A full implementation (camera → per-frame → top-5, with the host-side shift register and pool
119
+ accumulation) is in the sample app's `ActionRecognizer.kt`.
120
 
121
  ## Conversion
122