An easy and simply way to create your own image classifier AI using ml5.js and Google's Teachable Machine

Overview

Create your own image classifier AI

An easy and simple way to create your own image classifier AI (pre-trained) using ml5.js and Google's Teachable Machine.

Ex: This image classifier can detect a charmander, squirtle or bulbasaur in a image.

Document

1 - Creating your own model

First of all you need to create your own model by using the Google's machine learning tool called Teachable Machine. This tool is really simple and intuitive, you can easily create the model in less than 10 minutes.

Image-Model-Teachable-Machines

  1. Here you will create your own class, which means every "object" (or, in this case, every pokemon) that the AI will can recognize. PS: The more model images do you use, more accurate will be the AI.

  2. After you create all your classes make sure to train the model. This process is when the AI will learn to regonize every class (pokemons).

  3. After all of these process, its time to export your model.

2 - Exporting the model

Now that you create your own model you have to export them to your project. You can export as Tensorflow.js, standart Tensorflow or Tensorflow Lite. In this project we'll pick the Tensorflow.js option.

Image-Model-Teachable-Machines (2)

You also can choose if the model will be uploaded and being online or if it will be on your computer by downloading it.

If you pick the downloaded option make sure that you extract all the Json files to the my_model folder.

At the end you have to choose the code snippet to use. It can be javascript or p5.js. We will use p5.js.

Just copy and paste the content on your index.html file.

3 - Using the model

Replace your script, which is inside the index.html, to this script tag:

">
<script src="script.js">script>

And replace the script.js file to this:

     // Classifier Variable
      let classifier;
      // Model URL
      let imageModelURL = './my_model/';
      
      // To store the classification
      let label = "";
      let pokemon;
    
      // Load the model first
      function preload() {
        classifier = ml5.imageClassifier(imageModelURL + 'model.json');
      }
    
      function setup() {
        createCanvas(640, 480);
        background(153);
        getImage();
      }
    function getImage(){
        pokemon = createImg('assets/test_images/charmander-test.jpg', imageReady);
        pokemon.hide();
    }
 

    function imageReady() {
        image(pokemon, 0, 0);
        classifier.classify(pokemon, gotResult)
        console.log('loaded!')
    }
      // When we get a result
    function gotResult(error, results) {
        // If there is an error
        if (error) {
          console.error(error);
          return;
        }
        // The results are in an array ordered by confidence.
        console.log(results)
        label = results[0].className;
        createDiv(`Label: ${results[0].label}`);
        createDiv(`Confidence: ${nf(results[0].confidence, 0, 2)}`);
      }

This function will get the image test:

    function getImage(){
        pokemon = createImg('assets/test_images/charmander-test.jpg', imageReady);
        pokemon.hide();
    }

Make sure that your test image is different that the images used to train the model, to make sure that your AI really learned how to recognize the object and not it just reproducing an information.

The result will be something like this:

Document

Excellent! Now you have your own AI image classifier using your own model.

Architecture and Technology

You might also like...

Wonka JS is the easiest way to mint Metaplex's Candy Machine NFTs with APIs.

Wonka JS is the easiest way to mint Metaplex's Candy Machine NFTs with APIs.

Wonka JS Wonka JS is the easiest way to mint from Candy Machine and fetch NFTs through JS APIs. You can see an end to end example in Next.js demo proj

Nov 3, 2022

Create your own password generator using jQuery, Vanilla JS, and SASS.

Password Generator Create your own password generator using jQuery, Vanilla JS, and SASS. I have been working with JS for my last few projects so I th

Jul 12, 2021

simple-remix-blog is a blog template built using Remix and TailwindCSS. Create your own blog in just a few minutes!

simple-remix-blog is a blog template built using Remix and TailwindCSS. Create your own blog in just a few minutes!

simple-remix-blog is a blog template built using remix.run and TailwindCSS. It supports markdown and MDX for the blog posts. You can clone it and star

Dec 8, 2022

This extensions adds blocks to help you create your own carnival games in MakeCode Arcade using throwable balls, extra timer functions, and extra game-over options.

Usage This extensions adds blocks to help you create your own carnival games in MakeCode Arcade using throwable balls, extra timer functions, and extr

Nov 16, 2022

Create your own custom NFT minting page using thirdweb's NFT Drop contract

Customizable NFT Drop Minting Page In this example, you can create your own NFT Drop minting page just by customising the template with your branding,

Dec 24, 2022

🎨 Beautify your github profile with this amazing tool, creating the readme your way in a simple and fast way 🚀 The best profile readme generator you will find ⚡

🎨 Beautify your github profile with this amazing tool, creating the readme your way in a simple and fast way 🚀 The best profile readme generator you will find ⚡

Demo Profile Readme Generator The best profile readme generator you will find! About | Technologies | Requirements | Starting | Contributing 🎯 About

Jan 1, 2023

To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mark them as complete. I build a simple website that allows for doing that, and I do it using ES6 and Webpack!

To-do list

Project Name : TO-Do list "To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mar

Aug 22, 2022

"To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mark them as complete. You will build a simple website that allows for doing that, and you will do it using ES6 and Webpack!

To-do-list Description "To-do list" is a tool that helps to organize your day. It simply lists the things that you need to do and allows you to mark t

Oct 18, 2022
Owner
Mateus Vinícius de Lima
Brazilian law student who loves web develop, football, chess and philosophy. Looking for new adventures.
Mateus Vinícius de Lima
Easiest 1-click way to install and use Stable Diffusion on your own computer. Provides a browser UI for generating images from text prompts and images. Just enter your text prompt, and see the generated image.

Stable Diffusion UI Easiest way to install and use Stable Diffusion on your own computer. No dependencies or technical knowledge required. 1-click ins

null 3.5k Dec 30, 2022
This React-Based WebPage allows the client/user system to create their own blog, where users can publish their own opinions.

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

Gauri Bhand 4 Jul 28, 2022
This repo contains instructions on how to create your NFT in Solana(using Metaplex and Candy Machine) and mint it using your custom front-end Dapp

Solana-NFT minting Dapp Create your own NFT's on Solana, and mint them from your custom front-end Dapp. Tools used Metaplex -> Metaplex is the NFT sta

Udit Sankhadasariya 12 Nov 2, 2022
Solana blockchain candy machine app boilerplate on top of Metaplex Candy Machine. NextJS, Tailwind, Anchor, SolanaLabs.React, dev/mainnet automation scripts.

NFT Candy Factory NOTE: This repo will prob only work on unix-based environments. The NFT Candy Factory project is designed to let users fork, customi

Kevin Faveri 261 Dec 30, 2022
Complete Open Source Front End Candy Machine V2 Minter dAPP Built For The Frog Nation NFT Solana Project. Built With React, Candy Machine V2, Typescript

Complete Open Source Front End Candy Machine V2 Minter dAPP Built For The Frog Nation NFT Solana Project. Built With React, Candy Machine V2, Typescript

null 17 Sep 24, 2022
Catalogist is the easy way to catalog and make your software and (micro)services visible to your organization in a lightweight and developer-friendly way.

catalogist ?? ?? ?? ?? ?? The easy way to catalog and make your software and (micro)services visible to your organization through an API You were a pe

Mikael Vesavuori 11 Dec 13, 2022
optimize image & upload file to cloud as image bed with tiny image automic.

Rush! 图片压缩 & 直传图床工具 这是一个兴趣使然的项目, 希望 Rush! 能让这个世界的网络资源浪费减少一点点 下载 Downloads 获取最新发行版 功能 Features 拖拽批量压缩图片, 支持格式 jpg/png/gif Drop to optimize, jpg/png/gif

{ Chao } 3 Nov 12, 2022
zkPoB is a mobile compatible tool that lets anyone prove they own a Bufficorn (or any NFT) without revealing which Buffi they own or the address they are verifying themselves with

zkPoB is a mobile compatible tool that lets anyone prove they own a Bufficorn (or any NFT) without revealing which Buffi they own or the address they are verifying themselves with

Marto.eth 10 Aug 25, 2022
Harrison Njuguna 5 Nov 11, 2022
Makes downloading Scratch projects easy. Simply enter two project IDs and click start.

Makes downloading Scratch projects easy. Simply enter two project IDs and click start. No need to pick the right format or include the assets, all of this is done automatically and in the browser.

null 6 May 27, 2022