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.
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.
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')
])
-Qiita --2019 strongest image recognition model EfficientNet commentary
Recommended Posts