W&T's diary

W&T Thermal Cam に関連する情報

Thermal Cam の AI機能について Thermal Cam AI function(Yolo v3 Object Detection)

新しいThermal Cam は Our new feature of Thermal Cam

画像認識機能が付いています。Thermal Camの特徴は暗視カメラであることと、携帯端末とカメラを分離できることです。カメラ自体が非常に軽量で、ESP8266を使用した場合には電波の飛距離が伸び、さらに自由に入れ替え可能な画像認識AIが加わるため様々な応用が可能になりました。ただし、Thermal Cam アプリをダウンロードしただけではAI機能を実行できません。下記を参考にしてまず学習済みファイルをダウンロードして下さい。

We add object detection for  thermography. One of feature for Thermal Cam is night vision and our system is divided display from FILR sensor.

ESP8266 helps to transmit WiFi longer and light weight low battery consumption all at the same time.

Furthermore, various applications are possible by adding image recognition AI.

However, AI function cannot be executed just by downloading Thermal Cam application. Please download the Pre-learned file first referring to the following.

ESP8266 helps to transmit WiFi longer and light weight low battery consumption all at the same time.

Furthermore, various applications are possible by adding image recognition AI.

However, AI function cannot be executed just by downloading Thermal Cam3x application. Please download the Pre-learned file first referring to the following.

f:id:TAKEsan:20191107133217p:plain

特徴は?    New feature ?

  • iPhone Xs,Xs Maxm,Xr,11,11 Pro,11Pro Max,iPad Pro 11,12.9inchに関して (A12,A13 Bionicを使っているiPhone,iPad)、「設定」YOLO ONトグルスイッチをONにすることで画像認識機能が働きます。*1
  • 認識エンジンはYOLOv3を使用しています。これはTiny版ではないので優れた認識能力を発揮します。
  • 学習済みファイルが自由に選択可能で、ユーザー自身が用意したWeightデータを使用することができます。*2
  • 認識結果を利用して、英語または日本語の音声、アラーム、カメラフラッシュ対象物の認識個数表示、タイムスタンプ表示をユーザーが自由に設定できます。*3 

f:id:TAKEsan:20191109223950p:plain

認識結果のアラートや対象物(以降Class)の表示名称を自由に変更することが可能です。これには一般テキストファイルの編集ソフトが必要です。「Edidown」の事前インストールをおすすめします。

For iPhone Xs, Xs Max, 11, 11 Pro, and 11 Pro Max, the image recognition function works by turning YOLO ON toggle switch at the setting of iPhone.

* 1 The recognition engine uses YOLOv3. Since this is not a Tiny version, it demonstrates excellent recognition ability.Pre-learned files can be freely selected, and the weight data prepared by the user.

* 2 Using the recognition results, the user can freely set Siri voice in English or Japanese, alarm, camera flash and display number of objects recognized, time stamp.

* 3 You can freely change the above alert and the text of the target object (hereinafter referred to as Classification). This requires a general text file edit software. Although it is a paid application, it is recommended to install “Textor” or "Edidown" in advance.

Thermal Cam BOSON版は

赤外線画像の他に、BOSONが接続されていない場合は。iPhoneカメラ画像に切り替わります。カメラ画像についても下記の画像認識アラートが使えます。また認識した同一クラスの対象物について、中央付近81点の温度測定を行い最高温度を表示するコマンドを新しく追加しました。

 

1.学習済みファイルのダウンロード方法 How to download Pre-learned files

画像認識をさせるには、まず学習済みデータのダウンロード作業が必要です。学習済みファイルは100Mbyte~250Mbyteの大きさになりますので、自身のiPhone容量を確認してから使用して下さい。

現在ダウンロードできる物体認識モデルは、以下の3種類です。Thermal Cam3xThermal Cam Bではデータ内容が違いますのでご注意ください。

a)は赤外線画像用、b),c)は一般カメラ画像用に特化したデータです。

 Thermal Cam 3X用データ

a)   https://drive.google.com/file/d/1IzfCwoilTfw-8zrgSAWc8zM16P8I4N-Z/view?usp=sharing

(LEPTON赤外線画像を対象:車、人間、自転車、大型車両、歩道、犬、グー、チョキ、パー、顔の認識 32Bit

b)  https://drive.google.com/file/d/1fHe5Czv4wO1UaygwHsb6vCT5iuHVc-gr/view?usp=sharing

(標準RGB画像が対象:80種類の物体検出で、赤外線カメラでどの程度認識するかを確認するための試験用データ。一般的なCOCOです 16bit)

c)  https://drive.google.com/file/d/1o-PyBH9AztUpAsSc6QfZmyzi7bhfnkHz/view?usp=sharing

(標準RGB画像が対象:80種類の物体検出で、赤外線カメラでどの程度認識するかを確認するための試験用データ。一般的なCOCOです 32bit

 Thermal Cam B用データ

a)  https://drive.google.com/file/d/1MHE-uPRZvWx3CIAAe-lWHChLa3xnzk1h/view?usp=sharing

(LEPTON赤外線画像を対象:車、人間、自転車、大型車両、歩道、犬、グー、チョキ、パー、顔の認識 32Bit

b)  https://drive.google.com/file/d/1AgJYFT9N56wRX_MulEPgEu01K7Ih3hil/view?usp=sharing

(標準RGB画像が対象:80種類の物体検出で、赤外線カメラでどの程度認識するかを確認するための試験用データ。一般的なCOCOです 16bit)

c)  https://drive.google.com/file/d/18fF6tw_krbSJlepeqp9rMJ946BjjTM39/view?usp=sharing

(標準RGB画像が対象:80種類の物体検出で、赤外線カメラでどの程度認識するかを確認するための試験用データ。一般的なCOCOです 32bit

ダウンロード方法を以下に説明しますが、URLを指定してダウンロードしたzipファイルを解凍後、Thermal Cam3x専用フォルダに入れるだけなので、手順に惑わされないようにして下さい。

To perform image recognition, you must first download the Pre-learned data. The Pre-learned file will be 100Mbyte ~ 250Mbyte, so to start with, please use one of them after checking your own iPhone capacity.

The following three types of the Pre-learned models is available at the moment.

a) https://drive.google.com/file/d/1LGmp1Y62Y1egbhEUtFuzissI4PWZNVt4/view?usp=sharing

(Target LEPTON infrared image: recognition of car, human, bicycle, large vehicle, sidewalk, dog 16bit)

b) https://drive.google.com/file/d/1XiEgkwlJctOlpsCYdVwl3Ud_QCfF-jCd/view?usp=sharing

(Target LEPTON infrared image: recognition of car, human, bicycle, large vehicle, sidewalk, dog 32bit)

c) https://drive.google.com/file/d/1au2JzuK7hJxnvbMluZ6eoPiqo0PPAJh9/view?usp=sharing

(Standard RGB image is targeted: 80 kinds of object detection, test data to confirm how much is recognized by infrared image. This is a general COCO 16bit)

d) https://drive.google.com/file/d/1q4UDFE3LKq55nRMRBTlLQjihtcBXIPrL/view?usp=sharing

(Standard RGB image is targeted: 80 kinds of object detection, test data to confirm how much is recognized by infrared image. This is a general COCO 32bit)

The download method is explained below, but please specify the URL and unzip the downloaded zip file, and then put it in the folder dedicated to Thermal Cam3x.

1.1 サファリの設定からダウンロード先を選択します。Select the download destination from iPhone Safari settings

サファリのダウンロード先を自分のiPhoneに変更します。標準ではiCloudとなっていますが操作が慣れてからiCloudに変更することをおすすめします。

Change the safari download location to your iPhone internal file. Although iCloud is the standard download location, we recommend to change to iCloud after getting used of it.

f:id:TAKEsan:20191110203225p:plain

1.2 上記のアドレスの中から学習データを選択します。Select Pre-learning data from the above addresses.

最初はa)を選択してみて下さい。ジャンケンの手の形や顔も判定できるので、手元で確認するには十分だと思います。どんな角度でも面白いようにジャンケンの手の形を判断する様子を確認できると思います。赤外線カメラの特徴としてWeb Cameraのように車などの画像を写しても対象物を手軽に判断できません。熱を発生する実物である必要があります。つまり手の形なら卓上ですぐに判定可能で、車の判定をさせるには外に出て実際の車を写さなければなりません。

First of all, select b).

Rock-Paper-Scissors✌️ of your hand or your face😃 can be detected, good enough to check feature to start with. You can see how to judge the shape of your hand and our model can detect at any angle of your hand. As a feature of the infrared camera, even if a thermal image of a car captured like Web Camera, the target cannot be easily determined. It must realy generate heat. In other words, if it is in the shape of a hand, it can be judged immediately at home, and in order to judge the car, you must go outside and capture the actual cars.

f:id:TAKEsan:20191110203327p:plain

1.3 ファイルアプリを開き以下の操作を実行します。Open the file app and do the following:

標準でインストールされているファイルアプリは、多少のコツが必要です。事前にファイルのコピー方法などを試してから以下に進んで下さい。特にiCloudの中にいるのか自分のiPhoneに入っているのか練習で感覚をつかむ必要があるようです。

The file app that is installed by default requires some tips. Please try the file copy method in advance.

And then proceed to the following. In particular, it seems to be necessary to practice whether you are in iCloud or in your iPhone internal file.

f:id:TAKEsan:20191110203408p:plain

このiPhone内->Download を選択します。ダウンロードが完了していれば、w_t.zip が確認できます。

Select This iPhone-> Download. When the download is complete, you can check w_t.zip.

f:id:TAKEsan:20191110203505p:plain

解凍した後はzipファイルが必要なくなるのでこれを削除、解凍したフォルダをアプリ専用のフォルダ(Thermal Cam3x又はThermal Cam Bフォルダ)に移動します。

After unzipping, the zip file is no longer needed, so delete it and move the unzipped folder to a folder dedicated to the app (Thermal Cam3x or Thermal Cam B folder).

f:id:TAKEsan:20191110203550p:plain

Thermal Cam3x 又は Thermal Cam B のフォルダを選択し、w_tフォルダを移動します。

Select the Thermal Cam3x folder and move the w_t folder.

f:id:TAKEsan:20191110203740p:plain

ダウンロードしたフォルダ名称はすべてw_tとなります。下図のように1つのフォルダと3つのテキストファイルが確認できます。内容を識別するにはw_tフォルダクリックしてREADME等のファイル内容を確認して下さい。また、w_t.namesファイルで何が認識できるか確認することができます。テキストファイルを編集することで拡張が可能ですが、編集作業はiPhone標準アプリではできないようなので、テキストファイル編集専用アプリ「Textor」などで作業を行う必要があります。

他のテキストファイル編集アプリ

  • Edidown(無料アプリ):現在はこれがおすすめです
  • Pythonista(有料アプリ:編集機能使用)

※現在Textorはアプリストアで公開されていません。GitHub - louisdh/textor: A plain text editor for iOSからダウンロードしてコンパイルする必要があります。

All downloaded folder names will be w_t. You can check one folder and three text files as shown below. Click the w_t folder to check the contents of files such as README. You can also check what can be recognized in the w_t.names file. Although it is possible to extend by editing the text file, editing work seems to be impossible with the iPhone standard application, so it is necessary to work with text file editing application “Textor” etc.

Other text file editing apps

  • Edidown(Free app:I recommend this now)
  • Pythonista (paid app:using editing function)

* Thor is not currently available on the app store. GitHub-louisdh / textor: Must be downloaded from A plain text editor for iOS and compiled.

f:id:TAKEsan:20191110204118p:plain

ファイル内容は以下の通りです。iPhoneでは拡張子が確認できない場合があるので注意して下さい。

  • w_t.mlmodelc 学習済みファイルが入ったフォルダ。内容は絶対変更しないで下さい。
  • w_t.names クラスの名称を改行コードを挟んで書き込んであります。この名称を使ってバウンディングボックスのクラス名称が表示されます。名称の変更が可能ですが、変更する場合は日本語に対応していない点と、全体の行数を変えないよう注意して下さい。あらかじめ作られた画像認識モデルは認識数が限定されています。
  • w_t.txt 認識後のアラートと、全体の認識率(しきい値)を設定するファイルです。このファイルのパラメーターを変更することで、認識結果に関するアラートを様々な形で変更できます。内容や変更方法は「3.認識結果アラートの設定方法」を確認して下さい。
  • README.txt ダウンロードした学習済みファイルの特徴が記入されています。

The file contents are as follows. Please note that the extension(.txt & .names) may not be confirmed on iPhone.

w_t.mlmodelc Folder containing Pre-learned files.

Never change the contents.

w_t.names

The name of the class is written across the line feed code(/n). The class name of the bounding box is displayed using this name. You can change the name, but please be careful not to change in Japnese(must not be 2bites language) and  the total number of lines. Pre-made image recognition models have a limited number of recognitions.

w_t(.txt)

This file sets alerts after recognition and the overall recognition rate (threshold). By changing the parameters in this file, you can change alerts related to recognition results in various ways.

Please confirm “3. Setting method of recognition result alert” for contents and change method.

README.txt

Contains the characteristics of the downloaded learned file.

2.画像認識スタート Start image recognition

 設定で選択すると、Thermal Cam 画像認識が開始されます。通常GPUをフルに使うと携帯端末がかなりの熱を帯びてきますが、今回のアプリはスピードをコントロールしているので極端に熱くはなりません。ただしポケットなどに入れてアプリを動かすことはなるべく避けて下さい。また電池の消耗が早いので、電池残量に気をつけて使用することをお勧めします。長時間使用する場合には電源を確保することと、携帯端末用の冷却ファンを使用して下さい。

When selected in Thermal Cam settings, Thermal Cam3x image recognition starts.

Normally, when you use the GPU(A13 Bionic) fully, your mobile device gets a lot of heat, but this app does not get extremely hot because it controls the speed. However, avoid walk with running the app in a pocket. In addition, caution as the battery is consumed quickly. When using for a long time, ensure the power supply and use a cooling fan for iPhone.

f:id:TAKEsan:20191110204200p:plain

3.認識結果アラートの設定方法 Setting recognition result alert

下図は「Textor」の編集画面でw_t.txtを開いた画像です。ここではそれぞれの設定内容を説明します。=を含めた左側の文字は変更しないで下さい。また、=の右側には必ず数値か文字を記入する必要があります。指定範囲外の数値を記入した場合は、標準値が適用されるので注意して下さい。

The figure below is an image of w_t.txt opened on the “Textor” editing screen. This section explains each setting. Do not change the characters on the left-hand side including the =. In addition, it is necessary to enter a numerical value or a character on the right side of =. Please note that the standard value will be applied if a value outside the specified range is entered.

f:id:TAKEsan:20191110204434p:plain

  • conf_all=0.4   全体の認識率(認識できるクラスのすべて)のしきい値を設定します。この値は0.1~0.9の範囲です。数値を小さくすると誤認識が多くなります。標準は0.4です。
  • iou_all=0.3   バウンディングボックスの重複係数を指定します。この値は0.1~0.9の範囲です。この数値を大きくすると同じクラス名での重複するバウンディングボックスが増えて画像がうるさくなります。標準値は0.3です。     

conf_all = 0.4

Set the threshold for the overall recognition rate (all classes that can be recognized). This value ranges from 0.1 to 0.9. Decreasing the number increases misrecognition. The standard is 0.4.

iou_all = 0.3

Specifies the overlap factor of the bounding box. This value ranges from 0.1 to 0.9. Increasing this number will increase the number of overlapping bounding boxes with the same class name and make the image annoying. The standard value is 0.3.

f:id:TAKEsan:20191110204943p:plain

iou_allを0.9にした場合の画像です。バウンディングボックスが重複してしいます

これらの数値の調整やダイナミックレンジスライダーの調整で、対象クラスの焦点を絞ることが可能です。また、学習モデルにより微妙に変更する必要がある場合があります。

以下の設定は、指定したクラスについて認識結果を基に特殊なアラートを出します。今のところ対象クラスは1種類だけとなります。

  • class=7 学習済みファイルのクラス数又は0を指定します。対象とするクラス番号です。w_t.namesに書き込んであるクラス名称の先頭番号を1として指定します。アラートが必要ない場合は0を記入します。下図の場合でclass 7はGooを指します。

By adjusting these values and adjusting Dynamic Range !! slider, you can focus on the target class. It may also need to be changed slightly depending on the Pre-learning model.

The following settings issue a special alert based on the recognition result for the specified class. Currently there is only one target class.

class = 7

Specify the number of classes of Pre-learned files or 0. The target class number. Specify 1 as the top of the class name written in w_t.names. Enter 0 if no alert is required. In the case shown below, class 7 refers to “Goo”.

    f:id:TAKEsan:20191110205031p:plain

  • conf=0.7 対象とするクラスのしきい値を入力します。0.7とした場合は、対象とするクラス番号7が70%以上の認識率であった場合、アラート処理を実施するという意味になります。0.1~0.99の範囲で指定します。標準値は0.7です。
  • disply=1   画面左下にクラス名称などを表示させます。  

  0 :画面左下にクラス名称の表示は行いません。
  1 :画面の左下に対象とするクラス名称と同一画面に映った対象物の数を表示します。      

conf = 0.7

Enter the target class threshold. When 0.7 is set, it means that alert processing is executed when the target class number 7 has a recognition rate of 70% or more. Specify in the range of 0.1 to 0.99. The standard value is 0.7.

disply = 1 : Class name etc. are displayed at the lower left of the screen.

0: Class name is not displayed at the bottom left of the screen.     

f:id:TAKEsan:20191110205143p:plain

    2 バウンディングボックスの数値部分をタイムスタンプに変更します(標準は認識率表示)。この設定は指定クラスに依存しません。

 

f:id:TAKEsan:20191110205359p:plain

   3 BOSON版のみで機能します。クラス名称のみ表示され数値は表示されません

2: Change the numerical part of the bounding box to the time stamp (standard is the recognition rate display). This setting does not depend on the specified class.

  • thermals=0.9   BOSON版のみで機能します。0以外でメモリー機能ON。数値を記入すると、メモリーした温度がここで指定した温度以上の場合に以下のcountry命令を実行します。thermalsに0以外の数値を記入した場合、カーソル指示はできなくなりカーソルは中央固定になります。1回タップで class,conf の条件に合った対象物を認識した場合、認識した対象物中心の32x64ポイント(2048点)の中の最高温度を記憶。ダブルタップでメモリーがクリヤされます。温度が記憶された段階で、認識した対象物の中心部温度(2048点の最高温度)とメモリー温度との差が表示されます。メモリークリヤすると、温度表示は対象物の温度表示に切り替わります。一度メモリー登録をするとダブルタップするまでメモリーは消えません。メモリーした温度が少し違う場合は、すぐダブルタップして「メモリー解除->温度を見ながらシングルタップ」を繰り返します。メモリー登録中はカーソルを移動すると右の9x9画像表示が変わります(中の温度も)小さくて見にくいですが一応カーソル温度も確認できます。thermalsを0にすれば一般機能に戻ります。また、この機能が働いている場合、display機能は無視されます。

f:id:TAKEsan:20200419111825p:plain

例)class=8(チョキ)conf=0.7、thermals=0.3の場合。

thermalsの数値が0以外でメモリーがクリア状態の場合(右中央の温度表示が画像中央のカーソル部分の温度が白で表示)は、display、country命令は無視されます。そして画像上のチョキである確率が70%以上のとき、バウンディングボックス中央部にカーソルが現れて、バウンディングボックス中央を中心に2048点の中での最高温度を表示します。複数のチョキが現れた場合は、高い温度の方のカーソル中央部に黒丸が表示されます(画像左側のチョキ)。標準機能に戻すにはthermals=0である必要があります。

 

f:id:TAKEsan:20200419111945p:plain

例)class=8(チョキ)conf=0.7、thermals=0.3かつ事前に計測した温度がメモリーされている場合

thermalsの数値が0以外でメモリー状態の場合(右中央の温度表示はメモリーされた温度を緑で表示)は、country命令が実行されます。つまり、「country=ja  voice=発熱者が発見されました 」であれば、画像上のチョキである確率が70%以上で、かつメモリー温度との差が0.3以上の場合Siriは「発熱者が発見されました」と警告します。標準機能に戻すにはthermals=0である必要があります。

  • country=us    アラートの種類を指定します。(すべて英半角2文字で指定)   

   ja又はus指定した認識率以上であれば英語または日本語で以下voiceに書き込まれた文章を読み上げます。

   so  soundの略。指定した認識率以上であれば、警戒音を出します。口笛の音限定です。

   fl   flashの略。指定した認識率以上であればカメラのフラッシュを2回発光します。

  • voice= Please_note_that_is_a_car

countryをja又はusとしたときに発声する文章を記入します。英語の場合は60文字以内、日本語の場合は30文字以内で、なるべく1.5秒以内で終了する文章を記入して下さい。英語の場合は、空白部分を必ずアンダーバーに置き換えて下さい。jaに設定した場合で英語表記をすると英語発声が非ネイティブになります。

この設定例でclass番号を3に変更した場合、例えばLEPTON端末を自転車の後ろに設置して、iPhoneアプリを実行させ、後ろから70%以上の認識率の車が迫ってくると Please note that is a car !! とiPhoneが教えてくれます。日本語指定の場合は「車が来ます」でも良いですね。赤外線カメラですから当然真夜中でも!!

country = us

Specify the type of alert.(All specified with two single-byte characters)

ja or us: If the recognition rate is higher than the specified rate, the text written in the Siri voice below will be read out in us=English or ja=Japanese.

so: Abbreviation for “sound”. If the specified recognition rate is exceeded, a warning sound is emitted. Only “whistling” sounds.

fi: Abbreviation for flash. If the specified recognition rate is exceeded, the camera flash will fire twice.

voice = Plaese_note_that_is_a_car

Enter the text to be uttered when country is ja or us. For English, enter up to 60 characters, for Japanese(2bites), up to 30 characters. it should be sound within 1.5 seconds.

For English, be sure to replace the blank with an underscore(_). If it is set to ja and English is used, English utterance will be non-native.

If you change the class number to 3 in this setting example, for example, if you install the LEPTON terminal behind the bicycle and run the iPhone application, if a car with a recognition rate of 70% or more approaches from the back, Plaese note that is a car !! and iPhone(Siri) will tell you. In the case of ja, “car will come” is also in Japanese. Of course, it’s an infrared camera, even at midnight ! !

f:id:TAKEsan:20191107125316p:plain

実際に実現させたら.....。特に自転車では危険な細い道ではアラーム効果の利点が確実に体験できました。実際には左下にCarと表示された認識率70%段階でアラームが鳴っています。(開発段階の動画です)

Actually tested … The advantage of the alarm effect was definitely experienced on the narrow roads that are particularly dangerous for bicycles. Actually, the alarm is sounding at the recognition rate of 70% displayed as Car in the lower left. (This is a video at the development stage.)

 

 w_t.txtの内容を「textor」等で編集してDoneで保存した場合、すぐに設定が反映されますので、変更しながら最適なアラートを見つけて下さい。

When you edit the contents of w_t.txt with “textor” and save it with Done, the settings will be reflected immediately, so find the best alert while changing your setting.

-----------------------------------------------------------------------------------------------------

4.YOLOv3学習済みファイルの変換方法 How to make YOLOv3 Pre-learned files.

ここからは十分に経験と知識のある方、NVIDIAGPUを積んだLinuxマシンが動く環境が使える方が対象です。最初は非常に複雑なインストール作業を伴いますが、2回目以降はさほどでもありません。概要は以下の通りです。内容を理解した段階でMac側の一連の作業をPython等にまとめると効率が上がります。

linuxマシンで学習->学習済みweightsファイルをmacにコピー->h5ファイルに変換->coremlファイルに変換->coremlcファイルに変換->txtファイルを3つ作成-->zipに圧縮 

From here, it is for those who have sufficient Deep learning experience and knowledge, and who can use an environment where Linux machines with NVIDIA GPUs can run. The first involves a very complex installation(according to https://github.com/AlexeyAB/darknet), but not much after the second time. The outline is as follows. When you understand the contents, you can improve the efficiency by grouping a series of tasks on the Mac side into Python.

Learning on linux machine-> Copy learned weights file to mac-> Convert to h5 file-> Convert to coreml file-> Convert to coremlc file-> Create three txt files-> Compress to zip

4.1 録画した赤外線画像データをアノテーションする。Annotating LEPTON images and learning

学習データ画像はThermal Cam3xで録画したファイルを使います。アノテーション及び学習方法はこのページを参照して下さい。

YOLOオリジナルデータの学習 - Take’s diary

YOLOオリジナルデータの学習その2(追加学習) - Take’s diary

さらに詳しい内容は以下URLを参考にして下さい。

darknet/cfg at master · AlexeyAB/darknet · GitHub

 

iOSで実行するためには特に以下の設定が必要です。

  • 設定ファイル(CFGファイル)は yolov3-voc.cfg又はyolov3.cfgを使用します。
  • 入力画像の大きさは with=416 heights=416 限定です。
  • YOLOv3.cfgの設定ファイルは参考ページにも説明していますが、classがらみで合計10カ所以上の変更が必要です
  • 学習の収束を早めるための初期weightsファイルは、darknet53.cov.74をダウンロードして使用します。

The learning data image uses a file recorded with Thermal Cam3x. Please refer to this page for annotation and learning methods.

YOLOオリジナルデータの学習 – Take’s diary

YOLOオリジナルデータの学習その2(追加学習) – Take’s diary

Please refer to the following URL for further details.

darknet/cfg at master · AlexeyAB/darknet · GitHub

In order to run on iOS, the following settings are required.

Use yolov3-voc.cfg or yolov3.cfg as the configuration file (CFG file).

The size of the input image is limited to with = 416 heights = 416.

The configuration file of YOLOv3.cfg is also explained on the reference page, but it is necessary to change a total of 10 or more locations in relation to the class

Download and use darknet53.cov.74 as the initial weights file to speed up learning convergence.

4.2 MacにYAD2Kをインストールする。Install YAD2K on your Mac.

以下python3.7用のanaconda環境を作り、YAD2K及びkerasをインストールします。インストール方法は各々冒頭に記述されています。ただし最初のKerasインストール時はTensorflowインストールコマンドのみ conda install -c anaconda tensorflow==1.14 つまりtensorflowのバージョンは1.14にして下さい。

Create Anaconda environment for python3.7 below and install YAD2K and keras. Each installation method is described at the beginning. However, when installing Keras for the first time, only the Tensorflow installation command is used. Conda install -canaconda tensorflow == 1.14 That is, tensorflow version should be 1.14.

GitHub - allanzelener/YAD2K: YAD2K: Yet Another Darknet 2 Keras

GitHub - qqwweee/keras-yolo3: A Keras implementation of YOLOv3 (Tensorflow backend)

4.3 Kares を使ってYOLO学習済みファイルをコンバートする Convert files created in 4.3 to mlmodel

keras-yolo3-masterフォルダに入ってから、以降もanaconda環境の中で作業を行います。

まずconvert.py を実行しますが、このままではエラーが出てしまうので、convert.pyの88行目をinput_layer = Input(shape=(416, 416, 3))に変更します。

次に、同じディレクトリへ該当するweightsファイル、そして学習で使ったcfgファイルを入れておきます。

cfgファイルのはじめに設定しているパラメーターを bach=1 subdivisions=1に変更しておき、以下のコマンドで 新たにh5ファイルを作成します。cfg、weightファイル名はコピーしたそれぞれのファイル名に変更し、.h5ファイルは好きな名称を付けます。

この例ではdataフォルダにh5ファイルができます。

After entering the keras-yolo3-master folder, the following work is also performed in the anaconda environment.

First of all, convert.py is executed, but an error will occur if this is done, so change the 88th line of convert.py to input_layer = Input (shape = (416, 416, 3)).

Next, put the corresponding weights file in the same directory and the cfg file used for learning.

Change the parameter set at the beginning of the cfg file to bach = 1 subdivisions = 1, and create a new h5 file with the following command. Change the cfg and weight file names to the copied file names, and give the .h5 file a name of your choice.

In this example, an h5 file is created in the data folder.

./convert.py yolov3.cfg yolov3.weights model_data/yolo.h5

4.4 4.3でできたファイルをmlmodelに変換する

Apple 提供のcoremltoolsをインストールします

pip install coremltools

新たにフォルダを作成し(yolo_coremlと仮定)

mkdir yolo_coreml

cd yolo_coreml

以下のpythonプログラムを作成します

この中で3行目の ../../keras-yolo3-master/model_data/yolo.h5 は先ほど作成したh5ファイルを指定して下さい。

Install coremltools provided by Apple

pip install coremltools

Create a new folder (assuming yolo_coreml)

mkdir yolo_coreml

cd yolo_coreml

Create the following python program

In this, please specify the h5 file created earlier for ../../keras-yolo3-master/model_data/FLIR_J.h5 on the third line.

coreml.py

--------------------------------------------------------------------------------------------------

import coremltools

 

coreml_model = coremltools.converters.keras.convert('../../keras-yolo3-master/model_data/yolo.h5', input_names='input1', image_input_names='input1',  image_scale=1/255.)

coreml_model.input_description['input1'] = 'Input image'

 

coreml_model.author = 'Original paper: Joseph Redmon, Ali Farhadi'

coreml_model.license = 'Public Domain'

coreml_model.short_description = "The YOLOv3 network from the paper 'YOLOv3: An Incremental Improvement'"

 

coreml_model.save('w_t.mlmodel')

 --------------------------------------------------------------------------------------------------

python coreml.py

の実行で、フォルダ内にw_t.mlmodelファイルが作成されます。多少時間がかかります。

python coreml.py

Execution will create a w_t.mlmodel file in the folder.

4.5 標準では32ビットデータなのでデータ容量を減らしたい場合は16bitに変換する Standard is 32-bit data, so if you want to reduce the data capacity, convert it to 16-bit

16bitモデルは認識率が多少落ちるので、用途に応じて対応して下さい。16bitモデルに変更する場合は以下のpythonプログラムを作成して実行します。

The 16bit model has a slightly lower recognition rate. To change to the 16bit model, create and execute the following python program.

convert16.py

--------------------------------------------------------------------------------------------------

import coremltools

model_spec = coremltools.utils.load_spec('./w_t.mlmodel')

model_fp16_spec = coremltools.utils.convert_neural_network_spec_weights_to_fp16(model_spec)

coremltools.utils.save_spec(model_fp16_spec, 'w_t.mlmodel')

--------------------------------------------------------------------------------------------------

4.6 mlmodelをmlmodelcに変換する Convert mlmodel to mlmodelc

mlmodelコンパイルしてmlmodelcファイル(実はフォルダ)を作成します。必ず最終ファイル名はw_t.mlmodelcであることを確認して下さい。

Compile mlmodel and create mlmodelc file (actually folder). Make sure that the final file name is w_t.mlmodelc.

/Applications/Xcode.app/Contents/Developer/usr/bin/coremlc compile w_t.mlmodel ./

4.7 さらに3つのファイルを用意する Prepare 3 more files

w_t.names   : 学習に使ったクラス名称ファイルで、ファイル名称を変更して使用します。

w_t.txt   :「3.認識結果アラートの設定方法」を参考にして下さい・

REDME.txt :名称、内容とも任意で、実際には使用しません。今回の作業ファイルはすべて同じ名称にしなければないので、後から確認できるようにデータ内容の説明を記入して下さい。

w_t.names : The class name file used for learning is used by changing the file name.

w_t.txt        : Refer to “3. Setting method of recognition result alert”.

REDME.txt : Name and content are optional and are not actually used. All work files must have the same name, so please enter a description of the data so that you can check it later.

4.8 合計4つのファイルを新たに作成したw_tフォルダに移動する Move a total of 4 files to the newly created w_t folder

w_tフォルダを作成して、中にw_t.mlmodelcフォルダ、w_t.names、w_t.txt.、README.txtをコピーします。

Create a w_t folder and copy the w_t.mlmodelc folder, w_t.names, w_t.txt., and README.txt into it.

4.9 フォルダをzipに変換して自分のアカウントを持つicloudへuplodeする Convert folder to zip and uplode to icloud with your account

w_tフォルダをzipに圧縮します。iPhoneから一番使いやすいダウンロード先はiCloudです。今回のThermal Cam3xはフォルダ名がw_t限定なので、モデル毎にフォルダ管理して下さい。

Compress the w_t folder to zip. The easiest download location for iPhone is iCloud. Since this Thermal Cam3x folder name is limited to w_t, please manage folders for each model.

 

最後に Finally

Thermal Cam はOSCを使ってデータを送受信していて、OSC通信を使ったシンセサイザーや、複数のESP8266、コンピュータとの交信が可能です。また今回のバージョンはユーザーが用意した画像認識データを自由に利用できるAI画像認識に対応できたので、赤外線カメラを利用したいろいろなアイディアがiPhoneiPad で実現できます。今後は認識アラートの強化を進めていく予定ですが、皆さんのちょっとしたアイディアが、実用性と面白さを伴って生み出されて行くことを願っています。

Thermal Cam3x transmits and receives data using OSC, and can communicate with synthesizers using OSC communication, multiple ESP8266s, and computers. This version also supports AI image recognition that allows users to freely use image recognition data prepared by the user, so various ideas using infrared cameras can be realized on the iPhone or iPad. In the future, we will continue to strengthen awareness alerts, but I hope that your little ideas will be produced with fun.

Goto Home

----------------------------------------------------------------------------------------------------------------------------

 

 

 

*1:残念ながら内臓GPU性能に依存するためiPhone X以前の機種では使用できません。また事前に学習済みファイルを所定のフォルダにダウンロードする必要があります。Unfortunately, it depends on the built-in GPU(Bionic chip) performance and cannot be used with iPhone X or earlier models. In addition, it is necessary to download the learned files to a predetermined folder in advance.

*2:現在公開しているテスト用学習済みファイルは3種類です。There are three types of test-learned files currently available.

*3:複数のESP8266にメッセージを送るなど今後機能を増やしていく予定です。We plan to add more functions in the future, such as sending messages to multiple ESP8266.

Maker Faire Kyoto に向けて

W&T Thermal Cam1,3,D,Y ?

LEPTONとは米国FLIR社が製造している超小型サーモグラフィーカメラ(センサー)で、大きく分けて画素が80x60のLEPTON1、160x120のLEPTON3が販売されています。I2CとSPIを使って制御する少々お高いセンサーですが、格安ESP8266を利用して、iPhoneで表示させるアプリを作りました。

          f:id:TAKEsan:20180924212322p:plain

私たちが製作したものは、LEPTON1、3とも制御可能で、さらに2台同時に使うことにより距離認識が可能です。概要は、FLIR社のMaker Community   https://lepton.flir.com/community-showcase-items/thermal-stereo-cam/

          f:id:TAKEsan:20190129210342j:plain

に掲載されています。今回Maker Fair Kyotoへの出展応募に当たり、この仕組みを応用してワクワクするような展示を考えています。

PI3 LEPTON

過去2回Maker Faire Tokyoに出展経験がありますが、会場ではWIFIが繋がりにくく、急遽ビデオによる紹介しかできずに悔しい思いをしていました。そのため、今回はESP8266の代わりに有線LANでもWIFIでも対応できるラズベリーパイ3(以降PI3)でLEPTON3を動かすことにしました。海外でこの組み合わせに成功した事例が公開されているので楽勝かと思ったのですが、大きな問題がありました。Linuxマルチタスク処理が主な原因で、LEPTON3+PI3では数分〜数時間で止まってしまうのです。FLIRがこの組み合わせのソースを公開していない理由が、体験を通して理解させられることになりました。でも、私たちは基盤とソフトの工夫で、これを克服することができています。PI3単独で赤外線画像(暗視画像)を表示するだけでなく、iPhoneの代わりに使ったNvidiaのTX2やXavierからでもLAN経由で画像制御と動画表示が可能です。まずこれが1つ目の展示です。

f:id:TAKEsan:20190131141622j:plain

               PI3は電源供給だけ!後ろの画像はPI3から送られた画像をNVIDIA Xavierで表示させてます。 

f:id:TAKEsan:20190131101008p:plain

ホストマシンの画像です。2D、3D画像や画像調整、17種類のカラー表示が2D、3D側別々に指定可能。ポイント温度はもちろんポイント周辺の温度も測定できます。

PI BOSON

FLIRにはLEPTONの上位機種でBOSONという名称のサーモグラフィーカメラも存在します。こちらは2種類。320x256(QVGA)又は640x512(VGA)の画素で非常に小型な上、フレームレートも最高60fps(LEPTONは日本国内では10fps以下)というとんでもない性能。たまたまVGAカメラを借りることができましたが、こちらは価格が60万円以上という宝石並みの高額商品です。この時の比較テストで、LEPTON3のたかだか160x120画素でも、私たちが今まで開発したものは画質がかなり良いことが分かりました。VGAカメラの1/3の価格であるQVGAでこのアルゴリズムを応用した場合どうなるのか…?果たしてVGAの代替え機種になるのでしょうか?私たちの2つ目の展示予定作品です。

                                     

                    BOSON VGA の参考画像画像。流石に素晴らしいスピードと解像度です。

        f:id:TAKEsan:20190130130732p:plain           f:id:TAKEsan:20190130130805p:plain

          160x120 LEPTON3出力(GloupGes PURETHRMAL 2)                           今回の画像(319x239補完画像) 

               両者同じLEPTON3.5で撮影したものですが全く印象が違うことが確認できます。

f:id:TAKEsan:20190129214131p:plain

    画角は異なるが左がThermal Cam 3(LEPTON3.0)画像。右はBOSON VGA 。LEPTON 160x120でもディテールがかなり再現できている。

f:id:TAKEsan:20190129214154p:plain

            同上。この方法で、BOSON QVGA(320x256画素)がVGA(640x512画素)に追いつく可能性があります!!

おうちクラウドAI 

PI3と同一LAN上に接続した小型で省電力なGPUを持つNVIDIA TX2やXavierで、AIを活用しない手はありません。ただし、これらの機種でも標準的なデータセットで動画認識のスピードを上げるには、かなりの努力が必要です。私たちはまずTX2やXavier でYOLO V3やV2を現実的なスピードで実行する方法を考えました(眠っている昔のGPU付きマシンでも実現可能)。PI3で処理した赤外線画像データをメインPCに送り、AIで認識したバウンディングボックス座標をPI3に表示させたらどうなるか?これが「おうちクラウドAI」です。XavierもPI3もGPIOが使えるので、お互いにAIを応用した様々な制御が可能になります。この仕組みはAWSに応用できると思いませんか?今できているシステムはこれです。どちらも開発が容易なOpenframeworksで実現していることにも注目して下さい。さらに発展させて、高画質化したBOSON QVGAで展示しようと思っています。それが3つ目の展示予定作品です。ジャンケン判定で何か動くものを作ってみようと思います。

              

                                                                                  どんなのかは、この動画で!!

f:id:TAKEsan:20190129223322p:plain

                        夜間の動物被害に応用できそう。

サーボジンバル

もともとESP8266+LEPTON3+iPhoneの構成は、小型ドローン搭載により安価な計測システムを作ることが目的でした。基盤やソフトの改良で電波到達距離を伸ばしましたが、機体が姿勢制御で揺れた場合、画像がすぐ画面から外れてしまいます。よってカメラ側の揺れ対策が最後の課題。誰でも導入できてシステム価格が安く、軽くできたら…。DJ1やDOBYへ手軽に搭載できて、撮影対象物を大きく外す事なく録画できたら…。ドローンから発生する様々なノイズ対策は、私たちにはとても難しい課題でしたが、もう少しの改良で実現できる確信があります。4つ目の展示として鋭意作成中です。

                最後に

素人エンジニアと素人プログラマーが作った複雑で高度な処理が、あっけないほど手軽に実現できる様子を会場でお見せできると思っています。

追伸

おかげさまで、今まで作ったすべてのモノをさらに進化させて展示することができました。いろいろな意見をいただいて、とても有意義な2日間となりました。みなさんありがとうございました。

f:id:TAKEsan:20190510223431p:plain