ML.NET Object Detection

ML.NET Samplesにある、Object Detectionを動かしてみました。

github.com

Object Detectionサンプル

学習済みモデルTiny Yolo2を.NET Coreコンソールアプリ(+ML.NET)で動かすサンプルプログラムです。

実行

Visual StudioObjectDetection.slnを開いて実行するだけ。

こんな感じで、画像に含まれるオブジェクトをコンソールに表示します。

=====Identify the objects in the images=====

.....The objects in the image image1.jpg are detected as below....
car and its Confidence score: 0.9697261
car and its Confidence score: 0.6674223
person and its Confidence score: 0.5226038
car and its Confidence score: 0.5224892
car and its Confidence score: 0.4675334

.....The objects in the image image2.jpg are detected as below....
cat and its Confidence score: 0.6461141
cat and its Confidence score: 0.6400049

.....The objects in the image image3.jpg are detected as below....
chair and its Confidence score: 0.8405777
chair and its Confidence score: 0.7963627
diningtable and its Confidence score: 0.6056049
diningtable and its Confidence score: 0.3737413

.....The objects in the image image4.jpg are detected as below....
dog and its Confidence score: 0.7608147
person and its Confidence score: 0.6321325
dog and its Confidence score: 0.5967442
person and its Confidence score: 0.5730396
person and its Confidence score: 0.5551758

========= End of Process..Hit any Key ========

また、assets/images/output フォルダに、オブジェクトを検知した結果画像を保存します。

f:id:matsujirushix:20190901115438p:plain

処理時間

ここかな?というところに、Stopwatchを追加して測りました。

var sw = new System.Diagnostics.Stopwatch();
sw.Restart();
IList<YoloBoundingBox> detectedObjects = boundingBoxes.ElementAt(i);
sw.Stop();
Console.WriteLine($"Elapsed time = {sw.ElapsedMilliseconds}");

Surface Pro 4Core i7-6650U@2.20GHz)で、この結果でした。

Elapsed time = 1485
.....The objects in the image image1.jpg are detected as below....

Elapsed time = 1300
.....The objects in the image image2.jpg are detected as below....

Elapsed time = 1299
.....The objects in the image image3.jpg are detected as below....

Elapsed time = 1277
.....The objects in the image image4.jpg are detected as below....