[PYTHON] [I want to classify images using Tensorflow] (2) Let's classify images

Classify using Inception-v3

I will omit the explanation of Inception. Please refer to the following site TensorFlow: Tutorials: Image Recognition TensorFlow Tutorial-Image Recognition (Translation)

Environmental preparation

Last time Make "classify_image" available for the built environment

$ git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow/models/image/imagenet

Let's move it for the time being

If no argument is specified, the classification result of the panda image will be displayed.

python classify_image.py
giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca (score = 0.88493)
indri, indris, Indri indri, Indri brevicaudatus (score = 0.00878)
lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens (score = 0.00317)
custard apple (score = 0.00149)
earthstar (score = 0.00127)

Make a list of the file paths you want to classify.

Something like this

/home/vagrant/my_tensorflow/images/image01.jpg
/home/vagrant/my_tensorflow/images/image02.jpg
/home/vagrant/my_tensorflow/images/image03.jpg
/home/vagrant/my_tensorflow/images/image04.jpg
/home/vagrant/my_tensorflow/images/image05.jpg

Actually classify and divide into folders

Move the classified image files to a directory.

#!/bin/bash -x
FILES=`cat /home/vagrant/my_tensorflow/train.csv | tr -d ' '`
for FILE in $FILES
  do
    DIR="/tmp/image/"`python /home/vagrant/tensorflow/tensorflow/models/image/imagenet/classify_image.py --image_file ${FILE} | awk 'NR==1{print $1}' | tr -d "," | tr -d ' '  `"/"

    echo "-------------------"
    echo "FILE:$FILE"
    echo "DIR:$DIR"
    mkdir $DIR
    mv $FILE $DIR
  done

I was able to divide it into folders

ls /tmp/image/comic/
image02.jpg
image04.jpg

Recommended Posts

[I want to classify images using Tensorflow] (2) Let's classify images
I tried to classify text using TensorFlow
I want to visualize csv files using Vega-Lite!
I tried to make a ○ ✕ game using TensorFlow
I want to detect images of cats from Instagram
I want to use self in Backpropagation (tf.custom_gradient) (tensorflow)
I want to write in Python! (2) Let's write a test
I want to automate ssh using the expect command!
I tried using magenta / TensorFlow
I want to collect a lot of images, so I tried using "google image download"
[TensorFlow] I want to master the indexing for Ragged Tensor
I want to automate ssh using the expect command! part2
I wanted to classify Shadowverse card images by reader class
[For those who want to use TPU] I tried using the Tensorflow Object Detection API 2
I want to understand systemd roughly
I want to do ○○ with Pandas
I want to copy yolo annotations
I want to debug with Python
I tried to transform the face image using sparse_image_warp of TensorFlow Addons
I want to detect objects with OpenCV
I tried using Azure Speech to Text.
I tried to implement Autoencoder with TensorFlow
I want to print in a comprehension
I want to operate DB using Django's ORM from an external application
I want to scrape them all together.
I want to know how LINUX works!
I want to blog with Jupyter Notebook
Challenge image classification by TensorFlow2 + Keras 5 ~ Observe images that fail to classify ~
I want to use jar from python
I want to display an image on Jupyter Notebook using OpenCV (mac)
I want to build a Python environment
I want to use Linux on mac
I want to pip install with PythonAnywhere
I want to analyze logs with Python
I want to use IPython Qt Console
I want to display the progress bar
[Google Colab] I want to display multiple images side by side in tiles
I want to make an automation program!
I want to embed Matplotlib in PySimpleGUI
Let's summarize what you want to do.
I want to handle the rhyme part2
I want to develop Android apps on Android
I want CAPTCHA to say HIWAI words
I want to handle the rhyme part5
I want to handle the rhyme part4
Implemented DQN in TensorFlow (I wanted to ...)
I want to make a web application using React and Python flask
I tried to predict Covid-19 using Darts
I want to make matplotlib a dark theme
I want to connect to PostgreSQL from various languages
I want to do Dunnett's test in Python
I want to have recursion come to my mind
I want to pin Datetime.now in Django tests
I want to analyze songs with Spotify API 2
I want to INSERT a DataFrame into MSSQL
I want to memoize including Python keyword arguments
I want to create a window in Python
Anyway, I want to check JSON data easily
[Python] I want to manage 7DaysToDie from Discord! 1/3
I tried to synthesize WAV files using Pydub.
I want to perform SageMaker inference from PHP