Skip to content

My personal AI

elRaulito edited this page Nov 17, 2020 · 12 revisions

At the beginning of this project the object detection system that was used was Google Cloud Vision. This is a powerful AI system that can detect objects, give labels to the images and much more. Unfortunately it's a pay to use API and therefore in projects like this could be a limit in the prototype stage.

Google cloud vision was tested and working 100% with this project.

In order to allow to everyone to play with AI it was used a Tensorflow model, called coco-ssd, this model is more limited than google one but for this project it suits perfect. Capable of detecting more than 80 objects like cars, dogs, cats, persons and bicycle.

The package used for using tensorflow in js is @tensorflow/tfjs, it is possible to speed up the speed of computation using @tensorflow/tfjs-node that exploits CPU, if your server has a good GPU you wan also try changing to @tensorflow/tfjs-node-gpu

How to install it?

download the folder project

git clone https://github.com/elRaulito/Iotraffic-hackaton.git

Inside MyPersonalAI folder run the command

npm install

and run the .js AI with the command

node index.js

The server is started listening on http://localhost:3000

How to make a request?

You can select any image you want to test, encode it in base64 with tools like this Make the request using any device or Postman.

curl --location --request POST 'http://<YOUR_DEVICE_IP>:3000/image' \
--header 'Content-Type: application/json' \
--data-raw '{
    "image": "this string will be the image encoded in base64 in plain text..
it will be pretty long but dont' worry esp32 will deal with it"
}'

The response will be like this

[
    {
        "bbox": [
            12.013011932373047,
            28.14077541232109,
            323.8699836730957,
            224.03340235352516
        ],
        "class": "bicycle",
        "score": 0.931533932685852
    },
    {
        "bbox": [
            73.09247589111328,
            1.23288094997406,
            176.43450164794922,
            142.04309940338135
        ],
        "class": "person",
        "score": 0.557381808757782
    }
]

The bbox parameter has 4 elements, the first 2 are x and y coordinates of the box containing the object, the other two elements are the width and length.

Class is the object.

Score is the probability of being correct.

AICAM

AIcam will take pictures in jpeg, the image will be encoded in base64 and sent to MyPersonalAI port. The answer will be analyzed and each object will be counted. The number of times that the string "person" is detected in the response is the numbers of persons in the image.

Clone this wiki locally