Categorize iris flowers using k-means clustering with ML.NET

Machine learning with Human

This tutorial illustrates how to use ML.NET to build a clustering model for the iris flower data set.

In this tutorial, you learn how to:

  • Understand the problem
  • Select the appropriate machine learning task
  • Prepare the data
  • Load and transform the data
  • Choose a learning algorithm
  • Train the model
  • Use the model for predictions

Prerequisites

Understand the problem

This problem is about dividing the set of iris flowers in different groups based on the flower features. Those features are the length and width of a sepal and the length and width of a petal. For this tutorial, assume that the type of each flower is unknown. You want to learn the structure of a data set from the features and predict how a data instance fits this structure.

Select the appropriate machine learning task

As you don’t know to…

View original post 1,241 more words

Advertisements

#Humor – From the creators of “New Folder” and “New Folder (2)” ….

Greetings @ Burlington

El Bruno

First Azure Kinect App C API vs C# K4A Nuget Package

Ivana Tilca Blog

Hello!

I started to do some test with the new Azure Kinect DK and the results are amazing. I´m not an AI expert, so I decided to read/watch/learn while testing.

I started with the basic reading provided by Microsoft https://azure.microsoft.com/es-es/services/kinect-dk/. I´ve been using C API, from Azure Kinect Sensor DK. Now the thing is… i am a c# fan… and learning console with C++ was not ideal… did not have time to import the entire C library into .net so i researched and found this amazing NuGet package: https://www.nuget.org/packages/K4AdotNet just developed and still mantained by Andrey Bibichev.

I will write a series of “How To” articles using both C API and K4A Nuget Package for .net.

Let´s Begin

To start using the sensor first of all you need to understand the architecture you need to implement.

Untitled-1

This is how the Kinect Azure Sensor works.

  1. The device needs to…

View original post 551 more words

#RaspberryPi – How To enable auto start with #HDMI safe mode

Hi!

A couple of days ago I wrote (a personal reminder post) about how to add automatic connect to Wi-Fi and SSH enabled in a bootable Raspbian image in a SD card (see references). I also explained that this was required for me because, by default Raspberry Pi 4 video ports were not starting with a 1920 x 1080p resolution.

Important: Remember that now, the 2 video ports supports 4K !

I was digging and reading about this, and I found another quick fix to solve this problem. Once you had a Raspbian image in a SD card, you can edit the file [config.txt] for some amazing cool tweaks! (Also, see references)

For me, my main change was in the [hdmi_safe] parameter. Setting hdmi_safe to 1 will lead to “safe mode” settings being used to try to boot with maximum HDMI compatibility.

# uncomment if you get no picture on HDMI for a default "safe" mode 
hdmi_safe=1

With this, the device will start automatically in a safe and standard mode. And, yes, it will work with my old and crappy test monitor!

Happy coding!

Greetings @ Toronto

El Bruno

References

#VSCode – Installing Visual Studio Code in a #RaspberryPi, a couple of lessons learned – @code

Hi!

Now that I have my amazing Raspberry Pi 4 with 4GB RAM, it’s time to see how serious the device is. So, I decided to install and use some developers’ tools in the RPi. My dev list will be something like this

  • Python
  • Some ML and AI Python packages
  • GIT
  • Arduino
  • Visual Studio Code

It’s been a while since I installed VSCode in the device. The last time I did this, I needed to download the code from GitHub and compile the tool in the Raspberry Pi. As far as I remember this was a +25 min process.

Lucky for us the process can now be much simpler, thanks to Headmelted (see references). Now, we only need a single command to install VSCode:

. <( wget -O -
https://code.headmelted.com/installers/apt.sh )

Install process started! Or Maybe not because I found this amazing GPG error

python error installing visual studio code in raspberry pi
pi@rpidev3:~ $ curl -L https://code.headmelted.com/installers/apt.sh | sudo bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2349 0 2349 0 0 19739 0 --:--:-- --:--:-- --:--:-- 19906
Detecting architecture…
Ensuring curl is installed
Reading package lists… Done
Building dependency tree
Reading state information… Done
curl is already the newest version (7.64.0-4).
The following packages were automatically installed and are no longer required:
python3-pyperclip python3-thonny rpi.gpio-common
Use 'apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Architecture detected as armv7l…
Retrieving GPG key headmelted
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
gpg: no valid OpenPGP data found.
Removing any previous entry to headmelted repository
Installing [headmelted] repository…
Updating APT cache…
Hit:1 http://raspbian.raspberrypi.org/raspbian buster InRelease
Hit:2 http://archive.raspberrypi.org/debian buster InRelease
Get:3 https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease [23.4 kB]
Err:3 https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease
The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0CC3FD642696BFC8
Reading package lists…
W: GPG error: https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0CC3FD642696BFC8
E: The repository 'https://packagecloud.io/headmelted/codebuilds/debian stretch InRelease' is not signed.
Done!
Repository install complete.
Installing Visual Studio Code from [stretch]…
Reading package lists… Done
E: The value 'stretch' is invalid for APT::Default-Release as such a release is not available in the sources
Visual Studio Code install failed.

There a public GPG key used to verify the package and the SH script somehow does not download it (I think the ARM RPI version is still not defined). So, before the previous command, I need to run this command

wget https://packagecloud.io/headmelted/codebuilds/gpgkey -O
- | sudo apt-key add –

Now we have Visual Studio Code installed!

raspberry pi visual studio code installed

But, yes another but, you may note that the tool open and display a black window. Again, I need to go deeper on the details, but the latest version does not work well. There is some context information on GitHub (see references), and the proposed solution is to rollback to a previous version

sudo apt-get install code-oss=1.29.0-1539702286

And we also need to disable the automatic updates on this tool

sudo apt-mark hold code-oss

And now, yes, we got a fully functional Visual Studio Code in our Raspberry Pi!

Happy Coding!

Greetings @ Toronto

El Bruno

References

#Python – Let’s use a #FaceRecognition demo app for a performance comparison between #RaspberryPi3 and #RaspberryPi4

Hi!

I started to do some tests with the new Raspberry Pi 4 and the results are amazing. I’m not a performance expert, so I decided to pick up some of the demos / apps I’ve creating for the Raspberry Pi and run them in both models: Raspberry Pi 3 B+ and Raspberry Pi 4.

I started with an amazing set of tutorials on how to perform Face Recognition from Adrian Rosebrock (see references). I’ve been using his Face Recognition python package for this scenarios and it’s an amazing one.

I added some code to a custom version of Adrian’s Face Recognition sample, and it looks great. The main idea was to track in real-time the current FPS (similar to the work I did with the Image AI and Hololens sample a couple of days ago, see references).

This sample load a file with 15 trained faces and analyze frame by frame to

  • Detect faces in the frame.
  • If a face is detected, draw a frame around it.
  • For each detected frame analyze if the face is a trained face.
  • If the face is part of the trained dataset, the app will add the name of the person on top of the frame.

I display in real-time the FPS processed with a USB camera in a Raspberry Pi 3 B+. Doing a lot of tweaks and getting the best performance in the device I could never process 1FPS. The average processing data were between 0.6 and 0.9 FPS in a Raspberry Pi 3B+.

python face recognition in raspberry py 3 with FPS live

IMHO, these results are great for a small device like a Raspberry Pi 3B+. But now it was time to test it in the new Raspberry Pi 4. And an important note here is to remark that even if I did this tests in a Raspberry Pi 4 with 4GB of Rams, the performance results are similar to a RPI4 with just 1 GB of ram. We have more memory, however the processor improvements are quite significant in the new version.

I installed all the necessary software in the Raspberry Pi 4 and I got 3X better results. I’ve even tun this in a 1080p resolution to get a sense of the real processing time. The average processing data were between 2.3 and 2.4 FPS in a Raspberry Pi 4.

python face recognition in raspberry py 4 with FPS live

Amazing! In this scenario the Raspberry Pi 4 is almost 3 times faster than the Raspberry Pi 3. And again, these are amazing times for a 50USD device.

The sample source code is https://github.com/elbruno/Blog/tree/master/20190819%20Rpi%203%20vs%20Rpi%204%20Face%20Recognition

I even have time for some BBQ time with family and friends!

Happy coding!

Greetings @ Toronto

El Bruno

References

#RaspberryPi – How To automatically connect to WiFi and enable SSH on 1st boot

Hi!

If you been playing around with Raspberry Pi, I’m sure you already know this. For me this was a 1st timer, so I must write this down for the future myself.

When I started testing the Raspberry Pi 4, I got one of the complete kits, so I got the official red keyboard and mouse.

raspberry pi 4 official keyboard and mouse

I figure out I also need a couple of extra video cables. Now we need a [Micro HDMI to HDMI Cable] to connect one of the 2 video outputs to an external monitor.

This is the (cheap) monitor I’ve been using for a long time, however by default the RPi does works in a valid resolution for this monitor.

raspberry pi 7 inches monitor

And, the 2 main tasks you perform when you start your RPI are

  • Configure Wireless Connection
  • Enable SSH

Of course, you can do this directly in the SD with the Raspbian image (see references). And it’s also very easy to do.

You need to create a file named [wpa_supplicant.conf] in the root of the SD card with the following information:

country=ca
update_config=1
ctrl_interface=/var/run/wpa_supplicant

network={
 scan_ssid=1
 ssid=" Your WiFi SSID"
 psk="You amazing password"
}

The file content is very straight forward to understand. Main values to complete are [ssid] and [psk]

Important: This only works the first time you boot the Raspberry Pi with the SD card. The SO search for [wpa_supplicant.conf] and performs the connection. If you already booted the device, you need to create a bootable SD card again.

If you also want to enable SSH, you need to create a blank file named [ssh] to the main partition.

And that’s it, your Raspberry Pi will be connected to the Wifi and with SSH enabled!

Happy coding!

Greetings @ Toronto

El Bruno

References

#RaspberryPi – Using “please” instead of “sudo”, a very Canadian command line of work for #Linux

Hi!

I’ll write this down, so I don’t forget in the near future. I’m not a Linux user, and that’s amazing. Every day I learn something new, mostly while I’m working with Python, Visual Studio Code and Raspberry Pi.

So, I received a couple of brand new Raspberry Pi 4, and now it’s time to test them. And of course, most of this job is via SSH / command line. I’m not an expert (yet) on Raspberry Pi user permissions, however I started to realize when I need to use “sudo” to get things done.

If you search for sudo definition, you may find something similar to this one:

Sudo stands for either “substitute user do” or “super user do” (depending upon how you want to look at it)

https://www.lifewire.com/what-is-sudo-2197466

Today, I’ve learned the power of the “alias” command, and how it can be used to have a more polite conversation with my device. In example, I can create an alias for sudo, named “please” and then this happen.

alias please="sudo"

This is a very polite way to display my Raspberry Pi4 CPU information

raspbery pi 4 using please instead of sudo display cpu information

Or another polite way to display Disk information for the Raspberry Pi 4

raspbery pi 4 using please instead of sudo display disk information

You get the idea.

Happy Coding!

Greetings @ Toronto

El Bruno

Twitter source

#Python – Detecting #Hololens in realtime in webcam feed using #ImageAI and #OpenCV with performance improvements

Hi!

In my previous post I created a sample on how to use ImageAI and OpenCV to detect Hololens from a webcam frame (see references). I added some code to the last sample, and I found that the performance was not very good.

python using imageai to detect hololens less than 1 fps

With the previous sample code, I couldn’t process more than 1 frame per second. So, I started to make some improvements and I got this result

python using imageai to detect hololens little more than 1 fps

Not an amazing one, but still is nice to have more than 1 frame per second analyzed.

I even remove all the camera preview and still works in less than 1FPS.

python using imageai to detect hololens no opencv camera preview

So, now it’s time to read and learn of the deep code on ImageAI. Fun times!

Happy coding!

Greetings @ Burlington

El Bruno

References