ml.postprocessing.edgeimpulse --- Edge Impulse#

ml.postprocessing.edgeimpulse モジュールには、Edge Impulse モデル用の後処理クラスが含まれています。

class Fomo -- Fast Objects More Objects#

FOMO (Fast Objects More Objects) モデル出力用の後処理クラス。

class ml.postprocessing.edgeimpulse.Fomo(threshold: float = 0.4, w_scale: float = 1.414214, h_scale: float = 1.414214, nms_threshold: float = 0.1, nms_sigma: float = 0.001)#

FOMO の後処理関数を作成します。

threshold 検出が保持されるために必要な最小スコア。

w_scale 非最大抑制の前にグリッドセルの幅に適用される水平方向のスケール係数。値が大きいほど、隣接するセルが 1 つの検出にまとめられます。

h_scale 非最大抑制の前にグリッドセルの高さに適用される垂直方向のスケール係数。値が大きいほど、隣接するセルが 1 つの検出にまとめられます。

nms_threshold 非最大抑制に渡される IoU のしきい値。

nms_sigma 非最大抑制(soft-NMS)に渡されるシグマ値。

__call__(model: ml.Model, inputs: list, outputs: list) → list#

モデル、その入力、および生の出力を引数として ml.Model.predict() から呼び出されます。クラスごとの検出リストからなるリストを返します。各検出は ((x, y, w, h), score) タプルです。出力における各リストの位置がモデル出力のクラスインデックスと一致するよう、空のクラスリストも含まれます。何も検出されない場合は空のタプルを返します。

class YoloPro -- YOLO Pro#

Edge Impulse YOLO Pro 物体検出モデル出力用の後処理クラス。YOLO Pro モデルは候補ボックスごとに 1 行を出力し、各行には(入力に対して正規化された)xmin, ymin, xmax, ymax と、それに続くクラスごとのスコアベクトルが含まれます。このようなモデルの学習方法については YOLO Pro のドキュメント を参照してください。

class ml.postprocessing.edgeimpulse.YoloPro(threshold: float = 0.6, nms_threshold: float = 0.1, nms_sigma: float = 0.1)#

YOLO Pro の後処理関数を作成します。

threshold non-max-suppression の前にボックスが保持されるために必要な最小クラススコア。

nms_threshold 非最大抑制に渡される IoU のしきい値。

nms_sigma 非最大抑制(soft-NMS)に渡されるシグマ値。

__call__(model: ml.Model, inputs: list, outputs: list) → list#

モデル、その入力、および生の出力を引数として ml.Model.predict() から呼び出されます。クラスごとの検出リストからなるリストを返します。各検出は ROI 座標での ((x, y, w, h), score) タプルです。出力における各リストの位置がモデル出力のクラスインデックスと一致するよう、空のクラスリストも含まれます。何も検出されない場合は空のタプルを返します。

例:

import csi
import ml
from ml.postprocessing.edgeimpulse import YoloPro

csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)

model = ml.Model("/rom/<model_file_name>", postprocess=YoloPro(threshold=0.4))

while True:
    img = csi0.snapshot()
    for i, detections in enumerate(model.predict([img])):
        for (x, y, w, h), score in detections:
            img.draw_rectangle(x, y, w, h)
            print(model.labels[i], score)