mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
scripts: Update ML examples and library.
This commit is contained in:
parent
4506682c2d
commit
6fd7d56a85
@ -22,7 +22,7 @@ min_confidence = 0.4
|
|||||||
threshold_list = [(math.ceil(min_confidence * 255), 255)]
|
threshold_list = [(math.ceil(min_confidence * 255), 255)]
|
||||||
|
|
||||||
# Load built-in FOMO face detection model
|
# Load built-in FOMO face detection model
|
||||||
labels, model = ml.Model("fomo_face_detection")
|
model = ml.Model("fomo_face_detection")
|
||||||
|
|
||||||
# Alternatively, models can be loaded from the filesystem storage.
|
# Alternatively, models can be loaded from the filesystem storage.
|
||||||
# model = ml.Model('<object_detection_modelwork>.tflite', load_to_fb=True)
|
# model = ml.Model('<object_detection_modelwork>.tflite', load_to_fb=True)
|
||||||
@ -76,7 +76,7 @@ while True:
|
|||||||
if len(detection_list) == 0:
|
if len(detection_list) == 0:
|
||||||
continue # no detections for this class?
|
continue # no detections for this class?
|
||||||
|
|
||||||
print("********** %s **********" % labels[i])
|
print("********** %s **********" % model.labels[i])
|
||||||
for (x, y, w, h), score in detection_list:
|
for (x, y, w, h), score in detection_list:
|
||||||
center_x = math.floor(x + (w / 2))
|
center_x = math.floor(x + (w / 2))
|
||||||
center_y = math.floor(y + (h / 2))
|
center_y = math.floor(y + (h / 2))
|
||||||
|
|||||||
@ -28,10 +28,11 @@ class MicroSpeech:
|
|||||||
def __init__(self, preprocessor=None, micro_speech=None, labels=None):
|
def __init__(self, preprocessor=None, micro_speech=None, labels=None):
|
||||||
self.preprocessor = preprocessor
|
self.preprocessor = preprocessor
|
||||||
if preprocessor is None:
|
if preprocessor is None:
|
||||||
self.preprocessor = Model("audio_preprocessor")[1]
|
self.preprocessor = Model("audio_preprocessor")
|
||||||
self.labels, self.micro_speech = (labels, micro_speech)
|
self.labels, self.micro_speech = (labels, micro_speech)
|
||||||
if micro_speech is None:
|
if micro_speech is None:
|
||||||
self.labels, self.micro_speech = Model("micro_speech")
|
self.micro_speech = Model("micro_speech")
|
||||||
|
self.labels = self.micro_speech.labels
|
||||||
# 16 samples/1ms
|
# 16 samples/1ms
|
||||||
self.audio_buffer = np.zeros((1, _SAMPLES_PER_STEP * 3), dtype=np.int16)
|
self.audio_buffer = np.zeros((1, _SAMPLES_PER_STEP * 3), dtype=np.int16)
|
||||||
self.spectrogram = np.zeros((1, _SLICE_COUNT * _SLICE_SIZE), dtype=np.int8)
|
self.spectrogram = np.zeros((1, _SLICE_COUNT * _SLICE_SIZE), dtype=np.int8)
|
||||||
|
|||||||
@ -9,19 +9,10 @@ import image
|
|||||||
from ml.preprocessing import Normalization
|
from ml.preprocessing import Normalization
|
||||||
|
|
||||||
|
|
||||||
class Model:
|
class Model(uml.Model):
|
||||||
def __new__(cls, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
self = super().__new__(cls)
|
super().__init__(*args, **kwargs)
|
||||||
retobj = uml.Model(*args, **kwargs)
|
|
||||||
if isinstance(retobj, tuple):
|
|
||||||
labels, self.model = retobj
|
|
||||||
return labels, self
|
|
||||||
self.model = retobj
|
|
||||||
return self
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return str(self.model)
|
|
||||||
|
|
||||||
def predict(self, args, **kwargs):
|
def predict(self, args, **kwargs):
|
||||||
args = [Normalization()(x) if isinstance(x, image.Image) else x for x in args]
|
args = [Normalization()(x) if isinstance(x, image.Image) else x for x in args]
|
||||||
return self.model.predict(args, **kwargs)
|
return super().predict(args, **kwargs)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user