[PYTHON] The fastest way to try EfficientNet

TL;DR --Pre-learned weights by imagenet is available on Tensorflow Hub. --EfficientNetB0 --All released up to B7 --Feature vectors for transfer learning have been released, so use them. -Introducing the fastest way to try EfficientNet with Official TensorFlow Hub Tutorial for Transfer Learning --Run Image Classification Demo in Google Collabratory environment --If you can prepare the environment, you should be able to check the operation with the same code as the demo. --All you have to do is change the URL that represents the model to be downloaded in the tensorflow-hub library.

Introduction

Read more about "Efficient Net" for a great article. Qiita --Explanation of the strongest image recognition model in 2019 EfficientNet

This article focuses on showing you how to try EfficientNet the fastest.

Let's move the demo immediately

I have prepared a demo Google Colabatory to run, so please use this.

GoogleColabratory - transfer_learning_EfficientNet

I tried to extract only the important code and model definition part from the above Google Colabatory. Now you can use EfficientNet. If you are wondering what to do with the rest of the learning part, please try the above demo.

EfficientNet.py


import tensorflow as tf
import tensorflow_hub as hub
from tensorflow.keras import layers

#Please change the number of classes appropriately according to the data
num_classes = 10

#URL is this page https://tfhub.dev/google/collections/efficientnet/1
#The model you want to use from the URL listed at the end(B0-B7)Please choose one of
#This time I will use B0
feature_extractor_url = "https://tfhub.dev/google/efficientnet/b0/feature-vector/1"

# width/For height, B0 is(224, 224)Is recommended, so I do so
#Recommended width/Please see this page for height https://tfhub.dev/google/collections/efficientnet/1
feature_extractor_layer = hub.KerasLayer(feature_extractor_url,
                                         input_shape=(224,224,3))
#Learned weights are fixed
feature_extractor_layer.trainable = False

#I tried to use Keras functional API, but it didn't work.
#Following the official tutorial, it is as follows
model = tf.keras.Sequential([
  feature_extractor_layer,
  layers.Dense(num_classes, activation='softmax')
])

reference

-Qiita --2019 strongest image recognition model EfficientNet commentary

Recommended Posts

The fastest way to try EfficientNet
The easiest way to try PyQtGraph
The fastest way for beginners to master Python
Excel X Python The fastest way to work
Try to introduce the theme to Pelican
Cython to try in the shortest
The easiest way to make Flask
The fastest way to get camera images regularly with python opencv
Try to face the integration by parts
Python amateurs try to summarize the list ①
What is the fastest way to create a reverse dictionary in python?
Try to solve the fizzbuzz problem with Keras
The easiest way to get started with Django
Try to decompose the daimyo procession into Tucker
Try to solve the Python class inheritance problem
The easiest way to synthesize speech with python
Try to solve the man-machine chart with Python
How to try the friends-of-friends algorithm with pyfof
The easiest way to use OpenCV with python
Introduction to Python with Atom (on the way)
Try to simulate the movement of the solar system
Try to make client FTP fastest with Pythonista
Try posting to Qiita for the first time
Easy way to check the source of Python modules
Try to solve the programming challenge book with python3
The easiest way to set up Last-Modified in Flask
[Python] Try to read the cool answer to the FizzBuzz problem
Try setting SSH (Exscript) from the software to the router
Try setting NETCONF (ncclient) from software to the router
Try to solve the problems / problems of "Matrix Programmer" (Chapter 1)
Try to visualize the room with Raspberry Pi, part 1
Try to solve the internship assignment problem with Python
Molecular dynamics simulation to try for the time being
Try to estimate the number of likes on Twitter
Try to get the contents of Word with Golang
Try to implement yolact
[Neo4J] ④ Try to handle the graph structure with Cypher
Try to Normalize Cut the image with scikit-image (although it gets angry on the way)
The road to Pythonista
Try to decipher the login data stored in Firefox
The road to Djangoist
Try to specify the axis with PyTorch's Softmax function
Try to get the function list of Python> os package
Try to evaluate the performance of machine learning / regression model
Try connecting to Supervisord via XMLRPC to start / stop the program
[Selenium/Python] Try to display the court case pdf at once
Probably the easiest way to create a pdf with Python3
Try to improve the accuracy of Twitter like number estimation
Try to solve the problems / problems of "Matrix Programmer" (Chapter 0 Functions)
Try to automate the operation of network devices with Python
The usual way to add a Kernel with Jupyter Notebook
Try to model a multimodal distribution using the EM algorithm
[Introduction to Reinforcement Learning] Reinforcement learning to try moving for the time being
Try to decipher the garbled attachment file name with Python
Try to extract the features of the sensor data with CNN
Try to factorial with recursion
Try to analyze Twitter trends
How to use the generator
Try to understand Python self
Dot according to the image
The road to download Matplotlib