Image Classifier
Last updated
Last updated
from future import *
from koi2 import KOI2
koi = KOI2(tx, rx)
Initializes the serial connection to KOI.
Parameters:
tx: TX Pin, use P2 for Robotbit EDU
rx: RX Pin, use P12 for Robotbit EDU
koi.setModel(5)
Sets the KOI mode to Face Mask Detection.
koi.classifierAddTag(class)
Adds a sample into the image classifier model.
Parameters:
class: The name for the class.
from future import *
from koi2 import KOI2
koi = KOI2('P2', 'P12')
koi.setModel(5)
sleep(15)
koi.direction(2)
koi.mirror(0)
screen.sync = 0
while True:
koi.read_from_uart()
if sensor.btnValue('a'):
koi.classifierAddTag('A')
sleep(0.2)
if sensor.btnValue('b'):
koi.classifierAddTag('B')
sleep(0.2)
if koi.getBtnState('A'):
koi.classifierSave('/flash/'+'abc.json')
koi.strVal
Returns the result from the image classifier.
koi.getSimilarity()
Returns the similarity value of the image classifier result.
koi.classifierSave(location'+json)
Saves the classifier onto the location specified.
Parameters:
location: '/sd/' to save on SD card, '/flash/' to save on onboard memory.
json: file name, must end in '.json'
koi.classifierLoad(location'+json)
Saves the classifier onto the location specified.
Parameters:
location: '/sd/' to save on SD card, '/flash/' to save on onboard memory.
json: file name, must end in '.json'
koi.classifierGetMostSimilarResults()
Sets the similarity value to return the similarity to the result with highest similarity.
koi.classifierSetDetectionTarget(class)
Sets the similarity value to return the similarity to the class specified.
Parameters:
class: The name for the class.
koi.classifierReset()
Reset the Image Classifier and clears the unsaved training results.
from future import *
from koi2 import KOI2
koi = KOI2('P2', 'P12')
koi.setModel(5)
sleep(15)
koi.direction(2)
koi.mirror(0)
screen.sync = 0
while True:
koi.read_from_uart()
if sensor.btnValue('a'):
koi.classifierLoad('/flash/'+'abc.json')
sleep(0.5)
screen.fill((0, 0, 0))
screen.text(koi.strVal,5,10,2,(255, 255, 255))
screen.text(koi.getSimilarity(),5,40,2,(255, 255, 255))
screen.refresh()