Introduction: BAIwatch, AI and 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.

Step 1: Downloading Images.

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

Step 2: Preparing the Data

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).

Step 3: Evaluating the CNN

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:

Step 4: Assembling It All.

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!

Automation Contest

Participated in the
Automation Contest