BAIwatch, AI and Surf

by sagarrabanana in Circuits > Raspberry Pi

2117 Views, 10 Favorites, 0 Comments

BAIwatch, AI and Surf

miniaturaENG.png
bAIwatch 🌊 Inteligencia Artificial y Surf

Hi!

In this tutorial I’m going to show you how I made the bAIwatch. This device is capable of being connected to the webcams located in a couple of beaches where I usually go surfing, while it evaluates the state of the waves and lets me know, thanks to the vibration of a solenoid, when the conditions are good to leave everything, take the board and go surfing!

It is also capable of functioning as an alarm clock and gets automatically disconnected if the sea conditions are not good enough to make getting up early worthwhile.

Downloading Images.

2021-01-07 10_47_33.287720.jpg
2021-01-04 12_07_38.763200.jpg
2020-12-30 11_38_01.682461.jpg

This project is based on an image classifier. The first step was collecting a good amount of pictures of the spot, with the aim of gathering images of every possible conditions: sunny days, cloudy days, heavy rain days, soft rain days...

For this, I used the notebook below on Google Colab (I’ve changed the target webcam url of the script). In this case, I'm using urllib to download the .jpg files directly to Google Drive -for other webcam configurations you may have to use Selenium-.

You will have to change the file extension to .ipynb

Downloads

Preparing the Data

good waves.jpg
too big.jpg
no waves.jpg
discards2.jpg
discards.jpg

After collecting data, I made another script to make a manual classification for preparing the dataset.

I made three categories:

1- Good waves, with all the images with acceptable waves.

2- Bad waves, with both photos of calm and shattered seas impossible to surf for me.

3- Discards, with all the photos that don't point to the place of the beach that I'm trying to analyze (because they point to another place on the beach, the parking lot... whatever).

Evaluating the CNN

confusionMatrixTF22_eng.png

Once I had all the downloaded images on those 3 categories I started training the AI. For this, I used this notebook as a guide:

https://www.kaggle.com/vincee/intel-image-classification-cnn-keras

The result was quite good, with 84% accuracy. Here you have the confusion matrix, where you can see the result in a more graphic way:

Assembling It All.

sketch.jpg
20210120_201507.jpg
20210120_163155.jpg

After that, I just put it inside a raspberry pi 3. Here you can find a guide to install tensorflow 2.2 on it.

https://github.com/sagarrabanana/Install-OpenCV-and-TF-2.2.0-on-RPi-3

Remember that you must downgrade the version of tensorflow on Google Colab before training the AI.

Here you have the adapted code I made for the raspberry. You must configure the RP to run this script automatically when the RP is turned on.

I also made a cool box and assembled everything inside.

Here you have the schema.

I hope you like the project! This isn't the best documentation, but I think it can be very handy if you are trying to replicate it.

Of course, you can contact me for further information!

Downloads