Featured image of post AI Powered anime character recognition

AI Powered anime character recognition

Preface

AI is scary.

Real scary.

The technology is very human in the way that it behaves and in the things that it does.

However, I, unlike many of the top researchers in the field (I do this as a hobby) do not have grand goals such as creating AI that would help people,(or subjugate them) but would rather just play with the technology and libraries people (companies) have made for me to tinker with.

So I made an AI that identifies anime characters from an anime i really like.

Because why not.

Anyways, the current example is from an anime called “Toaru no magical index”. I trained an image recognition model called “efficient0” on a dataset of images i hand labeled, and it can now accurately tell the difference between the two characters.

The two characters i trained it on are

  • Misaka mikoto
  • Accelerator

As you can see here, they’re very different characters, so the model I trained can tell the difference quite easily.

Misaka Mikoto Accelerator

How?

Step 1: get the repo

Well for starters, I recommend you download the repository from the github

git clone git@github.com:Eddy-Arch/ai_anime_recognition.git

As always, read the readme, and all that.

Step 2: Dependencies

grab the dependencies

pip3 install -r requirements.txt

If any dependencies are still missing afer you run this command, manually install them. If you enter dependency hell, like i did, (good luck) switch to linux. Not much I can help you with here.

Step 3 set up a dataset

Youre gonna want a dataset to train on, and since its a custom dataset you are going to have to make it yourself. Painstakingly.

What do i mean by that?

The entire dataset had to be tagged by hand and someone (me) had to go into each image and select a section of the image where the character is contained.

This process is painsteaking, but there is a utility to make the process easier.

For my purposes, i used labelImg, which you can download and setup here

Step 4: Train on the dataset.

This is where the toarutrain.py comes into use.

It is by default configured to train on the dataset provided in the repo. You will need to tweak the label names to the ones you used, and you will need to tweak the epochs value to the amount your computer can handle. training a model is a VERY system intense task. So make sure you saved all your important work and avoid doing multitasking and running big programs in the back ground. You have been warned.

Once you are done setting up your dataset, run the following command to train on it(after you have adjusted the training parameters to your liking in toarutrain.py) python3 toarutrain.py

Step 5: Profit

And its done!

You can now run

python3 toaruidentify.py "https://yourimage.png/"

On any image of those characters, and the model should be able to tell the difference between them, and output a file with an outline of the character, his name, and the confidence level of the identification.