fc2ブログ

大晦日の大雪

天気予報通り、大晦日の大雪です。昨年、雪は全く降らなかったので、久々ぶりでしょうか?
昨日の午後から風が強く、夕方から雪もちらほら。まとまって雪が積もるような所ではないのですが、風向き次第で、積雪エリアに入ってしまうような所に住んでいます・・。数十キロ離れた所では全く降っていないような不思議な所なんです。

朝起きたらこんな感じでした。屋根の上の積雪は25cmと言った所でしょうか?heavysnow1_201231.png
庭のキンモクセイも雪の重みで横に広がっていました。右下の鉢植えのダイダイは枝が折れてしまったのか、葉が地べたに這ってしまう有様。heavysnow2_201231.png

今日はブログでも書いて、おとなしくしていた方が良いですね。
スポンサーサイト



M5Stack Core2を買う

 先月、スイッチサイエンスで購入した「現実逃避?アイテム」の紹介をしていませんでした。ブログネタで温存していたのですが、モノに触れる時間が全く無くて、ようやく年末年始の休みに触れることができました。

購入したのはこの3点です。
 M5Stack Core2 IoT開発キット(5,225円)
 M5StickC(1,980円)
 M5Stack用GPSユニット(1,452円)

 M5Stackは最近IoT関連でよく耳にするようになり、気になっていましたが、怪しさ?も感じていました。調べてみると、中身はEspressif Systems製のESP32ベースのマイコンといろいろなセンサが実装された筐体だったんですね。

 以前のブログでESP8266を使って、Arduinoでコードを組んで遊んだこと(LCD実装Wi-Fiアクセスポイント)がありました。ESP32も基板を購入したのですが、今でも使わずに保管したままです・・。M5Stackはブレッドボードを使って結線しなくても、ある程度の機能が筐体中に実装されているので良いですね。

 M5Stack Core2は購入する際に品切れだったので、入荷後にメール連絡してもらって購入できました。電源を入れると初期の起動画面こんな感じです。M5StackCore2_201230_1.png立ち上がった画面はこれです。M5StackCore2_201230_2.pngやはり蓋を開けないとなと思って開けた中身はこれです。それなりに密に実装されています。M5StackCore2_201230_3.png裏面は端子リストのシールが貼られています。Raspberry Piを触るときはいつも端子リストを準備しなくてはならないので、シールが貼られていると些細なことですが、便利ですね。M5StackCore2_201230_4.png
 M5StickCは電源を入れると、以下のようなエラーが出ました。M5StickC_201230.png電源を何度かON/OFFしても変わらず。欠陥品かなと思いつつ、ネットで情報を収集すると、初期の充電されていない状態で出るエラーのようでした。しばらく充電すると正常に動きました。

 今回の年末年始の休暇は暦通りであと4日間と短いですが、コロナで出歩けないので、一緒に購入したGPSユニットを使って遊んでみようと思います。

AzureのComputer Visionを使う(3)

 前回の続きです。今回はAzure Computer Visionの顔認識のお話をします。
 コードは、画像を読み込み、画像の中の顔を抽出し、性別と年齢、および検出した画像エリアの座標(左上と右下の点)を返すものです。AzureのComputer VisionのQuick StartGitHubにコードがありますので、参考にしました。実行したコードは以下の通り。
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from azure.cognitiveservices.vision.computervision.models import OperationStatusCodes
from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes
from msrest.authentication import CognitiveServicesCredentials

from array import array
import os
from PIL import Image
import sys
import time

# Azure setting
subscription_key = "・・・・・・"
endpoint = "https://azure-computer-vision.cognitiveservices.azure.com/"
computervision_client = ComputerVisionClient(endpoint, CognitiveServicesCredentials(subscription_key))

# Image file
local_image_path = "./faces.jpg"

#--------------------
# Detect Faces
#--------------------
# Open local image
local_image = open(local_image_path, "rb")
# Select visual features(s) you want
local_image_features = ["faces"]
# Call API with local image and features
detect_faces_results_local = computervision_client.analyze_image_in_stream(local_image, local_image_features)

print("===== Detect Faces =====")
# Print results with confidence score
print("Faces in the local image: ")
if (len(detect_faces_results_local.faces) == 0):
print("No faces detected.")
else:
for face in detect_faces_results_local.faces:
print("'{}' of age {} at location {}, {}, {}, {}".format(face.gender, face.age, \
face.face_rectangle.left, face.face_rectangle.top, \
face.face_rectangle.left + face.face_rectangle.width, \
face.face_rectangle.top + face.face_rectangle.height))
print()
13、14行目には個人のazure-computer-visionのキーとエンドポイントを設定しました。

実行結果です。faces_res_img_201227.jpgコードを実行するだけでは以下のテキストデータの結果しか得られません。
===== Detect Faces =====
Faces in the local image:
'Male' of age 39 at location 118, 159, 212, 253
'Male' of age 54 at location 492, 111, 582, 201
'Female' of age 55 at location 18, 153, 102, 237
'Female' of age 33 at location 386, 166, 467, 247
'Female' of age 18 at location 235, 158, 311, 234
'Female' of age 8 at location 323, 163, 391, 231
性別と年齢、検出エリアの座標(Left、Top、Right、Bottomの順)です。この座標情報から検出エリアと検出順番(0番スタート)を生画像に描画するコードを書いたのが上の画像です。face_res_201227.jpgさすがにサンプル画像なので判定された性別も年齢も正しそうですね。

 顔認識の実力を知るには大勢の人が写っている画像が良いと思って試してみたのがこれです。元画像サイズは1200×800ピクセルです。sgt_res_img_201227.jpg人が密集しているせいか、頭の陰になっている人や漫画チックのものは検出出来ていないようですね。ネット情報から検出されたのが誰なのか調べた結果が以下の表です。sgt_res1_201227.jpgsgt_res2_201227.jpg性別は正しく判断しているようですが、年齢の判定結果がひどいですね。George、John、Paul、Ringoがそれぞれ48歳、46歳、38歳、35歳で年を取りすぎています・・。蝋人形は実物よりも若く出ていますが、それでも年取っていますね。Beatlesメンバー以外の人の名前、年齢は良く分からないので判断が難しいです。左下の福助人形が検出できなかったのも残念。下にうつむいているのがNGなのかな??

 仕切り直して、次はフルベッキの幕末志士の画像です。合成写真のいわく付きのものですね。元画像サイズは2004×1428ピクセルです。左最上段一人だけ前の人の陰になって検出できませんでしたが、その他は全部検出できています。bakumatu_res_img_201227.jpgこれも写っているのが誰なのかをネット情報でまとめると以下の通り。ネット情報では年齢も記載されていたので、転記しました。bakumatu_res1_201227.jpgbakumatu_res2_201227.jpg性別間違いが見られます。幕末の髪型(ちょんまげ)まではAIで学習されていないのでしょう・・。顔が童顔なのでしょうか、年齢が実年齢より若く判定されているケースが多く見受けられます。10番の大村益次郎が9歳はないやろ・・(笑)。フルベッキの長男が44番に写っているのですが、子供であることは分かるんですね。大したものです。

 今回も楽しくAzure Computer Visionの顔認識で遊ぶことができました。次回は、文字認識についてお話します。

AzureのComputer Visionを使う(2)

 前回のブログからかなり時間が経ちました。書くネタはあったのですが、この数ヶ月何かと忙しく、書く時間がまとまって取れない状態でした。今年のネタは今年のうちに♪、忘れずに書いておかなくては・・。来年になるとやったことすら忘れて、また同じことをやってしまうかも知れないので・・。

 AzureのComputer VisionのQuick Startのコードを実行する所からでした。
今回は、その中の以下の3つを試してみました。
 ① 画像を説明する(Describe an Image)
 ② 画像を分類する(Categorize an Image)
 ③ 画像にタグを付ける(Tag an Image)
GitHubに全コードがありますので、それを参考に以下のコードを実行させました。
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from azure.cognitiveservices.vision.computervision.models import OperationStatusCodes
from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes
from msrest.authentication import CognitiveServicesCredentials

from array import array
import os
from PIL import Image
import sys
import time

# Azure setting
subscription_key = "・・・・・・"
endpoint = "https://azure-computer-vision.cognitiveservices.azure.com/"
computervision_client = ComputerVisionClient(endpoint, CognitiveServicesCredentials(subscription_key))

# Image file
local_image_path = "./landmark.jpg"

#--------------------
# Describe an Image
#--------------------
# Open local image file
local_image = open(local_image_path, "rb")

# Call API
description_result = computervision_client.describe_image_in_stream(local_image)

print("===== Describe an Image =====")
if (len(description_result.captions) == 0):
print("No description detected.")
else:
for caption in description_result.captions:
print("'{}' with confidence {:.2f}%".format(caption.text, caption.confidence * 100))
print()

#--------------------
# Categorize an Image
#--------------------
# Open local image file
local_image = open(local_image_path, "rb")

# Select visual feature type(s)
local_image_features = ["categories"]
# Call API
categorize_results_local = computervision_client.analyze_image_in_stream(local_image, local_image_features)

# Category results with confidence score
print("===== Categorize an Image =====")
if (len(categorize_results_local.categories) == 0):
print("No categories detected.")
else:
for category in categorize_results_local.categories:
print("'{}' with confidence {:.2f}%".format(category.name, category.score * 100))
print()

#--------------------
# Tag an Image
#--------------------
# Open local image file
local_image = open(local_image_path, "rb")

# Call API
tags_result_local = computervision_client.tag_image_in_stream(local_image)

# Tags results with confidence score
print("===== Tag an Image =====")
if (len(tags_result_local.tags) == 0):
print("No tags detected.")
else:
for tag in tags_result_local.tags:
print("'{}' with confidence {:.2f}%".format(tag.name, tag.confidence * 100))
print()
13、14行目には前回の最後に話した、azure-computer-visionのキーとエンドポイントを設定しました。

実行結果です。
画像1landmark.jpg
===== Describe an Image =====
'a castle on top of Colosseum' with confidence 86.02%

===== Categorize an Image =====
'building_' with confidence 31.64%
'others_' with confidence 0.39%
'outdoor_' with confidence 3.91%

===== Tag an Image =====
'building' with confidence 99.92%
'outdoor' with confidence 97.66%
'sky' with confidence 93.79%
'ruins' with confidence 76.13%
'amphitheatre' with confidence 56.34%
サンプル画像のためか?86%の信頼度でコロッセオと認識しました。カテゴリは86個の分類の中から選択されます。画像タグで'ruins'と判断するのはなかなかなのか?学習させてあるためか・・?

画像2skytree.jpg
===== Describe an Image ===== 
'the tower of the city with Tokyo Skytree in the background' with confidence 95.15%

===== Categorize an Image =====
'building_' with confidence 44.53%
'building_pillar' with confidence 53.91%

===== Tag an Image =====
'outdoor' with confidence 99.82%
'sky' with confidence 99.79%
'skyscraper' with confidence 97.11%
'building' with confidence 95.96%
'tall' with confidence 44.68%
'tower' with confidence 17.40%
東京スカイツリーも賢く認識しました。

画像3shinkansen.jpg
===== Describe an Image =====
'a passenger train pulling into a station' with confidence 96.99%

===== Categorize an Image =====
'trans_trainstation' with confidence 99.61%

===== Tag an Image =====
'train' with confidence 99.99%
'track' with confidence 99.56%
'platform' with confidence 98.57%
'station' with confidence 98.20%
'railroad' with confidence 95.85%
'transport' with confidence 95.26%
'rail' with confidence 90.41%
'vehicle' with confidence 88.34%
'land vehicle' with confidence 86.81%
'locomotive' with confidence 72.69%
'pulling' with confidence 65.48%
'railway' with confidence 63.47%
'rolling stock' with confidence 55.82%
'subway' with confidence 11.39%
0系の新幹線も、駅に入線していることまで認識しました。なるほど、なるほど。

画像4castle.jpg
===== Describe an Image ===== 
'a large clock tower sitting in the grass' with confidence 69.04%

===== Categorize an Image =====
'building_' with confidence 19.92%
'outdoor_' with confidence 1.56%
'outdoor_sportsfield' with confidence 52.73%

===== Tag an Image =====
'sky' with confidence 99.86%
'outdoor' with confidence 99.85%
'tree' with confidence 99.85%
'castle' with confidence 88.82%
'building' with confidence 82.75%
'place of worship' with confidence 61.20%
'stone' with confidence 43.51%
'temple' with confidence 32.85%
熊本城は大きな時計台と認識しました。日本の古城は学習していないのでしょうか?タグで'castle'と出力されたのが救いかな?

次回は、Azure Computer Visionの顔認識のお話をします。

macOS Big Surで失敗する(2)

 前回の続きです。macOS Big SurにUpdateした後にセキュリティソフトウェアやArduinoが動かないなどの不具合が多発したので、耐えられずにTime MachineでCatalinaにダウングレードしました。万が一動かなくなったらクリーンインストールしようかなと不安に思いつつ、修復を終えるまで待ちました。

 結果、無事に復旧できました。Catalina_return.pngセキュリティソフトもArduinoもエラーなく起動しました。まずは一安心、やれやれです。起動後にソフトウェアアップデートでBig Surへのアップデートの案内がありますが、しばらく放置しておこうと思います。Windowsの無差別テロのような身勝手なUpdateはないとは思いますが・・。

 それにしても、まめにバックアップを取っておいて正解でした。これもWindowsの痛い経験のおかげ?です。

macOS Big Surで失敗する(1)

 Macお前もかぁ〜。Update毎にPCが不調になるWindowsに見切りをつけて久しくなりますが、今回Macもやってくれました。最近macOSやiOSは不具合だらけですね。不具合対応のUpdateが多過ぎます。機能を盛り込みすぎて不安定になっているのではないか?あるいはソフトウェアエンジニアの質が下がっているのでしょうか?ジョブズが天国で泣いていますね。ユーザも泣いていますが・・。不具合が多いので、個人的にUpdateの連絡があるとすぐに実行しています。セキュリティ面のケアもありますし。

 ただ、今回のBig Sur(macOS 11.0)のUpdateで懲りました。現在「Time Machineにお願い♪」して(古い・・)、まだ安定に動いていたCatalina(macOS 10.15)に戻している最中です。元に戻るかは心配。

 11/15にBig SurにUpdateして無事に立ち上がったので安心していました。Big_Sur_update_201115.pngただし、再起動すると、セキュリティソフトウェアのESETが早々にコケました。ESET_support_NG.pngメーカホームページを確認すると、Big SurへのUpdateは待ってください、Big Surのサポートには時間がかかる旨が書かれてありました。何やソレ!
 以後、VScodeやブラウザ、メールは普通に使えていたので、起動が以前より遅く感じたりするのも我慢して使っていましたが、今日Arduinoを使おうとしたら、エラー発生。Arduino_support_NG1.png対応していないようです。Arduino_support_NG2.pngReopenするとエディタは何とか開きましたが、気持ち悪いですね。

 結局、耐えられなくなり、OSをCatalinaに戻すべく「Time Machineにお願い♪」です。無事に戻ればよいのですが。ネット記事を眺めていると、悲しいことに「文鎮化」したMacもあるようですね。Macもこんなこと続けているとユーザ逃げるよ!!

ご訪問者数

(Since 24 July, 2016)

タグクラウド


プロフィール

Dr.BobT

Author: Dr.BobT
興味のおもむくままに生涯考え続けるエンジニアでありたい。

月別アーカイブ

メールフォーム

名前:
メール:
件名:
本文: