Open
Description
chapter ends with MobileNetV2 example. i extend a bit using MobileNetV3, as it is a bit fresher.
but perfomance results shows strange things.
def predict2(img_path):
img = image.load_img(img_path, target_size=(224, 224))
model = tf.keras.applications.**MobileNetV2**()
img_array = image.img_to_array(img)
img_batch = np.expand_dims(img_array, axis=0)
img_preprocessed = preprocess_input(img_batch)
prediction = model.predict(img_preprocessed)
print(decode_predictions(prediction, top=3)[0])
%timeit -r 3 predict2(IMG_PATH)
MobileNetV2 gives 912 ms ± 5.02 ms per loop
while as MobileNetV3 gives 1.04 s ± 19.9 ms per loop
from tensorflow.keras.applications import MobileNetV3Small
def predict3(img_path):
img = image.load_img(img_path, target_size=(224, 224))
model = tf.keras.applications.MobileNetV3Small()
img_array = image.img_to_array(img)
img_batch = np.expand_dims(img_array, axis=0)
img_preprocessed = preprocess_input(img_batch)
prediction = model.predict(img_preprocessed)
#print(prediction)
print(decode_predictions(prediction, top=3)[0])
%timeit -r 3 predict3(IMG_PATH)
very strange. MobileNetV3Small should be faster.
Metadata
Metadata
Assignees
Labels
No labels