mirror of
https://github.com/mit-han-lab/tinyengine.git
synced 2025-10-15 21:37:08 +08:00

* sparse training example on openmv cam * minor fix for openmv firmware compliation * python side code * mior * update README * remove fc only and update README * Update README.md * update news * update news * update link
32 lines
943 B
Python
32 lines
943 B
Python
# This example shows how to invoke to training or inference function calls of tinyengine.
|
|
import cexample
|
|
import lcd
|
|
import sensor
|
|
from pyb import Pin
|
|
|
|
sensor.reset() # Reset and initialize the sensor.
|
|
sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
|
|
sensor.set_framesize(sensor.B128X128) # Set frame size to QVGA (128x128)
|
|
lcd.init() # Initialize the lcd screen.
|
|
|
|
|
|
# class 1: green
|
|
pin4 = Pin("P4", Pin.IN, Pin.PULL_UP)
|
|
# class 0: red
|
|
pin1 = Pin("P1", Pin.IN, Pin.PULL_UP)
|
|
|
|
while True:
|
|
img = sensor.snapshot() # Take a picture and return the image.
|
|
|
|
pin4_value = pin4.value()
|
|
pin1_value = pin1.value()
|
|
if pin4_value == 0:
|
|
ret = cexample.train_demo(img, 0)
|
|
print("train class 0")
|
|
elif pin1_value == 0:
|
|
ret = cexample.train_demo(img, 1)
|
|
print("train class 1")
|
|
else:
|
|
ret = cexample.train_demo(img, -1)
|
|
lcd.display(img) # Display the image.
|