2019年7月25日木曜日

AppyBuilder Online will be closed for a while

I have developed various apps with AppyBuilder. I have been enthusiastic because both the design and the functionality of this system are good. Below are some of the applications I developed.

Some of the applications I developed with AppyBuilder
However, there has been an announcement that this online version will be closed from August 1st. The reason is that it takes time to concentrate on the development of a new version up to the 1st quarter of 2020. Once I knew that, I have to download and back up the apps I developed so far. And I expect new versions to be released successfully.

AppyBuilder also offers an amazing CodeEditor. It is very good at developing Extensions for App Inventor. Thanks to this, for example, I was able to easily develop the JSON Decode Extension as shown below:

http://sparse-dense.blogspot.com/2019/01/a-json-decoding-extension-for-app.html?m=0
http://sparse-dense.blogspot.com/2019/01/a-json-decoding-extension-for-app_19.html?m=0


I would like to expect further development of the CodeEditor.

2019年7月22日月曜日

MATLABセミナー:農業分野へのインパクト

 MathWorks社では、年1回のMATLAB EXPOという大規模技術展の他に、随時、セミナーを開催している。今回は下記セミナーに参加した。MathWorks社からのチュートリアル2件と、ユーザによる活用例2件(東大と八千代エンジニアリング)があった。会場のNext-1の定員は180名とのことだが、ほぼ満席に近い盛況であった。(スライドコピー等の配布資料は無し。)

MATLABおよびSimlinkセミナー
https://jp.mathworks.com/company/events/seminars.html
「ユーザから学ぶ画像処理・ディープラーニングでのMATLAB活用例」
2019年7月22日(月)、秋葉原UDX Next-1

MATLABセミナーが行われた秋葉原UDX(Google Mapsより)

 MATLABをすでに使っている人にとっては、MathWorksからのチュートリアルはそれほど目新しいものではないと思われるが、いくつかのポイントを以下に示す。
・MatLabのユーザは、世界で約400万人とのこと。
・日本国内では、約2,000社が利用している。
・画像処理のワークフローを宣言的に書けるので、プログラミングに煩わされずに自分が行いたいことに集中できる。
・MatLabコンパイラにより、成果物(MATLABコード)をスタンドアロンアプリ化して配布できる。
・Deep Learningだけでなく、そうではないルールベースの画像処理も充実。
・Deep Learningの処理の目的は「分類」、「検出」、「セマンティックセグメンテーション」の3種。
・これら3種それぞれに、ラベル付けの方法がある。

 小生が最も聴きたかったのが、東大(D1生)の発表である。これについて、以下に述べたい。実は、この研究成果は、2019年5月のMATLAB EXPO(台場で開催)のポスターセッションで公開されていた。小生は、すでにその報告をブログ記事としてここに書いた。今回、さらに詳しい内容と、ポスターセッションにはなかった農業分野での新しい展開も示された。この発表に、改めて感銘を受けた。

 今回新たに、「みかん」の熟度判定に蛍光分光法を用いて、みかんの最適収穫時期(糖酸比に基づく)判定を画期的に省力化できることが示された。ベイズ最適化を組み合わせたDeep Learningを行った。CNNは非常に有力ではあるが、なぜうまく行くのか分からない点もある。また、ネットワークの構造や実行制御のためのハイパーパラメータの調整も一筋縄では行かないとのこと。さらに、「とうふ」の凝固の制御(やわらかい、かたい)について、職人が長年の勘で判断していたことを置き換えるかも知れない方法もやっている。それは、とうふのできる過程でのレーザビーム反射光の画像を分類することだと言う。

 Deep Learningには、一般に多くの計算パワーが必要である。MATLABには、AmazonのAWSを使ってMATLABコードをクラウドで計算させる仕組みがある。これを使った。たまにしか使わない人にとって、自分のスケジュールで、使った分だけ支払うこのやり方のメリットは大きい。一例だが、自分のPCでMATLABコードの計算に25分かかったものが、AWSでは4分で完了した。

 MATLAB EXPOの時にも述べられていたことだが、以下の取り組みでは、実はDeep Learningはやっていない!ルールベースのアルゴリズムで、独自にプログラムを書き上げた。それにより、農園の「桃」の個数と熟度を判定できる。また、「いちご」の画像から、いちご一粒づつのサイズと糖度を認識する。さらに、3次元スキャナー(ライダー)の画像から、木の葉が重なって見えていても、葉っぱ一枚づつを確実に認識し、葉の面積、傾き角度も認識できるという。これらの、Deep Learningでないやりかたは、自分にフィットして制御しやすく、結果に応じて修正もやりやすい。そういうメリットは大きい。

 この発表のタイトルは、「機械学習や3次元点群処理技術が切り拓く植物計測の技術革新」となっている。まさに、その通りであり、農業分野へのインパクトは非常に大きなものとなるであろう。

セミナーで配布されたグッツ

2019年7月13日土曜日

Real-time image recognition demonstration on a smartphone using TensorFlow.js

There are many examples of image recognition (especially classification) by AI, but the "Google AI Experiments" introduced here seems to be further evolved. It was announced at TensorFlow Dev Summit 2019. Do you already know? This Summit's  38 lecture videos are available on youtube:

https://www.youtube.com/watch?v=GRMvCeIKvps

I tried the demo called "Teachable Machine" among them. As shown in Figure 1, the smartphone classifies images into three types. The Javascript version of Tensorflow runs under the web browser. A local Neural Network in the smartphone performs image training and evaluation without sending the image to the server. Of course, as long as this demo is used, no coding is required at all.


Here, we prepare three types of images of a hat, i.e. "back", "side", and "front", as shown in Figure 2, about 10 images each. Is it all right with such a small number of images? You may think that "transfer learning" is working there. In other words, this Teachable Machine should be using a Neural Network, which has been trained with a huge amount of images for a certain purpose.


Let's train this as shown in Figure 3. That is, press the corresponding button (train button) at the bottom to label each image. Each time, the image is trained in real time. For each of the three types, 10 images should be trained. After that, if you take a picture of the hat with either the back, side, or front, the orientation of the hat will be immediately determined. Actually, as you can see, everything was accurately identifiable! 100% confidence!


Next, try shooting with the hat in an ambiguous direction, not exactly on the back, side, nor front. As human beings feel, the result seems that Neural Network can not judge with certainty. It was a judgment that "maybe a side (59% confidence)". This is another good point.


● The university's graduation research is becoming increasingly severe. Even if you work hard to code and create an AI application, it seems that it is difficult to go beyond applications that can easily be made with no coding like this example. But on the other hand, the Teachable Machine demo app is just a demo. Kindly, the source list is also published. It's great if you can use this to solve your own problems. The level of graduation study goes up by this.

● This trial was carried out with smartphone Pixel3a (Android OS 9). Of course, it is also possible to use a PC or Mac, but the point is that you can train and evaluate in real time on your smartphone. Note that this demo will not work on iPhone and iPad.

2019年6月24日月曜日

June flower, Hydrangea ("Ajisai")

The flower of the rainy season (June) in Japan might be Hydrangea ("Ajisai", in Japanese). At this time of year, I see this flower in the neighborhood. It is a calm, beautiful flower. Six years ago in June, I traveled to Victoria, Canada, to attend a conference. I remembered that the garden of the hotel was in full bloom. It bloomed at the same time though there was a considerable difference in latitude in Tokyo and Victoria. I was able to find the photo right away in Google Photo. The following pictures are some of them. It seems to be common to see the flower and to feel at ease.


2019年6月17日月曜日

Javaに関する2つのニュース

Javaに関する以下の2つのニュース(2019年6月)に注目したいと思います。

Due to copyright issues, I put a picture of my Java notebooks instead of a news image.

まず、Microsoftからの発表です。
「Visual Studio Codeでの新人Java開発を支援するJava Pack Installerがリリース」

以下の[1][2]にその内容があります。実は、Microsoftは、元々、AdoptOpenJDK projectのプラチナメンバーとしてその開発に関わった来たのですから、自然な成り行きとも思えます。ともかく、このMicrosoftの発表によって、Javaはさらに底辺を広げることになるのではないでしょうか。

次のニュースは、IT関連企業への転職で求められるプログラミング言語に関するある調査結果です。
「転職求人において最も多く要求されるプログラミング言語はJavaである」

参考資料[3]にあるとおりですが、エンジニア向け転職サイト「レバテックキャリア」での発表によれば、Java、PHP、Ruby、C#、JavaScriptの順だという。これ以外に、台頭著しいPythonのシェアについても言及があります。さて、みなさまはこの調査結果にどう反応されますか?

例えば、Java、C#、C++のうち、どれがもっとも優れているか?それは愚問ではないでしょうか。トヨタのハイブリッド、日産のe-Power、スズキのハスラー、それぞれに多くの愛用者がいます。プログラミング言語もそういった側面を持つ。

[参考資料]
[1] Announcing the Visual Studio Code Installer for Java
https://devblogs.microsoft.com/visualstudio/announcing-visual-studio-code-java-installer/
[2[ Visual Studio Codeでの新人Java開発を支援するJava Pack Installerがリリース
https://www.excite.co.jp/news/article/Cobs_1922225/
[3] 転職求人の多いプログラミング言語、2位は「PHP」 1位は……
https://www.itmedia.co.jp/business/articles/1906/12/news123.html

2019年6月7日金曜日

日本タンポポと西洋タンポポ(2)

前の記事(1)では、西洋タンポポと日本タンポポの違いをみました。そうすると、次は、Deep Learningで両者を区別してみよう、ということになりますね。

以前にもご紹介しましたが、子供向けのAI体験システムであるML4K(Machine Learning for Kids)を使えば、コーディングも全く無しに、直ぐに結果を得られます!制約はもちろんありますが、素早く使えるこの優れた環境は、大人も遠慮する必要はありません!使ってみましょう。

ここでは、西洋タンポポと日本タンポポの画像それぞれ18枚づつを用意して、それを学習させます。実際には、バックでIBM WatsonのVisual Recognizerが動きます。一般的な画像認識の学習には、数百〜数千枚の画像が必要でしょうが、少ない画像でも(最低10枚以上あれば)一定の結果は得られます。


通常、数分で学習済みになりますので、学習用とは別に用意した画像でテストしました。西洋タンポポと日本タンポポの画像それぞれ1枚でテストしたに過ぎませんが、下図のとおり良好な識別結果が得られました。


これじゃ、小学生の夏休みの宿題くらいにしかならないかも知れません。でも、これだけ簡単にAI技術体験ができることは、誰にとっても嬉しいことです!

日本タンポポと西洋タンポポ(1)

とうとう本日(2019-6-7)梅雨入りとなりました。情報工学科のブログに以下の記事が載っていました。そろそろたんぽぽも終わりの時期ですが、まだ綺麗に咲いているようです。

たんぽぽ(?)の自然群生
http://blog.cs.kanagawa-it.ac.jp/2019/06/blog-post_5.html

たんぽぽ(?)と疑問符が付いていますが、恐らく、たんぽぽだと思います。ところで、たんぽぽには、西洋タンポポと日本タンポポ(カントウタンポポ等)があります。最近は、西洋に押されて、日本のは減少傾向のようです。

さて、その見分け方ですが、以下の図のように、花の下側にある総苞の形態で決まるとのことです。渡辺坦氏による参考資料[1]には、以下のような要約記述があります。詳しい説明と写真も掲載されています。
  • セイヨウタンポポ: 葉は羽状深裂し、花は舌状花のみで、総苞片は反り返る。
  • カントウタンポポ: 葉は羽状深裂し、花は舌状花のみで、総苞片は直立する。



本日から梅雨入りということなので、雨がまだ降る前の早朝に、近くの田んぼのあぜ道へ行って探してみました。幸い、上図のとおり、西洋タンポポと日本タンポポの両方とも見つかり(両者は数十メートル離れていましたが)、iPhoneで撮影することができました。

情報工学科のブログ記事のタンポポも恐らく、日本タンポポのように見えますが、正確には、総苞を調べないと断定できません。

[参考資料]
[1] 渡辺 坦: 植物の名前を探しやすいデジタル植物写真集

2019年5月29日水曜日

MATLAB EXPO 2019 に参加

 MATLAB EXPO 2019 (2019-5-28、グランドニッコー東京台場)に参加しました。断片的になりますが、以下に報告しますので、ご参考になれば幸いです。公式webページなどは以下にあります。
https://www.matlabexpo.com/jp/2019.html; Twitter #matlabexpo
(講演スライドは大部分すでに公開されています。)


 このEXPOは、毎年10月に開催されていたが、今回は間を縮めて、5月に開催となった。それだけ人工知能応用への関心の高まりが持続しているのかも知れない。

 特別講演、ポスターセッションに加えて、技術セッションが7並列で実施された。どの会場(恐らく500席以上の規模)もほとんど満席だった。いろいろな産業分野へのAIの多彩な応用が広がりつつあることを実感する場であった。

[機械学習とディープラーニング]セッションより
ディープラーニングを活用した化粧品開発における微生物試験の迅速化(資生堂+MathWorks Japan)
  • 化粧品会社だが、基本理念は「安全性」のうえに築く人間科学+物質科学+生物科学にあるとのこと。
  • 化粧品開発には、微生物による汚染リスクの評価(菌種の同定、菌数カウントなど)のため、菌の培養を伴う試験に28日ほどかかる。これをDeep Learningにより大幅短縮できる見通しを得た。
  • 特に、菌の育成予測(38時間後)も、一定程度可能になったことが大きい。
  • 機械学習の専門家はいなかったが、社内でAIに興味を持つ有志が集まり、MathWorksの支援を得て、いろいろな事例研究をもとに、2018年からこのプロジェクトを始めた。
  • AIの専門家でなくても、その分野に精通する人々の熱意で、AIは有効活用できるという典型例のように思われた。
  • MathWorkの説明によれば、このために、セマンティックセグメンテーションネットワーク(SegNet)を構築しているのが、一つの特徴とのことである。

[機械学習とディープラーニング]セッションより
強化学習:最適制御のためのディープラーニングの応用(MathWorks Japan)
 この講演は図3から分かるように、聴衆が非常に多かった。強化学習(Reinforcement Learning)に関する世界の論文数は、機械学習全体の論文数の増加に伴い、図4に示されているように勢いを増している。


  • MatLabの最新版R2019aには、新たに強化学習のためのツールボックスであるReinforcement Learning Toolboxが提供されている。その解説があり、今後試行する上で大いに参考になりそうである。
  • サポートされている強化学習のアルゴリズムとしては、Q-LearningやSARSAなど有名なものを含む6種とのこと。
  • このツールボックスを使ったリファレンスアプリケーション(例題)が20件ほど公開されている。そのなかには、2足歩行、倒立振り子、グリッド移動など親しみやすいものが含まれている。

[ポスターセッション]より2件(図5参照)


機械学習や3次元点群処理技術が切り拓く植物計測の技術革新(東大大学院 農学生命科学研究科)->図5(a)
  • タイトルの前半は、植物のモニタリングにDeep Learningを活用(糖酸度比の推定などに)ということだったが、後半の「3次元点群処理 ... 」は違っていた。
  • 図からも分かるように、ライダー(3次元スキャナー)画像から、植物の葉の数を算出するという。さらに、葉面積や葉傾斜角まで推定できるという。これには、機械学習は全くやっていない!独自の方式に基づくコーディングにより、一方向のパスだけで、葉の1枚、1枚を色分けして表示させているのに驚いた。
  • この技術を使って、農場を移動しながらリアルタイムに、実っている「桃」の個数の自動計測と熟成の程度の自動判定を行う様子を、ビデオ表示していた。素晴らしい!
  • 機械学習万能じゃないなあ、という気にもなってくる。説明者によれば、「後になって、MatLabを使えばもっと楽に作れることが分かった」とのこと。確かに、MatLabは、核となる機械学習だけでなく、その上流下流の処理も一貫して支援する環境でもある。

CNN & SVMの設計・訓練・評価・実装ツール(山口東京理科大)->図5(b)
  • CNN(畳み込みニューラルネットワーク)とSVM(サポートベクタマシン)を独自のGUIで使いやすくするツールである。
  • Deep Learningばかりが目立つ昨今だが、SVMの実力と有用性を改めて認識させるツールになっているように思われる。
  • CNNのうち、Softmaxの前の段階での出力を特徴ベクトルとして、SVMへ入力することも可能にしている。
------------------------------------------------------------------------------
 今回の参加者記念品:

2019年5月26日日曜日

Season of rice planting

Rice planting has begun this year. Soon the rainy season, so frogs will croak a lot. However, in recent years, the nearby rice fields have become absolutely less. With the aging of farmers, it is feared that there are very few young people working in farming.

Atsugi, Kanagawa Japan (May 26, 2019)

Anyway, about 5 months later, rice ears will be fully grown. At that time, autumn has already deepened. By that time, I want to keep a productive life in mind.

Atsugi, Kanagawa Japan (October, 2018)

2019年5月21日火曜日

Enjoy Reinforcement Learning in Tic-tac-Toe

This app has won the "2019 June's MIT APP INVENTOR OF THE MONTH" award. 
http://appinventor.mit.edu/explore/app-month-winners-2019

The purpose of this app is to familiarize you with Reinforcement Learning (a type of artificial intelligence). This was created using MIT App Inventor. In particular, it takes advantage of the recently released Generic Event blocks.

As an example, we use Tic-Tac-Toe, a well-known and easy game. The main feature of this app is that you can adjust the strength of your opponent computer player according to the degree of reinforcement learning and enjoy the match.

The computer player learns the situation when it loses in the match, so it will become gradually stronger as the match is played many times. This app is published below and its appearance is as shown in Fig1.

MIT App Inventor Gallery (source file .aia)
ai2.appinventor.mit.edu/?galleryId=5141416460812288


3 cases of computer vs. human match

There are three cases of computer-human competition, but the last case-3 is the most attractive.

(case-1) Play against a weak computer player
-> The computer player has no knowledge, so if you don't make mistakes, you will easily win.
(case-2) Play against a very strong computer player
-> The computer player has enough learned information, so it is difficult for a human to win.
(case-3) Adjust the strength of the computer player
-> The strength of computer player can be adjusted by the degree of learning.

The battle procedure in case-1 and case-2 is described in Fig.2 and Fig.3 respectively.



Adjust the strength of the computer player (case-3)

The procedure to enjoy the match in this case-3 is in Fig.4. In order to do this, you need to make the computer learn Reinforcement Learning. For example, it takes about 30 minutes for learning to make the computer about 85% likely to be strong (that is, 85% chance of not losing). Is it too long?

Don't worry, you can interrupt learning at any time by LONG clicking the button "Reinf. Learning". Even if the power is turned off, you can continue the learning by turning on the power and clicking the button "Reinf. Learning" again. However, please keep in mind that if you click on "from scratch", computer's learning results will disappear.


The computer gets progressively stronger as learning progresses. The situation is shown in Fig5. You can use this figure as a guide to predict the required learning time (or number of games). Enjoy the game!



This application includes a text file like Fig. 6 as an asset file. This is a learning result obtained by playing about 37,000 games. Please refer to the above Fig.5. FIg.6 exemplifies what the learning content means.


In this application, we used TinyDB to store and retrieve reinforcement learning results and also used newly-provided general-purpose event blocks to operate buttons. Thanks to them, as shown in Fig. 7, the app was created very efficiently.



This app was created inspired by the following documents:
  • https://ecraft2learn.github.io/ai/AI-Teacher-Guide/chapter-6.html
  • Donald Michie, http://people.csail.mit.edu/brooks/idocs/matchbox.pdf
  • https://we-make-money-not-art.com/menace-2-an-artificial-intelligence-made-of-wooden-drawers-and-coloured-beads/
  • Oliver Child, http://chalkdustmagazine.com/features/menace-machine-educable-noughts-crosses-engine/

Comments on version upgrade

As soon as you use this app, you will want to add the following features:
  1. Specifying which one of the computer and the human takes the first move. This is not difficult, but this time I omitted it to simplify the structure of the program.
  2. Saving the results of Reinforcement Learning and making it available to other people. This is also relatively easy to achieve. Intermediate results of Reinforcement Learning are stored in TinyDB. Therefore, when necessary, the contents of TinyDB can be stored as a text file and retrieved to the outside. To use it for further Reinforcement Learning, convert the text file to TinyDB format. However, generally speaking, this conversion requires a little care. This is because the format of the value in TinyDB elements (tag, value) is various, such as a single element, list, or list of lists.