- 🤖 See full list of Machine Learning Experiments on GitHub
- ▶️ Interactive Demo: try this model and other machine learning experiments in action
In this experiment we will use a pre-trained MobileNetV2 Tensorflow model to classify images. This model is trained using the ImageNet dataset.
# Selecting Tensorflow version v2 (the command is relevant for Colab only).
%tensorflow_version 2.x
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np
import platform
import pathlib
print('Python version:', platform.python_version())
print('Tensorflow version:', tf.__version__)
print('Keras version:', tf.keras.__version__)
Python version: 3.7.6 Tensorflow version: 2.1.0 Keras version: 2.2.4-tf
MobileNet v2 models for Keras: https://www.tensorflow.org/api_docs/python/tf/keras/applications
model = tf.keras.applications.MobileNetV2()
print(model)
<tensorflow.python.keras.engine.training.Model object at 0x131595ad0>
model.summary()
Model: "mobilenetv2_1.00_224" __________________________________________________________________________________________________ Layer (type) Output Shape Param # Connected to ================================================================================================== input_1 (InputLayer) [(None, 224, 224, 3) 0 __________________________________________________________________________________________________ Conv1_pad (ZeroPadding2D) (None, 225, 225, 3) 0 input_1[0][0] __________________________________________________________________________________________________ Conv1 (Conv2D) (None, 112, 112, 32) 864 Conv1_pad[0][0] __________________________________________________________________________________________________ bn_Conv1 (BatchNormalization) (None, 112, 112, 32) 128 Conv1[0][0] __________________________________________________________________________________________________ Conv1_relu (ReLU) (None, 112, 112, 32) 0 bn_Conv1[0][0] __________________________________________________________________________________________________ expanded_conv_depthwise (Depthw (None, 112, 112, 32) 288 Conv1_relu[0][0] __________________________________________________________________________________________________ expanded_conv_depthwise_BN (Bat (None, 112, 112, 32) 128 expanded_conv_depthwise[0][0] __________________________________________________________________________________________________ expanded_conv_depthwise_relu (R (None, 112, 112, 32) 0 expanded_conv_depthwise_BN[0][0] __________________________________________________________________________________________________ expanded_conv_project (Conv2D) (None, 112, 112, 16) 512 expanded_conv_depthwise_relu[0][0 __________________________________________________________________________________________________ expanded_conv_project_BN (Batch (None, 112, 112, 16) 64 expanded_conv_project[0][0] __________________________________________________________________________________________________ block_1_expand (Conv2D) (None, 112, 112, 96) 1536 expanded_conv_project_BN[0][0] __________________________________________________________________________________________________ block_1_expand_BN (BatchNormali (None, 112, 112, 96) 384 block_1_expand[0][0] __________________________________________________________________________________________________ block_1_expand_relu (ReLU) (None, 112, 112, 96) 0 block_1_expand_BN[0][0] __________________________________________________________________________________________________ block_1_pad (ZeroPadding2D) (None, 113, 113, 96) 0 block_1_expand_relu[0][0] __________________________________________________________________________________________________ block_1_depthwise (DepthwiseCon (None, 56, 56, 96) 864 block_1_pad[0][0] __________________________________________________________________________________________________ block_1_depthwise_BN (BatchNorm (None, 56, 56, 96) 384 block_1_depthwise[0][0] __________________________________________________________________________________________________ block_1_depthwise_relu (ReLU) (None, 56, 56, 96) 0 block_1_depthwise_BN[0][0] __________________________________________________________________________________________________ block_1_project (Conv2D) (None, 56, 56, 24) 2304 block_1_depthwise_relu[0][0] __________________________________________________________________________________________________ block_1_project_BN (BatchNormal (None, 56, 56, 24) 96 block_1_project[0][0] __________________________________________________________________________________________________ block_2_expand (Conv2D) (None, 56, 56, 144) 3456 block_1_project_BN[0][0] __________________________________________________________________________________________________ block_2_expand_BN (BatchNormali (None, 56, 56, 144) 576 block_2_expand[0][0] __________________________________________________________________________________________________ block_2_expand_relu (ReLU) (None, 56, 56, 144) 0 block_2_expand_BN[0][0] __________________________________________________________________________________________________ block_2_depthwise (DepthwiseCon (None, 56, 56, 144) 1296 block_2_expand_relu[0][0] __________________________________________________________________________________________________ block_2_depthwise_BN (BatchNorm (None, 56, 56, 144) 576 block_2_depthwise[0][0] __________________________________________________________________________________________________ block_2_depthwise_relu (ReLU) (None, 56, 56, 144) 0 block_2_depthwise_BN[0][0] __________________________________________________________________________________________________ block_2_project (Conv2D) (None, 56, 56, 24) 3456 block_2_depthwise_relu[0][0] __________________________________________________________________________________________________ block_2_project_BN (BatchNormal (None, 56, 56, 24) 96 block_2_project[0][0] __________________________________________________________________________________________________ block_2_add (Add) (None, 56, 56, 24) 0 block_1_project_BN[0][0] block_2_project_BN[0][0] __________________________________________________________________________________________________ block_3_expand (Conv2D) (None, 56, 56, 144) 3456 block_2_add[0][0] __________________________________________________________________________________________________ block_3_expand_BN (BatchNormali (None, 56, 56, 144) 576 block_3_expand[0][0] __________________________________________________________________________________________________ block_3_expand_relu (ReLU) (None, 56, 56, 144) 0 block_3_expand_BN[0][0] __________________________________________________________________________________________________ block_3_pad (ZeroPadding2D) (None, 57, 57, 144) 0 block_3_expand_relu[0][0] __________________________________________________________________________________________________ block_3_depthwise (DepthwiseCon (None, 28, 28, 144) 1296 block_3_pad[0][0] __________________________________________________________________________________________________ block_3_depthwise_BN (BatchNorm (None, 28, 28, 144) 576 block_3_depthwise[0][0] __________________________________________________________________________________________________ block_3_depthwise_relu (ReLU) (None, 28, 28, 144) 0 block_3_depthwise_BN[0][0] __________________________________________________________________________________________________ block_3_project (Conv2D) (None, 28, 28, 32) 4608 block_3_depthwise_relu[0][0] __________________________________________________________________________________________________ block_3_project_BN (BatchNormal (None, 28, 28, 32) 128 block_3_project[0][0] __________________________________________________________________________________________________ block_4_expand (Conv2D) (None, 28, 28, 192) 6144 block_3_project_BN[0][0] __________________________________________________________________________________________________ block_4_expand_BN (BatchNormali (None, 28, 28, 192) 768 block_4_expand[0][0] __________________________________________________________________________________________________ block_4_expand_relu (ReLU) (None, 28, 28, 192) 0 block_4_expand_BN[0][0] __________________________________________________________________________________________________ block_4_depthwise (DepthwiseCon (None, 28, 28, 192) 1728 block_4_expand_relu[0][0] __________________________________________________________________________________________________ block_4_depthwise_BN (BatchNorm (None, 28, 28, 192) 768 block_4_depthwise[0][0] __________________________________________________________________________________________________ block_4_depthwise_relu (ReLU) (None, 28, 28, 192) 0 block_4_depthwise_BN[0][0] __________________________________________________________________________________________________ block_4_project (Conv2D) (None, 28, 28, 32) 6144 block_4_depthwise_relu[0][0] __________________________________________________________________________________________________ block_4_project_BN (BatchNormal (None, 28, 28, 32) 128 block_4_project[0][0] __________________________________________________________________________________________________ block_4_add (Add) (None, 28, 28, 32) 0 block_3_project_BN[0][0] block_4_project_BN[0][0] __________________________________________________________________________________________________ block_5_expand (Conv2D) (None, 28, 28, 192) 6144 block_4_add[0][0] __________________________________________________________________________________________________ block_5_expand_BN (BatchNormali (None, 28, 28, 192) 768 block_5_expand[0][0] __________________________________________________________________________________________________ block_5_expand_relu (ReLU) (None, 28, 28, 192) 0 block_5_expand_BN[0][0] __________________________________________________________________________________________________ block_5_depthwise (DepthwiseCon (None, 28, 28, 192) 1728 block_5_expand_relu[0][0] __________________________________________________________________________________________________ block_5_depthwise_BN (BatchNorm (None, 28, 28, 192) 768 block_5_depthwise[0][0] __________________________________________________________________________________________________ block_5_depthwise_relu (ReLU) (None, 28, 28, 192) 0 block_5_depthwise_BN[0][0] __________________________________________________________________________________________________ block_5_project (Conv2D) (None, 28, 28, 32) 6144 block_5_depthwise_relu[0][0] __________________________________________________________________________________________________ block_5_project_BN (BatchNormal (None, 28, 28, 32) 128 block_5_project[0][0] __________________________________________________________________________________________________ block_5_add (Add) (None, 28, 28, 32) 0 block_4_add[0][0] block_5_project_BN[0][0] __________________________________________________________________________________________________ block_6_expand (Conv2D) (None, 28, 28, 192) 6144 block_5_add[0][0] __________________________________________________________________________________________________ block_6_expand_BN (BatchNormali (None, 28, 28, 192) 768 block_6_expand[0][0] __________________________________________________________________________________________________ block_6_expand_relu (ReLU) (None, 28, 28, 192) 0 block_6_expand_BN[0][0] __________________________________________________________________________________________________ block_6_pad (ZeroPadding2D) (None, 29, 29, 192) 0 block_6_expand_relu[0][0] __________________________________________________________________________________________________ block_6_depthwise (DepthwiseCon (None, 14, 14, 192) 1728 block_6_pad[0][0] __________________________________________________________________________________________________ block_6_depthwise_BN (BatchNorm (None, 14, 14, 192) 768 block_6_depthwise[0][0] __________________________________________________________________________________________________ block_6_depthwise_relu (ReLU) (None, 14, 14, 192) 0 block_6_depthwise_BN[0][0] __________________________________________________________________________________________________ block_6_project (Conv2D) (None, 14, 14, 64) 12288 block_6_depthwise_relu[0][0] __________________________________________________________________________________________________ block_6_project_BN (BatchNormal (None, 14, 14, 64) 256 block_6_project[0][0] __________________________________________________________________________________________________ block_7_expand (Conv2D) (None, 14, 14, 384) 24576 block_6_project_BN[0][0] __________________________________________________________________________________________________ block_7_expand_BN (BatchNormali (None, 14, 14, 384) 1536 block_7_expand[0][0] __________________________________________________________________________________________________ block_7_expand_relu (ReLU) (None, 14, 14, 384) 0 block_7_expand_BN[0][0] __________________________________________________________________________________________________ block_7_depthwise (DepthwiseCon (None, 14, 14, 384) 3456 block_7_expand_relu[0][0] __________________________________________________________________________________________________ block_7_depthwise_BN (BatchNorm (None, 14, 14, 384) 1536 block_7_depthwise[0][0] __________________________________________________________________________________________________ block_7_depthwise_relu (ReLU) (None, 14, 14, 384) 0 block_7_depthwise_BN[0][0] __________________________________________________________________________________________________ block_7_project (Conv2D) (None, 14, 14, 64) 24576 block_7_depthwise_relu[0][0] __________________________________________________________________________________________________ block_7_project_BN (BatchNormal (None, 14, 14, 64) 256 block_7_project[0][0] __________________________________________________________________________________________________ block_7_add (Add) (None, 14, 14, 64) 0 block_6_project_BN[0][0] block_7_project_BN[0][0] __________________________________________________________________________________________________ block_8_expand (Conv2D) (None, 14, 14, 384) 24576 block_7_add[0][0] __________________________________________________________________________________________________ block_8_expand_BN (BatchNormali (None, 14, 14, 384) 1536 block_8_expand[0][0] __________________________________________________________________________________________________ block_8_expand_relu (ReLU) (None, 14, 14, 384) 0 block_8_expand_BN[0][0] __________________________________________________________________________________________________ block_8_depthwise (DepthwiseCon (None, 14, 14, 384) 3456 block_8_expand_relu[0][0] __________________________________________________________________________________________________ block_8_depthwise_BN (BatchNorm (None, 14, 14, 384) 1536 block_8_depthwise[0][0] __________________________________________________________________________________________________ block_8_depthwise_relu (ReLU) (None, 14, 14, 384) 0 block_8_depthwise_BN[0][0] __________________________________________________________________________________________________ block_8_project (Conv2D) (None, 14, 14, 64) 24576 block_8_depthwise_relu[0][0] __________________________________________________________________________________________________ block_8_project_BN (BatchNormal (None, 14, 14, 64) 256 block_8_project[0][0] __________________________________________________________________________________________________ block_8_add (Add) (None, 14, 14, 64) 0 block_7_add[0][0] block_8_project_BN[0][0] __________________________________________________________________________________________________ block_9_expand (Conv2D) (None, 14, 14, 384) 24576 block_8_add[0][0] __________________________________________________________________________________________________ block_9_expand_BN (BatchNormali (None, 14, 14, 384) 1536 block_9_expand[0][0] __________________________________________________________________________________________________ block_9_expand_relu (ReLU) (None, 14, 14, 384) 0 block_9_expand_BN[0][0] __________________________________________________________________________________________________ block_9_depthwise (DepthwiseCon (None, 14, 14, 384) 3456 block_9_expand_relu[0][0] __________________________________________________________________________________________________ block_9_depthwise_BN (BatchNorm (None, 14, 14, 384) 1536 block_9_depthwise[0][0] __________________________________________________________________________________________________ block_9_depthwise_relu (ReLU) (None, 14, 14, 384) 0 block_9_depthwise_BN[0][0] __________________________________________________________________________________________________ block_9_project (Conv2D) (None, 14, 14, 64) 24576 block_9_depthwise_relu[0][0] __________________________________________________________________________________________________ block_9_project_BN (BatchNormal (None, 14, 14, 64) 256 block_9_project[0][0] __________________________________________________________________________________________________ block_9_add (Add) (None, 14, 14, 64) 0 block_8_add[0][0] block_9_project_BN[0][0] __________________________________________________________________________________________________ block_10_expand (Conv2D) (None, 14, 14, 384) 24576 block_9_add[0][0] __________________________________________________________________________________________________ block_10_expand_BN (BatchNormal (None, 14, 14, 384) 1536 block_10_expand[0][0] __________________________________________________________________________________________________ block_10_expand_relu (ReLU) (None, 14, 14, 384) 0 block_10_expand_BN[0][0] __________________________________________________________________________________________________ block_10_depthwise (DepthwiseCo (None, 14, 14, 384) 3456 block_10_expand_relu[0][0] __________________________________________________________________________________________________ block_10_depthwise_BN (BatchNor (None, 14, 14, 384) 1536 block_10_depthwise[0][0] __________________________________________________________________________________________________ block_10_depthwise_relu (ReLU) (None, 14, 14, 384) 0 block_10_depthwise_BN[0][0] __________________________________________________________________________________________________ block_10_project (Conv2D) (None, 14, 14, 96) 36864 block_10_depthwise_relu[0][0] __________________________________________________________________________________________________ block_10_project_BN (BatchNorma (None, 14, 14, 96) 384 block_10_project[0][0] __________________________________________________________________________________________________ block_11_expand (Conv2D) (None, 14, 14, 576) 55296 block_10_project_BN[0][0] __________________________________________________________________________________________________ block_11_expand_BN (BatchNormal (None, 14, 14, 576) 2304 block_11_expand[0][0] __________________________________________________________________________________________________ block_11_expand_relu (ReLU) (None, 14, 14, 576) 0 block_11_expand_BN[0][0] __________________________________________________________________________________________________ block_11_depthwise (DepthwiseCo (None, 14, 14, 576) 5184 block_11_expand_relu[0][0] __________________________________________________________________________________________________ block_11_depthwise_BN (BatchNor (None, 14, 14, 576) 2304 block_11_depthwise[0][0] __________________________________________________________________________________________________ block_11_depthwise_relu (ReLU) (None, 14, 14, 576) 0 block_11_depthwise_BN[0][0] __________________________________________________________________________________________________ block_11_project (Conv2D) (None, 14, 14, 96) 55296 block_11_depthwise_relu[0][0] __________________________________________________________________________________________________ block_11_project_BN (BatchNorma (None, 14, 14, 96) 384 block_11_project[0][0] __________________________________________________________________________________________________ block_11_add (Add) (None, 14, 14, 96) 0 block_10_project_BN[0][0] block_11_project_BN[0][0] __________________________________________________________________________________________________ block_12_expand (Conv2D) (None, 14, 14, 576) 55296 block_11_add[0][0] __________________________________________________________________________________________________ block_12_expand_BN (BatchNormal (None, 14, 14, 576) 2304 block_12_expand[0][0] __________________________________________________________________________________________________ block_12_expand_relu (ReLU) (None, 14, 14, 576) 0 block_12_expand_BN[0][0] __________________________________________________________________________________________________ block_12_depthwise (DepthwiseCo (None, 14, 14, 576) 5184 block_12_expand_relu[0][0] __________________________________________________________________________________________________ block_12_depthwise_BN (BatchNor (None, 14, 14, 576) 2304 block_12_depthwise[0][0] __________________________________________________________________________________________________ block_12_depthwise_relu (ReLU) (None, 14, 14, 576) 0 block_12_depthwise_BN[0][0] __________________________________________________________________________________________________ block_12_project (Conv2D) (None, 14, 14, 96) 55296 block_12_depthwise_relu[0][0] __________________________________________________________________________________________________ block_12_project_BN (BatchNorma (None, 14, 14, 96) 384 block_12_project[0][0] __________________________________________________________________________________________________ block_12_add (Add) (None, 14, 14, 96) 0 block_11_add[0][0] block_12_project_BN[0][0] __________________________________________________________________________________________________ block_13_expand (Conv2D) (None, 14, 14, 576) 55296 block_12_add[0][0] __________________________________________________________________________________________________ block_13_expand_BN (BatchNormal (None, 14, 14, 576) 2304 block_13_expand[0][0] __________________________________________________________________________________________________ block_13_expand_relu (ReLU) (None, 14, 14, 576) 0 block_13_expand_BN[0][0] __________________________________________________________________________________________________ block_13_pad (ZeroPadding2D) (None, 15, 15, 576) 0 block_13_expand_relu[0][0] __________________________________________________________________________________________________ block_13_depthwise (DepthwiseCo (None, 7, 7, 576) 5184 block_13_pad[0][0] __________________________________________________________________________________________________ block_13_depthwise_BN (BatchNor (None, 7, 7, 576) 2304 block_13_depthwise[0][0] __________________________________________________________________________________________________ block_13_depthwise_relu (ReLU) (None, 7, 7, 576) 0 block_13_depthwise_BN[0][0] __________________________________________________________________________________________________ block_13_project (Conv2D) (None, 7, 7, 160) 92160 block_13_depthwise_relu[0][0] __________________________________________________________________________________________________ block_13_project_BN (BatchNorma (None, 7, 7, 160) 640 block_13_project[0][0] __________________________________________________________________________________________________ block_14_expand (Conv2D) (None, 7, 7, 960) 153600 block_13_project_BN[0][0] __________________________________________________________________________________________________ block_14_expand_BN (BatchNormal (None, 7, 7, 960) 3840 block_14_expand[0][0] __________________________________________________________________________________________________ block_14_expand_relu (ReLU) (None, 7, 7, 960) 0 block_14_expand_BN[0][0] __________________________________________________________________________________________________ block_14_depthwise (DepthwiseCo (None, 7, 7, 960) 8640 block_14_expand_relu[0][0] __________________________________________________________________________________________________ block_14_depthwise_BN (BatchNor (None, 7, 7, 960) 3840 block_14_depthwise[0][0] __________________________________________________________________________________________________ block_14_depthwise_relu (ReLU) (None, 7, 7, 960) 0 block_14_depthwise_BN[0][0] __________________________________________________________________________________________________ block_14_project (Conv2D) (None, 7, 7, 160) 153600 block_14_depthwise_relu[0][0] __________________________________________________________________________________________________ block_14_project_BN (BatchNorma (None, 7, 7, 160) 640 block_14_project[0][0] __________________________________________________________________________________________________ block_14_add (Add) (None, 7, 7, 160) 0 block_13_project_BN[0][0] block_14_project_BN[0][0] __________________________________________________________________________________________________ block_15_expand (Conv2D) (None, 7, 7, 960) 153600 block_14_add[0][0] __________________________________________________________________________________________________ block_15_expand_BN (BatchNormal (None, 7, 7, 960) 3840 block_15_expand[0][0] __________________________________________________________________________________________________ block_15_expand_relu (ReLU) (None, 7, 7, 960) 0 block_15_expand_BN[0][0] __________________________________________________________________________________________________ block_15_depthwise (DepthwiseCo (None, 7, 7, 960) 8640 block_15_expand_relu[0][0] __________________________________________________________________________________________________ block_15_depthwise_BN (BatchNor (None, 7, 7, 960) 3840 block_15_depthwise[0][0] __________________________________________________________________________________________________ block_15_depthwise_relu (ReLU) (None, 7, 7, 960) 0 block_15_depthwise_BN[0][0] __________________________________________________________________________________________________ block_15_project (Conv2D) (None, 7, 7, 160) 153600 block_15_depthwise_relu[0][0] __________________________________________________________________________________________________ block_15_project_BN (BatchNorma (None, 7, 7, 160) 640 block_15_project[0][0] __________________________________________________________________________________________________ block_15_add (Add) (None, 7, 7, 160) 0 block_14_add[0][0] block_15_project_BN[0][0] __________________________________________________________________________________________________ block_16_expand (Conv2D) (None, 7, 7, 960) 153600 block_15_add[0][0] __________________________________________________________________________________________________ block_16_expand_BN (BatchNormal (None, 7, 7, 960) 3840 block_16_expand[0][0] __________________________________________________________________________________________________ block_16_expand_relu (ReLU) (None, 7, 7, 960) 0 block_16_expand_BN[0][0] __________________________________________________________________________________________________ block_16_depthwise (DepthwiseCo (None, 7, 7, 960) 8640 block_16_expand_relu[0][0] __________________________________________________________________________________________________ block_16_depthwise_BN (BatchNor (None, 7, 7, 960) 3840 block_16_depthwise[0][0] __________________________________________________________________________________________________ block_16_depthwise_relu (ReLU) (None, 7, 7, 960) 0 block_16_depthwise_BN[0][0] __________________________________________________________________________________________________ block_16_project (Conv2D) (None, 7, 7, 320) 307200 block_16_depthwise_relu[0][0] __________________________________________________________________________________________________ block_16_project_BN (BatchNorma (None, 7, 7, 320) 1280 block_16_project[0][0] __________________________________________________________________________________________________ Conv_1 (Conv2D) (None, 7, 7, 1280) 409600 block_16_project_BN[0][0] __________________________________________________________________________________________________ Conv_1_bn (BatchNormalization) (None, 7, 7, 1280) 5120 Conv_1[0][0] __________________________________________________________________________________________________ out_relu (ReLU) (None, 7, 7, 1280) 0 Conv_1_bn[0][0] __________________________________________________________________________________________________ global_average_pooling2d (Globa (None, 1280) 0 out_relu[0][0] __________________________________________________________________________________________________ Logits (Dense) (None, 1000) 1281000 global_average_pooling2d[0][0] ================================================================================================== Total params: 3,538,984 Trainable params: 3,504,872 Non-trainable params: 34,112 __________________________________________________________________________________________________
In order to plot the model the graphviz
should be installed. For Mac OS it may be installed using brew
like brew install graphviz
.
tf.keras.utils.plot_model(model, show_shapes=True, show_layer_names=True)
INPUT_IMAGE_SIZE = model.get_input_shape_at(0)[1]
print('INPUT_IMAGE_SIZE:', INPUT_IMAGE_SIZE)
INPUT_IMAGE_SIZE: 224
LABELS_URL = 'https://storage.googleapis.com/download.tensorflow.org/data/ImageNetLabels.txt'
labels_path = tf.keras.utils.get_file('ImageNetLabels.txt', LABELS_URL)
labels = np.array(
open(labels_path).read().splitlines()
)[1:]
print('Labels shape:', labels.shape)
Labels shape: (1000,)
print(labels)
['tench' 'goldfish' 'great white shark' 'tiger shark' 'hammerhead' 'electric ray' 'stingray' 'cock' 'hen' 'ostrich' 'brambling' 'goldfinch' 'house finch' 'junco' 'indigo bunting' 'robin' 'bulbul' 'jay' 'magpie' 'chickadee' 'water ouzel' 'kite' 'bald eagle' 'vulture' 'great grey owl' 'European fire salamander' 'common newt' 'eft' 'spotted salamander' 'axolotl' 'bullfrog' 'tree frog' 'tailed frog' 'loggerhead' 'leatherback turtle' 'mud turtle' 'terrapin' 'box turtle' 'banded gecko' 'common iguana' 'American chameleon' 'whiptail' 'agama' 'frilled lizard' 'alligator lizard' 'Gila monster' 'green lizard' 'African chameleon' 'Komodo dragon' 'African crocodile' 'American alligator' 'triceratops' 'thunder snake' 'ringneck snake' 'hognose snake' 'green snake' 'king snake' 'garter snake' 'water snake' 'vine snake' 'night snake' 'boa constrictor' 'rock python' 'Indian cobra' 'green mamba' 'sea snake' 'horned viper' 'diamondback' 'sidewinder' 'trilobite' 'harvestman' 'scorpion' 'black and gold garden spider' 'barn spider' 'garden spider' 'black widow' 'tarantula' 'wolf spider' 'tick' 'centipede' 'black grouse' 'ptarmigan' 'ruffed grouse' 'prairie chicken' 'peacock' 'quail' 'partridge' 'African grey' 'macaw' 'sulphur-crested cockatoo' 'lorikeet' 'coucal' 'bee eater' 'hornbill' 'hummingbird' 'jacamar' 'toucan' 'drake' 'red-breasted merganser' 'goose' 'black swan' 'tusker' 'echidna' 'platypus' 'wallaby' 'koala' 'wombat' 'jellyfish' 'sea anemone' 'brain coral' 'flatworm' 'nematode' 'conch' 'snail' 'slug' 'sea slug' 'chiton' 'chambered nautilus' 'Dungeness crab' 'rock crab' 'fiddler crab' 'king crab' 'American lobster' 'spiny lobster' 'crayfish' 'hermit crab' 'isopod' 'white stork' 'black stork' 'spoonbill' 'flamingo' 'little blue heron' 'American egret' 'bittern' 'crane' 'limpkin' 'European gallinule' 'American coot' 'bustard' 'ruddy turnstone' 'red-backed sandpiper' 'redshank' 'dowitcher' 'oystercatcher' 'pelican' 'king penguin' 'albatross' 'grey whale' 'killer whale' 'dugong' 'sea lion' 'Chihuahua' 'Japanese spaniel' 'Maltese dog' 'Pekinese' 'Shih-Tzu' 'Blenheim spaniel' 'papillon' 'toy terrier' 'Rhodesian ridgeback' 'Afghan hound' 'basset' 'beagle' 'bloodhound' 'bluetick' 'black-and-tan coonhound' 'Walker hound' 'English foxhound' 'redbone' 'borzoi' 'Irish wolfhound' 'Italian greyhound' 'whippet' 'Ibizan hound' 'Norwegian elkhound' 'otterhound' 'Saluki' 'Scottish deerhound' 'Weimaraner' 'Staffordshire bullterrier' 'American Staffordshire terrier' 'Bedlington terrier' 'Border terrier' 'Kerry blue terrier' 'Irish terrier' 'Norfolk terrier' 'Norwich terrier' 'Yorkshire terrier' 'wire-haired fox terrier' 'Lakeland terrier' 'Sealyham terrier' 'Airedale' 'cairn' 'Australian terrier' 'Dandie Dinmont' 'Boston bull' 'miniature schnauzer' 'giant schnauzer' 'standard schnauzer' 'Scotch terrier' 'Tibetan terrier' 'silky terrier' 'soft-coated wheaten terrier' 'West Highland white terrier' 'Lhasa' 'flat-coated retriever' 'curly-coated retriever' 'golden retriever' 'Labrador retriever' 'Chesapeake Bay retriever' 'German short-haired pointer' 'vizsla' 'English setter' 'Irish setter' 'Gordon setter' 'Brittany spaniel' 'clumber' 'English springer' 'Welsh springer spaniel' 'cocker spaniel' 'Sussex spaniel' 'Irish water spaniel' 'kuvasz' 'schipperke' 'groenendael' 'malinois' 'briard' 'kelpie' 'komondor' 'Old English sheepdog' 'Shetland sheepdog' 'collie' 'Border collie' 'Bouvier des Flandres' 'Rottweiler' 'German shepherd' 'Doberman' 'miniature pinscher' 'Greater Swiss Mountain dog' 'Bernese mountain dog' 'Appenzeller' 'EntleBucher' 'boxer' 'bull mastiff' 'Tibetan mastiff' 'French bulldog' 'Great Dane' 'Saint Bernard' 'Eskimo dog' 'malamute' 'Siberian husky' 'dalmatian' 'affenpinscher' 'basenji' 'pug' 'Leonberg' 'Newfoundland' 'Great Pyrenees' 'Samoyed' 'Pomeranian' 'chow' 'keeshond' 'Brabancon griffon' 'Pembroke' 'Cardigan' 'toy poodle' 'miniature poodle' 'standard poodle' 'Mexican hairless' 'timber wolf' 'white wolf' 'red wolf' 'coyote' 'dingo' 'dhole' 'African hunting dog' 'hyena' 'red fox' 'kit fox' 'Arctic fox' 'grey fox' 'tabby' 'tiger cat' 'Persian cat' 'Siamese cat' 'Egyptian cat' 'cougar' 'lynx' 'leopard' 'snow leopard' 'jaguar' 'lion' 'tiger' 'cheetah' 'brown bear' 'American black bear' 'ice bear' 'sloth bear' 'mongoose' 'meerkat' 'tiger beetle' 'ladybug' 'ground beetle' 'long-horned beetle' 'leaf beetle' 'dung beetle' 'rhinoceros beetle' 'weevil' 'fly' 'bee' 'ant' 'grasshopper' 'cricket' 'walking stick' 'cockroach' 'mantis' 'cicada' 'leafhopper' 'lacewing' 'dragonfly' 'damselfly' 'admiral' 'ringlet' 'monarch' 'cabbage butterfly' 'sulphur butterfly' 'lycaenid' 'starfish' 'sea urchin' 'sea cucumber' 'wood rabbit' 'hare' 'Angora' 'hamster' 'porcupine' 'fox squirrel' 'marmot' 'beaver' 'guinea pig' 'sorrel' 'zebra' 'hog' 'wild boar' 'warthog' 'hippopotamus' 'ox' 'water buffalo' 'bison' 'ram' 'bighorn' 'ibex' 'hartebeest' 'impala' 'gazelle' 'Arabian camel' 'llama' 'weasel' 'mink' 'polecat' 'black-footed ferret' 'otter' 'skunk' 'badger' 'armadillo' 'three-toed sloth' 'orangutan' 'gorilla' 'chimpanzee' 'gibbon' 'siamang' 'guenon' 'patas' 'baboon' 'macaque' 'langur' 'colobus' 'proboscis monkey' 'marmoset' 'capuchin' 'howler monkey' 'titi' 'spider monkey' 'squirrel monkey' 'Madagascar cat' 'indri' 'Indian elephant' 'African elephant' 'lesser panda' 'giant panda' 'barracouta' 'eel' 'coho' 'rock beauty' 'anemone fish' 'sturgeon' 'gar' 'lionfish' 'puffer' 'abacus' 'abaya' 'academic gown' 'accordion' 'acoustic guitar' 'aircraft carrier' 'airliner' 'airship' 'altar' 'ambulance' 'amphibian' 'analog clock' 'apiary' 'apron' 'ashcan' 'assault rifle' 'backpack' 'bakery' 'balance beam' 'balloon' 'ballpoint' 'Band Aid' 'banjo' 'bannister' 'barbell' 'barber chair' 'barbershop' 'barn' 'barometer' 'barrel' 'barrow' 'baseball' 'basketball' 'bassinet' 'bassoon' 'bathing cap' 'bath towel' 'bathtub' 'beach wagon' 'beacon' 'beaker' 'bearskin' 'beer bottle' 'beer glass' 'bell cote' 'bib' 'bicycle-built-for-two' 'bikini' 'binder' 'binoculars' 'birdhouse' 'boathouse' 'bobsled' 'bolo tie' 'bonnet' 'bookcase' 'bookshop' 'bottlecap' 'bow' 'bow tie' 'brass' 'brassiere' 'breakwater' 'breastplate' 'broom' 'bucket' 'buckle' 'bulletproof vest' 'bullet train' 'butcher shop' 'cab' 'caldron' 'candle' 'cannon' 'canoe' 'can opener' 'cardigan' 'car mirror' 'carousel' "carpenter's kit" 'carton' 'car wheel' 'cash machine' 'cassette' 'cassette player' 'castle' 'catamaran' 'CD player' 'cello' 'cellular telephone' 'chain' 'chainlink fence' 'chain mail' 'chain saw' 'chest' 'chiffonier' 'chime' 'china cabinet' 'Christmas stocking' 'church' 'cinema' 'cleaver' 'cliff dwelling' 'cloak' 'clog' 'cocktail shaker' 'coffee mug' 'coffeepot' 'coil' 'combination lock' 'computer keyboard' 'confectionery' 'container ship' 'convertible' 'corkscrew' 'cornet' 'cowboy boot' 'cowboy hat' 'cradle' 'crane' 'crash helmet' 'crate' 'crib' 'Crock Pot' 'croquet ball' 'crutch' 'cuirass' 'dam' 'desk' 'desktop computer' 'dial telephone' 'diaper' 'digital clock' 'digital watch' 'dining table' 'dishrag' 'dishwasher' 'disk brake' 'dock' 'dogsled' 'dome' 'doormat' 'drilling platform' 'drum' 'drumstick' 'dumbbell' 'Dutch oven' 'electric fan' 'electric guitar' 'electric locomotive' 'entertainment center' 'envelope' 'espresso maker' 'face powder' 'feather boa' 'file' 'fireboat' 'fire engine' 'fire screen' 'flagpole' 'flute' 'folding chair' 'football helmet' 'forklift' 'fountain' 'fountain pen' 'four-poster' 'freight car' 'French horn' 'frying pan' 'fur coat' 'garbage truck' 'gasmask' 'gas pump' 'goblet' 'go-kart' 'golf ball' 'golfcart' 'gondola' 'gong' 'gown' 'grand piano' 'greenhouse' 'grille' 'grocery store' 'guillotine' 'hair slide' 'hair spray' 'half track' 'hammer' 'hamper' 'hand blower' 'hand-held computer' 'handkerchief' 'hard disc' 'harmonica' 'harp' 'harvester' 'hatchet' 'holster' 'home theater' 'honeycomb' 'hook' 'hoopskirt' 'horizontal bar' 'horse cart' 'hourglass' 'iPod' 'iron' "jack-o'-lantern" 'jean' 'jeep' 'jersey' 'jigsaw puzzle' 'jinrikisha' 'joystick' 'kimono' 'knee pad' 'knot' 'lab coat' 'ladle' 'lampshade' 'laptop' 'lawn mower' 'lens cap' 'letter opener' 'library' 'lifeboat' 'lighter' 'limousine' 'liner' 'lipstick' 'Loafer' 'lotion' 'loudspeaker' 'loupe' 'lumbermill' 'magnetic compass' 'mailbag' 'mailbox' 'maillot' 'maillot' 'manhole cover' 'maraca' 'marimba' 'mask' 'matchstick' 'maypole' 'maze' 'measuring cup' 'medicine chest' 'megalith' 'microphone' 'microwave' 'military uniform' 'milk can' 'minibus' 'miniskirt' 'minivan' 'missile' 'mitten' 'mixing bowl' 'mobile home' 'Model T' 'modem' 'monastery' 'monitor' 'moped' 'mortar' 'mortarboard' 'mosque' 'mosquito net' 'motor scooter' 'mountain bike' 'mountain tent' 'mouse' 'mousetrap' 'moving van' 'muzzle' 'nail' 'neck brace' 'necklace' 'nipple' 'notebook' 'obelisk' 'oboe' 'ocarina' 'odometer' 'oil filter' 'organ' 'oscilloscope' 'overskirt' 'oxcart' 'oxygen mask' 'packet' 'paddle' 'paddlewheel' 'padlock' 'paintbrush' 'pajama' 'palace' 'panpipe' 'paper towel' 'parachute' 'parallel bars' 'park bench' 'parking meter' 'passenger car' 'patio' 'pay-phone' 'pedestal' 'pencil box' 'pencil sharpener' 'perfume' 'Petri dish' 'photocopier' 'pick' 'pickelhaube' 'picket fence' 'pickup' 'pier' 'piggy bank' 'pill bottle' 'pillow' 'ping-pong ball' 'pinwheel' 'pirate' 'pitcher' 'plane' 'planetarium' 'plastic bag' 'plate rack' 'plow' 'plunger' 'Polaroid camera' 'pole' 'police van' 'poncho' 'pool table' 'pop bottle' 'pot' "potter's wheel" 'power drill' 'prayer rug' 'printer' 'prison' 'projectile' 'projector' 'puck' 'punching bag' 'purse' 'quill' 'quilt' 'racer' 'racket' 'radiator' 'radio' 'radio telescope' 'rain barrel' 'recreational vehicle' 'reel' 'reflex camera' 'refrigerator' 'remote control' 'restaurant' 'revolver' 'rifle' 'rocking chair' 'rotisserie' 'rubber eraser' 'rugby ball' 'rule' 'running shoe' 'safe' 'safety pin' 'saltshaker' 'sandal' 'sarong' 'sax' 'scabbard' 'scale' 'school bus' 'schooner' 'scoreboard' 'screen' 'screw' 'screwdriver' 'seat belt' 'sewing machine' 'shield' 'shoe shop' 'shoji' 'shopping basket' 'shopping cart' 'shovel' 'shower cap' 'shower curtain' 'ski' 'ski mask' 'sleeping bag' 'slide rule' 'sliding door' 'slot' 'snorkel' 'snowmobile' 'snowplow' 'soap dispenser' 'soccer ball' 'sock' 'solar dish' 'sombrero' 'soup bowl' 'space bar' 'space heater' 'space shuttle' 'spatula' 'speedboat' 'spider web' 'spindle' 'sports car' 'spotlight' 'stage' 'steam locomotive' 'steel arch bridge' 'steel drum' 'stethoscope' 'stole' 'stone wall' 'stopwatch' 'stove' 'strainer' 'streetcar' 'stretcher' 'studio couch' 'stupa' 'submarine' 'suit' 'sundial' 'sunglass' 'sunglasses' 'sunscreen' 'suspension bridge' 'swab' 'sweatshirt' 'swimming trunks' 'swing' 'switch' 'syringe' 'table lamp' 'tank' 'tape player' 'teapot' 'teddy' 'television' 'tennis ball' 'thatch' 'theater curtain' 'thimble' 'thresher' 'throne' 'tile roof' 'toaster' 'tobacco shop' 'toilet seat' 'torch' 'totem pole' 'tow truck' 'toyshop' 'tractor' 'trailer truck' 'tray' 'trench coat' 'tricycle' 'trimaran' 'tripod' 'triumphal arch' 'trolleybus' 'trombone' 'tub' 'turnstile' 'typewriter keyboard' 'umbrella' 'unicycle' 'upright' 'vacuum' 'vase' 'vault' 'velvet' 'vending machine' 'vestment' 'viaduct' 'violin' 'volleyball' 'waffle iron' 'wall clock' 'wallet' 'wardrobe' 'warplane' 'washbasin' 'washer' 'water bottle' 'water jug' 'water tower' 'whiskey jug' 'whistle' 'wig' 'window screen' 'window shade' 'Windsor tie' 'wine bottle' 'wing' 'wok' 'wooden spoon' 'wool' 'worm fence' 'wreck' 'yawl' 'yurt' 'web site' 'comic book' 'crossword puzzle' 'street sign' 'traffic light' 'book jacket' 'menu' 'plate' 'guacamole' 'consomme' 'hot pot' 'trifle' 'ice cream' 'ice lolly' 'French loaf' 'bagel' 'pretzel' 'cheeseburger' 'hotdog' 'mashed potato' 'head cabbage' 'broccoli' 'cauliflower' 'zucchini' 'spaghetti squash' 'acorn squash' 'butternut squash' 'cucumber' 'artichoke' 'bell pepper' 'cardoon' 'mushroom' 'Granny Smith' 'strawberry' 'orange' 'lemon' 'fig' 'pineapple' 'banana' 'jackfruit' 'custard apple' 'pomegranate' 'hay' 'carbonara' 'chocolate sauce' 'dough' 'meat loaf' 'pizza' 'potpie' 'burrito' 'red wine' 'espresso' 'cup' 'eggnog' 'alp' 'bubble' 'cliff' 'coral reef' 'geyser' 'lakeside' 'promontory' 'sandbar' 'seashore' 'valley' 'volcano' 'ballplayer' 'groom' 'scuba diver' 'rapeseed' 'daisy' "yellow lady's slipper" 'corn' 'acorn' 'hip' 'buckeye' 'coral fungus' 'agaric' 'gyromitra' 'stinkhorn' 'earthstar' 'hen-of-the-woods' 'bolete' 'ear' 'toilet tissue']
def load_image(image_path):
return tf.keras.preprocessing.image.load_img(
image_path,
target_size=[INPUT_IMAGE_SIZE, INPUT_IMAGE_SIZE]
)
def image_to_array(image):
return tf.keras.preprocessing.image.img_to_array(image, dtype=np.int32)
def display_image(image_np):
plt.figure()
plt.imshow(image_np)
TEST_IMAGES_DIR_PATH = pathlib.Path('data')
TEST_IMAGE_PATHS = sorted(list(TEST_IMAGES_DIR_PATH.glob('*.jpg')))
TEST_IMAGE_PATHS
[PosixPath('data/banana.jpg'), PosixPath('data/city.jpg'), PosixPath('data/dogs.jpg'), PosixPath('data/ship.jpg'), PosixPath('data/street.jpg')]
test_images = []
for image_path in TEST_IMAGE_PATHS:
# <PIL.Image.Image image mode=RGB size=224x224 at 0x141247ED0>
test_image = load_image(image_path)
test_image_array = image_to_array(test_image)
test_images.append(test_image_array)
display_image(test_image_array)
print(test_images[1])
[[[ 35 26 21] [ 36 26 24] [ 31 23 20] ... [228 219 222] [228 219 222] [227 218 221]] [[ 31 23 21] [ 33 25 23] [ 28 25 20] ... [223 214 217] [219 210 213] [219 210 213]] [[ 36 26 25] [ 30 25 22] [ 26 25 20] ... [219 210 213] [216 207 210] [217 208 211]] ... [[ 31 24 18] [ 29 22 16] [ 29 22 16] ... [ 73 54 37] [116 100 85] [ 55 41 28]] [[ 29 22 16] [ 28 21 15] [ 29 22 16] ... [ 64 48 32] [ 43 31 17] [ 42 32 20]] [[ 31 24 18] [ 29 22 16] [ 29 22 16] ... [ 51 41 31] [ 55 42 33] [ 55 43 31]]]
def image_preprocess(image_array):
return tf.keras.applications.mobilenet_v2.preprocess_input(
image_array[tf.newaxis, ...]
)
test_images_preprocessed = []
for test_image in test_images:
test_image_preprocessed = image_preprocess(test_image)
test_images_preprocessed.append(test_image_preprocessed)
print('Image shape before preprocessing:', test_images[0].shape)
print('Image shape after preprocessing:', test_images_preprocessed[0].shape)
Image shape before preprocessing: (224, 224, 3) Image shape after preprocessing: (1, 224, 224, 3)
print(test_images_preprocessed[1])
[[[[-0.7254902 -0.79607844 -0.8352941 ] [-0.7176471 -0.79607844 -0.8117647 ] [-0.75686276 -0.81960785 -0.84313726] ... [ 0.7882353 0.7176471 0.7411765 ] [ 0.7882353 0.7176471 0.7411765 ] [ 0.78039217 0.70980394 0.73333335]] [[-0.75686276 -0.81960785 -0.8352941 ] [-0.7411765 -0.8039216 -0.81960785] [-0.78039217 -0.8039216 -0.84313726] ... [ 0.7490196 0.6784314 0.7019608 ] [ 0.7176471 0.64705884 0.67058825] [ 0.7176471 0.64705884 0.67058825]] [[-0.7176471 -0.79607844 -0.8039216 ] [-0.7647059 -0.8039216 -0.827451 ] [-0.79607844 -0.8039216 -0.84313726] ... [ 0.7176471 0.64705884 0.67058825] [ 0.69411767 0.62352943 0.64705884] [ 0.7019608 0.6313726 0.654902 ]] ... [[-0.75686276 -0.8117647 -0.85882354] [-0.77254903 -0.827451 -0.8745098 ] [-0.77254903 -0.827451 -0.8745098 ] ... [-0.42745095 -0.5764706 -0.70980394] [-0.09019607 -0.21568626 -0.3333333 ] [-0.5686275 -0.6784314 -0.78039217]] [[-0.77254903 -0.827451 -0.8745098 ] [-0.78039217 -0.8352941 -0.88235295] [-0.77254903 -0.827451 -0.8745098 ] ... [-0.4980392 -0.62352943 -0.7490196 ] [-0.6627451 -0.75686276 -0.8666667 ] [-0.67058825 -0.7490196 -0.84313726]] [[-0.75686276 -0.8117647 -0.85882354] [-0.77254903 -0.827451 -0.8745098 ] [-0.77254903 -0.827451 -0.8745098 ] ... [-0.6 -0.6784314 -0.75686276] [-0.5686275 -0.67058825 -0.7411765 ] [-0.5686275 -0.6627451 -0.75686276]]]]
def get_tags(probs, labels, max_classes = 5, prob_threshold = 0.01):
probs_mask = probs > prob_threshold
probs_filtered = probs[probs_mask] * 100
labels_filtered = labels[probs_mask]
sorted_index = np.flip(np.argsort(probs_filtered))
labels_filtered = labels_filtered[sorted_index][:max_classes]
probs_filtered = probs_filtered[sorted_index][:max_classes].astype(np.int)
tags = ''
for i in range(0, len(labels_filtered)):
tags = tags + labels_filtered[i] + ' (' + str(probs_filtered[i]) + '%), '
return tags, labels_filtered, probs_filtered
TEST_IMAGE_INDEX = 1
result = model(test_images_preprocessed[TEST_IMAGE_INDEX])
result.shape
TensorShape([1, 1000])
print(result)
tf.Tensor( [[1.67357328e-04 7.48886960e-05 9.10225790e-05 1.61429649e-04 1.80477553e-04 2.01649018e-05 2.37957895e-04 1.66809506e-04 1.43144003e-04 1.60500538e-04 1.40027434e-04 7.66541052e-05 2.55448394e-04 1.01829886e-04 6.68075882e-05 6.71937887e-05 1.74754183e-04 4.76423484e-05 1.60923169e-04 2.91181699e-04 5.66527633e-05 5.96032805e-05 4.86944009e-05 2.32021936e-04 6.23657179e-05 1.27928943e-04 1.92076041e-04 6.28614274e-04 1.78236514e-04 1.19395932e-04 9.80493860e-05 3.75609598e-05 3.84934683e-04 1.28144806e-04 1.17247058e-04 1.13339731e-04 1.55172413e-04 4.41422366e-04 4.54554429e-05 1.81667769e-04 6.85919586e-05 2.61485839e-04 1.82488497e-04 7.38181407e-05 3.72787035e-04 2.17093329e-04 7.59527611e-05 6.37365811e-05 7.39252137e-05 5.10215614e-05 2.00286537e-04 3.32779928e-05 3.73418967e-04 1.86561752e-04 3.07171467e-05 5.00616334e-05 7.99422851e-05 2.87409755e-04 1.48447871e-04 3.89670386e-05 1.82260028e-05 1.02116865e-04 2.26840348e-05 1.01948033e-04 5.41410955e-05 6.08378250e-05 1.15725146e-04 7.38108793e-05 1.52765657e-04 1.65693229e-04 1.96085413e-04 8.52664380e-05 6.62517923e-05 7.21684701e-05 1.44252786e-04 1.86123783e-04 1.40939417e-04 7.23011544e-05 1.99576112e-04 3.21566069e-04 4.61737727e-05 5.21688024e-04 1.13047085e-04 1.92566018e-04 6.06839749e-05 9.62445047e-05 1.13117931e-04 9.02370957e-05 9.22817344e-05 1.01368380e-04 3.59182188e-04 1.62126234e-04 2.08516853e-04 3.47721216e-05 3.64632229e-04 3.01419204e-04 6.83444887e-05 1.31897861e-04 1.95828077e-04 1.06738582e-04 1.74555971e-04 2.53571226e-04 1.87643338e-04 1.56295209e-04 1.18525888e-04 6.26458277e-05 1.59868941e-04 8.11573700e-05 1.25057864e-04 1.17108604e-04 7.13126574e-05 5.54172475e-05 9.23214393e-05 1.64395955e-04 3.52056144e-04 2.47819873e-04 8.78320789e-05 5.41064583e-05 2.01308751e-04 1.49956046e-04 1.57278395e-04 2.40579466e-04 1.85823956e-04 1.22923564e-04 2.21942173e-04 4.40764670e-05 1.16574083e-04 3.04487068e-04 2.83238012e-04 1.61682008e-04 3.96540359e-04 1.05197752e-04 2.41361529e-04 1.11718109e-04 7.25388119e-04 1.80169984e-04 1.58088631e-04 9.85863735e-05 6.95664276e-05 1.47213708e-04 1.12825524e-04 1.60540803e-04 3.38791142e-04 7.71324485e-05 2.15697553e-04 5.11942962e-05 3.77704855e-05 6.30176364e-05 4.72086365e-04 1.11339141e-04 9.47190798e-04 1.13887545e-04 2.38809167e-04 2.06700686e-04 7.80091039e-04 1.96210734e-04 1.76762536e-04 1.71593929e-04 3.93578463e-04 1.08376778e-04 9.31922332e-05 2.96955899e-04 1.41593759e-04 7.23419143e-05 1.04821716e-04 1.74653047e-04 1.27286985e-04 1.02071099e-04 1.29239445e-04 8.04442097e-05 2.92383804e-04 6.03596563e-05 1.31854715e-04 1.18426688e-04 3.04332178e-04 3.53113661e-04 5.07758486e-05 9.92798305e-05 1.24749946e-04 5.67539937e-05 3.71809401e-05 3.46395303e-04 8.81566433e-04 6.49011927e-05 8.02722760e-04 2.04695854e-04 2.40250476e-04 5.78261970e-05 1.20262150e-04 3.45854933e-04 1.42004035e-04 2.21934126e-04 5.74710939e-05 1.14472394e-04 8.17674518e-05 1.23496735e-04 2.06799377e-04 6.43156091e-05 6.76670170e-05 1.29037842e-04 1.10540132e-04 1.17918869e-04 1.18846889e-04 1.28439438e-04 1.04448409e-04 9.96431263e-05 1.58541574e-04 2.47384654e-04 6.22294901e-05 1.42855715e-04 9.40137397e-05 2.98859406e-04 1.72066531e-04 2.51497404e-04 2.13951949e-04 1.82864358e-04 3.25560832e-04 2.65320239e-04 1.52477471e-04 1.38287229e-04 4.21349599e-04 4.76433459e-04 9.71817644e-05 2.18461602e-04 2.75821018e-04 1.65611098e-04 1.95778965e-04 9.95107403e-05 1.90569117e-04 6.79200675e-05 2.68582575e-04 1.42772551e-04 1.21785415e-04 8.38747219e-05 9.36725919e-05 1.53051835e-04 2.68764998e-04 2.97076855e-04 7.53670174e-05 1.28449363e-04 2.45624251e-04 6.00717212e-05 7.90790727e-05 4.12735426e-05 1.10393914e-04 2.92747223e-04 1.03377053e-04 1.82162214e-04 3.87734945e-05 1.65707766e-04 1.51658227e-04 1.61610937e-04 1.82058182e-04 2.05814838e-04 2.02232943e-04 9.53260023e-05 2.98828498e-04 3.33915988e-04 9.96771560e-05 1.87070938e-04 1.79301540e-04 1.83119584e-04 3.12310149e-04 1.38238378e-04 3.00599750e-05 1.56912458e-04 1.16694326e-04 1.25714461e-04 2.13557985e-04 1.56702430e-04 2.74436810e-04 1.46911902e-04 4.39555122e-04 7.41670738e-05 6.72850947e-05 2.08303973e-05 3.55755037e-05 1.91525833e-04 8.93982651e-05 1.92051681e-04 9.68867462e-05 1.57627583e-04 2.27602693e-04 1.31187306e-04 1.64624085e-04 2.75210739e-04 1.33124297e-04 1.95651286e-04 7.76510860e-05 9.62153135e-05 4.54786234e-04 6.56663542e-05 2.37827669e-04 3.40095721e-05 2.10821221e-04 1.70597210e-04 1.26792918e-04 1.78063550e-04 1.36804723e-04 5.95220481e-05 4.80892224e-04 9.18859369e-05 1.84604578e-04 1.39191310e-04 2.91351142e-04 2.36900014e-04 1.32085916e-04 2.27185548e-04 1.45869926e-04 8.80977605e-05 1.98933645e-04 1.41513432e-04 2.88640877e-04 3.83168408e-05 7.85072334e-05 3.02854260e-05 9.82208439e-05 1.41690267e-04 1.43693149e-04 1.66590427e-04 1.32049012e-04 2.44498835e-04 1.98872644e-04 2.14436484e-04 1.38428673e-04 2.09264414e-04 1.33705107e-04 5.08142402e-04 4.56837937e-04 1.20619487e-04 1.98008827e-04 3.31353134e-04 1.81024254e-04 2.18643123e-04 1.27678344e-04 6.49769034e-04 2.80206878e-04 7.99543268e-05 1.66537531e-04 1.94384847e-04 1.30818516e-04 2.17383582e-04 1.59268835e-04 6.85101113e-05 7.75048175e-05 4.33948007e-04 1.96583554e-04 3.51238377e-05 1.47340470e-04 1.01998216e-04 9.11554089e-05 1.32211426e-04 6.77166536e-05 8.04037918e-05 4.37622512e-05 8.75672049e-05 1.70788480e-04 3.90449306e-04 3.14480887e-04 2.11017134e-04 1.56760274e-04 1.32804867e-04 1.77957354e-05 3.50671413e-04 1.15747338e-04 2.67752301e-04 5.40343717e-05 7.03712867e-05 1.14286093e-04 2.76649778e-04 2.52920581e-04 1.19134893e-04 1.78383605e-04 2.94235419e-04 1.51324857e-04 1.67897975e-04 1.94346008e-04 1.17992771e-04 9.32319599e-05 1.60808951e-04 2.55117164e-04 3.64112173e-04 8.62851884e-05 5.07094992e-05 2.83875532e-04 2.52050115e-04 5.90971576e-05 2.85809656e-04 1.88095379e-04 1.27586929e-04 4.37917224e-05 3.87920853e-04 7.41973563e-05 8.77350540e-05 8.15246021e-05 2.35257496e-04 1.90197636e-04 8.50121287e-05 2.37704531e-04 1.03099308e-04 2.59184133e-04 4.60767769e-05 1.80213465e-04 7.27412337e-03 3.11539538e-04 1.56120828e-03 4.44631267e-04 2.66253279e-04 8.42514797e-04 3.09255061e-04 2.15319797e-05 1.06556319e-04 7.75268069e-04 7.49748797e-05 6.37864432e-05 1.41168421e-05 1.45275726e-05 5.06322074e-04 3.15404614e-04 6.64380670e-04 2.40592082e-04 2.16024360e-04 6.13866505e-05 8.78105566e-05 5.46784031e-05 3.20850668e-05 4.90134080e-05 7.93228101e-05 7.77184978e-05 7.58772600e-04 1.71554580e-04 9.17959915e-05 7.23952617e-05 3.19199207e-05 2.13496809e-04 7.21321485e-05 2.24105643e-05 3.13031167e-04 4.55443987e-05 6.87055173e-04 6.09505165e-04 4.57360235e-04 4.99408506e-03 1.09396911e-04 2.88811152e-05 1.45948055e-04 8.17528708e-05 1.09756237e-03 1.87502024e-04 2.04540323e-03 1.23364429e-04 1.84171557e-04 5.65130540e-05 1.50492080e-04 1.41106982e-04 1.38743504e-04 2.53782018e-05 6.33907475e-05 1.61757358e-04 3.93228052e-04 1.27267092e-02 1.01859790e-04 1.71431107e-04 9.77969612e-05 1.58332448e-04 6.63650499e-05 5.41307440e-04 1.21139397e-04 1.61333301e-03 5.97645812e-05 2.56448784e-05 1.49999117e-03 5.32147882e-04 5.82903798e-04 3.95592448e-04 1.42487115e-04 3.28893366e-04 1.94963159e-05 3.87864973e-04 8.83529574e-05 8.88068462e-05 5.36482199e-04 2.73689948e-04 1.51329990e-02 1.62611832e-04 8.26883188e-05 1.96636902e-04 3.48623173e-04 2.98071827e-04 5.44828421e-04 1.29765438e-04 5.10983045e-05 1.76515925e-04 2.76940264e-04 5.70710217e-05 6.50954025e-05 1.42366844e-04 2.23277719e-03 1.35558788e-04 1.71005900e-04 9.01887470e-05 3.87938780e-04 6.36503246e-05 3.56488832e-04 4.31275184e-05 1.05291809e-04 8.26198157e-05 3.62519757e-04 4.55220346e-04 6.31531875e-04 2.03710259e-03 6.42493324e-05 2.54170678e-04 1.18964701e-04 2.87157254e-05 1.17950804e-04 1.12647373e-04 2.07547098e-03 1.48444466e-04 3.97456170e-04 1.00609745e-04 1.62285491e-04 6.88708678e-05 6.21697618e-05 1.85760087e-04 2.62780534e-03 8.74956677e-05 8.75948535e-05 8.01707865e-05 1.40172342e-04 9.30300448e-04 4.53038010e-05 5.10637146e-05 3.94132658e-04 3.87863292e-05 7.26157741e-05 3.99216026e-01 4.19301432e-05 4.02754033e-03 1.54149602e-05 2.65294453e-03 1.35875700e-04 3.69741378e-04 1.08514425e-04 9.72095731e-05 2.07789308e-05 3.73110175e-04 4.26259823e-04 2.01917006e-04 2.42721566e-04 1.11561283e-04 1.89086903e-04 4.28869273e-04 4.63015604e-05 8.90578050e-03 3.50718212e-04 9.62700215e-05 4.09287459e-04 2.39198689e-05 1.85963741e-04 3.04453948e-04 4.29403735e-05 1.22898421e-03 9.43132327e-05 5.23350645e-05 1.02358719e-03 2.95696227e-05 8.47954507e-05 1.14004797e-04 1.31279303e-04 1.03662969e-04 1.46131824e-05 1.36542658e-04 2.11491992e-04 1.23417616e-04 2.70172895e-04 9.27503314e-03 3.58393154e-05 1.42996432e-04 4.88580481e-05 2.08129743e-04 7.55469227e-05 1.80010602e-03 2.69579381e-04 6.14304590e-05 1.51719782e-04 3.06613947e-04 3.91341418e-05 7.01408062e-05 1.73189299e-04 1.69934458e-04 5.96841055e-05 4.24156024e-04 9.17293073e-05 1.36444840e-04 3.44250038e-05 1.63474804e-04 2.58311688e-04 1.26392333e-04 2.09165719e-05 5.17314591e-04 2.21558570e-04 6.93166949e-05 5.01095143e-04 6.04604793e-05 1.06962965e-04 1.12396388e-04 1.60767100e-04 2.88392417e-04 5.41996815e-05 3.24832043e-04 2.20701098e-03 6.49877533e-04 5.02989460e-05 7.52472988e-05 7.38493982e-05 2.02643103e-04 1.58175724e-04 9.58628807e-05 2.05265809e-04 1.33395239e-04 1.00665995e-04 4.41335229e-04 8.53350139e-05 2.41072685e-03 6.76312763e-03 1.99550879e-04 2.18866873e-04 3.68268136e-03 1.52131484e-04 3.47973619e-05 2.63408438e-04 8.99361403e-05 2.44862371e-04 9.36706201e-05 3.96404794e-04 1.69232895e-04 1.82643184e-04 8.23817390e-05 1.28939297e-04 1.60003619e-04 2.54262326e-04 4.13911621e-05 2.18296002e-04 2.34968931e-04 1.13110706e-04 2.33932471e-04 7.90734543e-04 8.66776827e-05 5.90911259e-05 5.33395469e-05 6.42125888e-05 1.73698267e-04 2.86906667e-04 6.17210520e-04 1.36306771e-04 6.00402236e-05 7.31108012e-05 4.78808419e-04 5.04766474e-04 2.92460645e-05 2.40552748e-04 2.26358025e-04 1.64050783e-03 2.69968790e-04 2.75273342e-04 3.58361685e-05 4.55840520e-04 7.55458779e-04 4.77244757e-05 4.25744278e-04 2.56503467e-04 9.32842595e-05 4.78531350e-04 3.82126920e-04 1.40906748e-04 1.59672083e-04 1.35300914e-04 1.45991624e-04 1.26332321e-04 4.65454854e-04 6.87230422e-05 3.50040413e-04 7.57950984e-05 7.95457599e-05 1.45460814e-04 8.68879870e-05 8.87998976e-05 1.03155173e-04 1.11441434e-04 3.03752691e-04 9.76508309e-05 3.01196793e-04 3.61487328e-04 1.51797803e-02 6.21921790e-04 1.78741466e-04 1.03896542e-04 4.74601202e-02 8.49541902e-05 9.95561277e-05 2.17465175e-04 1.33937447e-05 2.46054464e-04 3.02065222e-04 4.99109738e-04 1.85740428e-04 8.53602469e-05 1.81934598e-03 6.40128972e-04 2.41056368e-05 1.10112022e-04 5.73154015e-04 3.90185014e-05 3.55087977e-05 1.14686016e-04 5.30490179e-05 9.12918986e-05 1.00015774e-01 8.83070461e-04 2.72962556e-04 8.38908018e-05 2.82040564e-04 4.93622734e-04 7.46247405e-03 5.96156715e-05 1.67575799e-05 1.16346288e-04 5.36920328e-04 1.27802356e-04 2.30134101e-05 2.74490070e-04 9.00082232e-05 3.21574509e-04 9.95760638e-05 1.29736232e-04 6.78601064e-05 2.29982383e-04 1.53331392e-04 4.60963347e-05 9.96922754e-05 2.38105451e-04 6.07146540e-05 7.30701373e-04 9.12623000e-05 2.74614558e-05 1.61513351e-04 1.87124999e-04 5.76453458e-04 1.12990710e-04 7.20965909e-05 3.50037910e-04 2.92407232e-04 1.49299231e-04 1.06138468e-04 2.38677567e-05 1.80755123e-05 7.04687263e-05 1.31522902e-04 7.73099964e-05 1.51216867e-04 2.80134205e-04 1.20323304e-04 2.04802476e-04 3.83206752e-05 5.23925919e-05 2.26494049e-05 4.94287815e-05 2.80370354e-04 1.37045572e-04 1.33363937e-04 1.33160982e-04 3.13233031e-04 9.00903178e-05 3.99530982e-05 7.71072955e-05 4.91564606e-05 7.67913662e-05 9.70205365e-05 2.11171340e-04 8.83378263e-04 4.25377022e-03 7.54079301e-05 8.63048554e-05 4.14039168e-05 2.18398884e-04 2.09474660e-04 1.10473004e-04 1.79602488e-04 7.84180374e-05 1.18341675e-04 5.95971709e-04 1.77652473e-05 1.22647209e-04 4.61962809e-05 6.35733377e-05 5.55073748e-05 3.80490856e-05 3.09399271e-04 7.95710221e-05 8.06995449e-05 1.29091379e-04 3.64821753e-05 1.01977887e-04 6.55211697e-05 4.00396268e-04 1.65697827e-04 7.14321795e-05 9.27373258e-05 2.19753987e-04 1.01688194e-04 7.81616473e-05 1.42240012e-03 3.65302403e-04 5.22933784e-04 1.26051207e-04 2.27914934e-04 1.23822581e-04 3.74602270e-04 1.15855958e-03 7.02308665e-04 1.06714051e-02 2.53521517e-04 1.03349266e-04 4.81895077e-05 2.97289836e-04 1.69289153e-04 1.41962128e-05 5.98742627e-04 1.26236887e-03 1.93419008e-04 4.62458265e-05 8.37992120e-04 4.54028044e-03 3.02547269e-04 2.72878358e-04 3.35981429e-04 3.98071657e-04 2.88501469e-04 9.95966345e-02 4.63833676e-05 8.01439222e-04 1.59440940e-04 7.87119789e-05 1.18450967e-04 1.18075055e-03 1.69294872e-04 1.65762234e-04 2.93512654e-04 3.50778108e-04 3.24402616e-04 7.45128418e-05 3.55992786e-04 6.10341303e-05 2.11328384e-04 2.10321487e-05 1.11494694e-04 8.39037675e-05 5.30467194e-04 7.59179311e-05 9.96805757e-05 1.41086406e-04 6.48089161e-04 1.04560633e-04 2.20013899e-04 6.19974395e-04 1.22074140e-04 2.16955304e-04 4.42797937e-05 2.66275631e-04 1.26754720e-04 3.00378539e-04 2.94329016e-04 1.68290327e-03 7.27367878e-05 1.81106443e-04 1.41880242e-04 1.45083977e-05 3.60573540e-05 6.53995899e-03 1.49049898e-04 6.96775096e-05 5.27453303e-05 7.57880844e-05 1.18763382e-04 4.37842900e-05 1.68973333e-04 7.16834475e-05 2.00324156e-03 1.57868140e-04 1.66626254e-04 3.23227898e-04 5.07752411e-04 2.87794013e-04 7.93236468e-05 4.47009443e-05 7.02501784e-05 2.69621178e-05 1.79364637e-04 9.77465243e-05 2.40390742e-04 5.75227459e-05 2.31010272e-04 3.41189210e-04 3.34294193e-04 6.23751766e-05 8.69955256e-05 1.18864453e-04 8.59565844e-05 4.43529934e-05 5.33128477e-05 2.24634088e-04 1.60142852e-04 2.07382982e-04 5.30219622e-05 8.73597128e-06 7.64939541e-05 1.34427872e-04 1.25443912e-04 3.47132765e-04 2.50138750e-04 1.15714553e-04 1.03594371e-04 8.48490890e-05 1.49802829e-04 1.19625700e-04 5.19954301e-05 1.02711478e-04 1.48221661e-04 2.17507913e-04 4.43230165e-05 1.74802102e-04 3.52305215e-04 1.28698273e-04 3.30608047e-04 1.23894992e-04 4.23865509e-04 4.24290993e-05 3.37020843e-04 2.38423687e-04 1.95631423e-04 1.04855506e-04 7.46722508e-05 5.48311400e-05 2.12092593e-04 1.54307112e-04 5.20747562e-04 7.50570834e-05 1.44592457e-04 3.80499958e-04 9.01258099e-05 1.43552694e-04 6.33521850e-05 1.58772920e-04 6.28738053e-05 2.43450977e-05 9.15214259e-05 1.82955511e-04 3.05623398e-05 2.06110941e-04 6.22943917e-05 9.40461177e-05 1.86849575e-04 5.77892024e-05 5.31381374e-05 3.45071785e-05 3.49373731e-04 1.16785173e-04 1.54422160e-04 3.13776894e-04 2.81451037e-04 4.56202310e-04 8.62182758e-04 2.69047625e-04 1.29641252e-04 1.41201299e-02 1.45091792e-03 2.88067076e-05 1.01580075e-03 2.94299971e-04 3.27183079e-04 1.88859383e-04 1.69486302e-04 3.94478440e-04 1.70523606e-04 4.11478395e-04 1.36369446e-04 4.72482025e-05 1.33227426e-04 2.34814594e-04 4.63315082e-05 4.23921883e-04 1.72544052e-04 5.27461343e-05 1.73788823e-04 2.50683457e-04 4.65004268e-05 7.26177823e-05 6.48862770e-05 6.42277737e-05]], shape=(1, 1000), dtype=float32)
np_result = result.numpy()[0]
print(np_result)
[1.67357328e-04 7.48886960e-05 9.10225790e-05 1.61429649e-04 1.80477553e-04 2.01649018e-05 2.37957895e-04 1.66809506e-04 1.43144003e-04 1.60500538e-04 1.40027434e-04 7.66541052e-05 2.55448394e-04 1.01829886e-04 6.68075882e-05 6.71937887e-05 1.74754183e-04 4.76423484e-05 1.60923169e-04 2.91181699e-04 5.66527633e-05 5.96032805e-05 4.86944009e-05 2.32021936e-04 6.23657179e-05 1.27928943e-04 1.92076041e-04 6.28614274e-04 1.78236514e-04 1.19395932e-04 9.80493860e-05 3.75609598e-05 3.84934683e-04 1.28144806e-04 1.17247058e-04 1.13339731e-04 1.55172413e-04 4.41422366e-04 4.54554429e-05 1.81667769e-04 6.85919586e-05 2.61485839e-04 1.82488497e-04 7.38181407e-05 3.72787035e-04 2.17093329e-04 7.59527611e-05 6.37365811e-05 7.39252137e-05 5.10215614e-05 2.00286537e-04 3.32779928e-05 3.73418967e-04 1.86561752e-04 3.07171467e-05 5.00616334e-05 7.99422851e-05 2.87409755e-04 1.48447871e-04 3.89670386e-05 1.82260028e-05 1.02116865e-04 2.26840348e-05 1.01948033e-04 5.41410955e-05 6.08378250e-05 1.15725146e-04 7.38108793e-05 1.52765657e-04 1.65693229e-04 1.96085413e-04 8.52664380e-05 6.62517923e-05 7.21684701e-05 1.44252786e-04 1.86123783e-04 1.40939417e-04 7.23011544e-05 1.99576112e-04 3.21566069e-04 4.61737727e-05 5.21688024e-04 1.13047085e-04 1.92566018e-04 6.06839749e-05 9.62445047e-05 1.13117931e-04 9.02370957e-05 9.22817344e-05 1.01368380e-04 3.59182188e-04 1.62126234e-04 2.08516853e-04 3.47721216e-05 3.64632229e-04 3.01419204e-04 6.83444887e-05 1.31897861e-04 1.95828077e-04 1.06738582e-04 1.74555971e-04 2.53571226e-04 1.87643338e-04 1.56295209e-04 1.18525888e-04 6.26458277e-05 1.59868941e-04 8.11573700e-05 1.25057864e-04 1.17108604e-04 7.13126574e-05 5.54172475e-05 9.23214393e-05 1.64395955e-04 3.52056144e-04 2.47819873e-04 8.78320789e-05 5.41064583e-05 2.01308751e-04 1.49956046e-04 1.57278395e-04 2.40579466e-04 1.85823956e-04 1.22923564e-04 2.21942173e-04 4.40764670e-05 1.16574083e-04 3.04487068e-04 2.83238012e-04 1.61682008e-04 3.96540359e-04 1.05197752e-04 2.41361529e-04 1.11718109e-04 7.25388119e-04 1.80169984e-04 1.58088631e-04 9.85863735e-05 6.95664276e-05 1.47213708e-04 1.12825524e-04 1.60540803e-04 3.38791142e-04 7.71324485e-05 2.15697553e-04 5.11942962e-05 3.77704855e-05 6.30176364e-05 4.72086365e-04 1.11339141e-04 9.47190798e-04 1.13887545e-04 2.38809167e-04 2.06700686e-04 7.80091039e-04 1.96210734e-04 1.76762536e-04 1.71593929e-04 3.93578463e-04 1.08376778e-04 9.31922332e-05 2.96955899e-04 1.41593759e-04 7.23419143e-05 1.04821716e-04 1.74653047e-04 1.27286985e-04 1.02071099e-04 1.29239445e-04 8.04442097e-05 2.92383804e-04 6.03596563e-05 1.31854715e-04 1.18426688e-04 3.04332178e-04 3.53113661e-04 5.07758486e-05 9.92798305e-05 1.24749946e-04 5.67539937e-05 3.71809401e-05 3.46395303e-04 8.81566433e-04 6.49011927e-05 8.02722760e-04 2.04695854e-04 2.40250476e-04 5.78261970e-05 1.20262150e-04 3.45854933e-04 1.42004035e-04 2.21934126e-04 5.74710939e-05 1.14472394e-04 8.17674518e-05 1.23496735e-04 2.06799377e-04 6.43156091e-05 6.76670170e-05 1.29037842e-04 1.10540132e-04 1.17918869e-04 1.18846889e-04 1.28439438e-04 1.04448409e-04 9.96431263e-05 1.58541574e-04 2.47384654e-04 6.22294901e-05 1.42855715e-04 9.40137397e-05 2.98859406e-04 1.72066531e-04 2.51497404e-04 2.13951949e-04 1.82864358e-04 3.25560832e-04 2.65320239e-04 1.52477471e-04 1.38287229e-04 4.21349599e-04 4.76433459e-04 9.71817644e-05 2.18461602e-04 2.75821018e-04 1.65611098e-04 1.95778965e-04 9.95107403e-05 1.90569117e-04 6.79200675e-05 2.68582575e-04 1.42772551e-04 1.21785415e-04 8.38747219e-05 9.36725919e-05 1.53051835e-04 2.68764998e-04 2.97076855e-04 7.53670174e-05 1.28449363e-04 2.45624251e-04 6.00717212e-05 7.90790727e-05 4.12735426e-05 1.10393914e-04 2.92747223e-04 1.03377053e-04 1.82162214e-04 3.87734945e-05 1.65707766e-04 1.51658227e-04 1.61610937e-04 1.82058182e-04 2.05814838e-04 2.02232943e-04 9.53260023e-05 2.98828498e-04 3.33915988e-04 9.96771560e-05 1.87070938e-04 1.79301540e-04 1.83119584e-04 3.12310149e-04 1.38238378e-04 3.00599750e-05 1.56912458e-04 1.16694326e-04 1.25714461e-04 2.13557985e-04 1.56702430e-04 2.74436810e-04 1.46911902e-04 4.39555122e-04 7.41670738e-05 6.72850947e-05 2.08303973e-05 3.55755037e-05 1.91525833e-04 8.93982651e-05 1.92051681e-04 9.68867462e-05 1.57627583e-04 2.27602693e-04 1.31187306e-04 1.64624085e-04 2.75210739e-04 1.33124297e-04 1.95651286e-04 7.76510860e-05 9.62153135e-05 4.54786234e-04 6.56663542e-05 2.37827669e-04 3.40095721e-05 2.10821221e-04 1.70597210e-04 1.26792918e-04 1.78063550e-04 1.36804723e-04 5.95220481e-05 4.80892224e-04 9.18859369e-05 1.84604578e-04 1.39191310e-04 2.91351142e-04 2.36900014e-04 1.32085916e-04 2.27185548e-04 1.45869926e-04 8.80977605e-05 1.98933645e-04 1.41513432e-04 2.88640877e-04 3.83168408e-05 7.85072334e-05 3.02854260e-05 9.82208439e-05 1.41690267e-04 1.43693149e-04 1.66590427e-04 1.32049012e-04 2.44498835e-04 1.98872644e-04 2.14436484e-04 1.38428673e-04 2.09264414e-04 1.33705107e-04 5.08142402e-04 4.56837937e-04 1.20619487e-04 1.98008827e-04 3.31353134e-04 1.81024254e-04 2.18643123e-04 1.27678344e-04 6.49769034e-04 2.80206878e-04 7.99543268e-05 1.66537531e-04 1.94384847e-04 1.30818516e-04 2.17383582e-04 1.59268835e-04 6.85101113e-05 7.75048175e-05 4.33948007e-04 1.96583554e-04 3.51238377e-05 1.47340470e-04 1.01998216e-04 9.11554089e-05 1.32211426e-04 6.77166536e-05 8.04037918e-05 4.37622512e-05 8.75672049e-05 1.70788480e-04 3.90449306e-04 3.14480887e-04 2.11017134e-04 1.56760274e-04 1.32804867e-04 1.77957354e-05 3.50671413e-04 1.15747338e-04 2.67752301e-04 5.40343717e-05 7.03712867e-05 1.14286093e-04 2.76649778e-04 2.52920581e-04 1.19134893e-04 1.78383605e-04 2.94235419e-04 1.51324857e-04 1.67897975e-04 1.94346008e-04 1.17992771e-04 9.32319599e-05 1.60808951e-04 2.55117164e-04 3.64112173e-04 8.62851884e-05 5.07094992e-05 2.83875532e-04 2.52050115e-04 5.90971576e-05 2.85809656e-04 1.88095379e-04 1.27586929e-04 4.37917224e-05 3.87920853e-04 7.41973563e-05 8.77350540e-05 8.15246021e-05 2.35257496e-04 1.90197636e-04 8.50121287e-05 2.37704531e-04 1.03099308e-04 2.59184133e-04 4.60767769e-05 1.80213465e-04 7.27412337e-03 3.11539538e-04 1.56120828e-03 4.44631267e-04 2.66253279e-04 8.42514797e-04 3.09255061e-04 2.15319797e-05 1.06556319e-04 7.75268069e-04 7.49748797e-05 6.37864432e-05 1.41168421e-05 1.45275726e-05 5.06322074e-04 3.15404614e-04 6.64380670e-04 2.40592082e-04 2.16024360e-04 6.13866505e-05 8.78105566e-05 5.46784031e-05 3.20850668e-05 4.90134080e-05 7.93228101e-05 7.77184978e-05 7.58772600e-04 1.71554580e-04 9.17959915e-05 7.23952617e-05 3.19199207e-05 2.13496809e-04 7.21321485e-05 2.24105643e-05 3.13031167e-04 4.55443987e-05 6.87055173e-04 6.09505165e-04 4.57360235e-04 4.99408506e-03 1.09396911e-04 2.88811152e-05 1.45948055e-04 8.17528708e-05 1.09756237e-03 1.87502024e-04 2.04540323e-03 1.23364429e-04 1.84171557e-04 5.65130540e-05 1.50492080e-04 1.41106982e-04 1.38743504e-04 2.53782018e-05 6.33907475e-05 1.61757358e-04 3.93228052e-04 1.27267092e-02 1.01859790e-04 1.71431107e-04 9.77969612e-05 1.58332448e-04 6.63650499e-05 5.41307440e-04 1.21139397e-04 1.61333301e-03 5.97645812e-05 2.56448784e-05 1.49999117e-03 5.32147882e-04 5.82903798e-04 3.95592448e-04 1.42487115e-04 3.28893366e-04 1.94963159e-05 3.87864973e-04 8.83529574e-05 8.88068462e-05 5.36482199e-04 2.73689948e-04 1.51329990e-02 1.62611832e-04 8.26883188e-05 1.96636902e-04 3.48623173e-04 2.98071827e-04 5.44828421e-04 1.29765438e-04 5.10983045e-05 1.76515925e-04 2.76940264e-04 5.70710217e-05 6.50954025e-05 1.42366844e-04 2.23277719e-03 1.35558788e-04 1.71005900e-04 9.01887470e-05 3.87938780e-04 6.36503246e-05 3.56488832e-04 4.31275184e-05 1.05291809e-04 8.26198157e-05 3.62519757e-04 4.55220346e-04 6.31531875e-04 2.03710259e-03 6.42493324e-05 2.54170678e-04 1.18964701e-04 2.87157254e-05 1.17950804e-04 1.12647373e-04 2.07547098e-03 1.48444466e-04 3.97456170e-04 1.00609745e-04 1.62285491e-04 6.88708678e-05 6.21697618e-05 1.85760087e-04 2.62780534e-03 8.74956677e-05 8.75948535e-05 8.01707865e-05 1.40172342e-04 9.30300448e-04 4.53038010e-05 5.10637146e-05 3.94132658e-04 3.87863292e-05 7.26157741e-05 3.99216026e-01 4.19301432e-05 4.02754033e-03 1.54149602e-05 2.65294453e-03 1.35875700e-04 3.69741378e-04 1.08514425e-04 9.72095731e-05 2.07789308e-05 3.73110175e-04 4.26259823e-04 2.01917006e-04 2.42721566e-04 1.11561283e-04 1.89086903e-04 4.28869273e-04 4.63015604e-05 8.90578050e-03 3.50718212e-04 9.62700215e-05 4.09287459e-04 2.39198689e-05 1.85963741e-04 3.04453948e-04 4.29403735e-05 1.22898421e-03 9.43132327e-05 5.23350645e-05 1.02358719e-03 2.95696227e-05 8.47954507e-05 1.14004797e-04 1.31279303e-04 1.03662969e-04 1.46131824e-05 1.36542658e-04 2.11491992e-04 1.23417616e-04 2.70172895e-04 9.27503314e-03 3.58393154e-05 1.42996432e-04 4.88580481e-05 2.08129743e-04 7.55469227e-05 1.80010602e-03 2.69579381e-04 6.14304590e-05 1.51719782e-04 3.06613947e-04 3.91341418e-05 7.01408062e-05 1.73189299e-04 1.69934458e-04 5.96841055e-05 4.24156024e-04 9.17293073e-05 1.36444840e-04 3.44250038e-05 1.63474804e-04 2.58311688e-04 1.26392333e-04 2.09165719e-05 5.17314591e-04 2.21558570e-04 6.93166949e-05 5.01095143e-04 6.04604793e-05 1.06962965e-04 1.12396388e-04 1.60767100e-04 2.88392417e-04 5.41996815e-05 3.24832043e-04 2.20701098e-03 6.49877533e-04 5.02989460e-05 7.52472988e-05 7.38493982e-05 2.02643103e-04 1.58175724e-04 9.58628807e-05 2.05265809e-04 1.33395239e-04 1.00665995e-04 4.41335229e-04 8.53350139e-05 2.41072685e-03 6.76312763e-03 1.99550879e-04 2.18866873e-04 3.68268136e-03 1.52131484e-04 3.47973619e-05 2.63408438e-04 8.99361403e-05 2.44862371e-04 9.36706201e-05 3.96404794e-04 1.69232895e-04 1.82643184e-04 8.23817390e-05 1.28939297e-04 1.60003619e-04 2.54262326e-04 4.13911621e-05 2.18296002e-04 2.34968931e-04 1.13110706e-04 2.33932471e-04 7.90734543e-04 8.66776827e-05 5.90911259e-05 5.33395469e-05 6.42125888e-05 1.73698267e-04 2.86906667e-04 6.17210520e-04 1.36306771e-04 6.00402236e-05 7.31108012e-05 4.78808419e-04 5.04766474e-04 2.92460645e-05 2.40552748e-04 2.26358025e-04 1.64050783e-03 2.69968790e-04 2.75273342e-04 3.58361685e-05 4.55840520e-04 7.55458779e-04 4.77244757e-05 4.25744278e-04 2.56503467e-04 9.32842595e-05 4.78531350e-04 3.82126920e-04 1.40906748e-04 1.59672083e-04 1.35300914e-04 1.45991624e-04 1.26332321e-04 4.65454854e-04 6.87230422e-05 3.50040413e-04 7.57950984e-05 7.95457599e-05 1.45460814e-04 8.68879870e-05 8.87998976e-05 1.03155173e-04 1.11441434e-04 3.03752691e-04 9.76508309e-05 3.01196793e-04 3.61487328e-04 1.51797803e-02 6.21921790e-04 1.78741466e-04 1.03896542e-04 4.74601202e-02 8.49541902e-05 9.95561277e-05 2.17465175e-04 1.33937447e-05 2.46054464e-04 3.02065222e-04 4.99109738e-04 1.85740428e-04 8.53602469e-05 1.81934598e-03 6.40128972e-04 2.41056368e-05 1.10112022e-04 5.73154015e-04 3.90185014e-05 3.55087977e-05 1.14686016e-04 5.30490179e-05 9.12918986e-05 1.00015774e-01 8.83070461e-04 2.72962556e-04 8.38908018e-05 2.82040564e-04 4.93622734e-04 7.46247405e-03 5.96156715e-05 1.67575799e-05 1.16346288e-04 5.36920328e-04 1.27802356e-04 2.30134101e-05 2.74490070e-04 9.00082232e-05 3.21574509e-04 9.95760638e-05 1.29736232e-04 6.78601064e-05 2.29982383e-04 1.53331392e-04 4.60963347e-05 9.96922754e-05 2.38105451e-04 6.07146540e-05 7.30701373e-04 9.12623000e-05 2.74614558e-05 1.61513351e-04 1.87124999e-04 5.76453458e-04 1.12990710e-04 7.20965909e-05 3.50037910e-04 2.92407232e-04 1.49299231e-04 1.06138468e-04 2.38677567e-05 1.80755123e-05 7.04687263e-05 1.31522902e-04 7.73099964e-05 1.51216867e-04 2.80134205e-04 1.20323304e-04 2.04802476e-04 3.83206752e-05 5.23925919e-05 2.26494049e-05 4.94287815e-05 2.80370354e-04 1.37045572e-04 1.33363937e-04 1.33160982e-04 3.13233031e-04 9.00903178e-05 3.99530982e-05 7.71072955e-05 4.91564606e-05 7.67913662e-05 9.70205365e-05 2.11171340e-04 8.83378263e-04 4.25377022e-03 7.54079301e-05 8.63048554e-05 4.14039168e-05 2.18398884e-04 2.09474660e-04 1.10473004e-04 1.79602488e-04 7.84180374e-05 1.18341675e-04 5.95971709e-04 1.77652473e-05 1.22647209e-04 4.61962809e-05 6.35733377e-05 5.55073748e-05 3.80490856e-05 3.09399271e-04 7.95710221e-05 8.06995449e-05 1.29091379e-04 3.64821753e-05 1.01977887e-04 6.55211697e-05 4.00396268e-04 1.65697827e-04 7.14321795e-05 9.27373258e-05 2.19753987e-04 1.01688194e-04 7.81616473e-05 1.42240012e-03 3.65302403e-04 5.22933784e-04 1.26051207e-04 2.27914934e-04 1.23822581e-04 3.74602270e-04 1.15855958e-03 7.02308665e-04 1.06714051e-02 2.53521517e-04 1.03349266e-04 4.81895077e-05 2.97289836e-04 1.69289153e-04 1.41962128e-05 5.98742627e-04 1.26236887e-03 1.93419008e-04 4.62458265e-05 8.37992120e-04 4.54028044e-03 3.02547269e-04 2.72878358e-04 3.35981429e-04 3.98071657e-04 2.88501469e-04 9.95966345e-02 4.63833676e-05 8.01439222e-04 1.59440940e-04 7.87119789e-05 1.18450967e-04 1.18075055e-03 1.69294872e-04 1.65762234e-04 2.93512654e-04 3.50778108e-04 3.24402616e-04 7.45128418e-05 3.55992786e-04 6.10341303e-05 2.11328384e-04 2.10321487e-05 1.11494694e-04 8.39037675e-05 5.30467194e-04 7.59179311e-05 9.96805757e-05 1.41086406e-04 6.48089161e-04 1.04560633e-04 2.20013899e-04 6.19974395e-04 1.22074140e-04 2.16955304e-04 4.42797937e-05 2.66275631e-04 1.26754720e-04 3.00378539e-04 2.94329016e-04 1.68290327e-03 7.27367878e-05 1.81106443e-04 1.41880242e-04 1.45083977e-05 3.60573540e-05 6.53995899e-03 1.49049898e-04 6.96775096e-05 5.27453303e-05 7.57880844e-05 1.18763382e-04 4.37842900e-05 1.68973333e-04 7.16834475e-05 2.00324156e-03 1.57868140e-04 1.66626254e-04 3.23227898e-04 5.07752411e-04 2.87794013e-04 7.93236468e-05 4.47009443e-05 7.02501784e-05 2.69621178e-05 1.79364637e-04 9.77465243e-05 2.40390742e-04 5.75227459e-05 2.31010272e-04 3.41189210e-04 3.34294193e-04 6.23751766e-05 8.69955256e-05 1.18864453e-04 8.59565844e-05 4.43529934e-05 5.33128477e-05 2.24634088e-04 1.60142852e-04 2.07382982e-04 5.30219622e-05 8.73597128e-06 7.64939541e-05 1.34427872e-04 1.25443912e-04 3.47132765e-04 2.50138750e-04 1.15714553e-04 1.03594371e-04 8.48490890e-05 1.49802829e-04 1.19625700e-04 5.19954301e-05 1.02711478e-04 1.48221661e-04 2.17507913e-04 4.43230165e-05 1.74802102e-04 3.52305215e-04 1.28698273e-04 3.30608047e-04 1.23894992e-04 4.23865509e-04 4.24290993e-05 3.37020843e-04 2.38423687e-04 1.95631423e-04 1.04855506e-04 7.46722508e-05 5.48311400e-05 2.12092593e-04 1.54307112e-04 5.20747562e-04 7.50570834e-05 1.44592457e-04 3.80499958e-04 9.01258099e-05 1.43552694e-04 6.33521850e-05 1.58772920e-04 6.28738053e-05 2.43450977e-05 9.15214259e-05 1.82955511e-04 3.05623398e-05 2.06110941e-04 6.22943917e-05 9.40461177e-05 1.86849575e-04 5.77892024e-05 5.31381374e-05 3.45071785e-05 3.49373731e-04 1.16785173e-04 1.54422160e-04 3.13776894e-04 2.81451037e-04 4.56202310e-04 8.62182758e-04 2.69047625e-04 1.29641252e-04 1.41201299e-02 1.45091792e-03 2.88067076e-05 1.01580075e-03 2.94299971e-04 3.27183079e-04 1.88859383e-04 1.69486302e-04 3.94478440e-04 1.70523606e-04 4.11478395e-04 1.36369446e-04 4.72482025e-05 1.33227426e-04 2.34814594e-04 4.63315082e-05 4.23921883e-04 1.72544052e-04 5.27461343e-05 1.73788823e-04 2.50683457e-04 4.65004268e-05 7.26177823e-05 6.48862770e-05 6.42277737e-05]
tags, labels_filtered, probs_filtered = get_tags(np_result, labels)
print('probs_filtered:', probs_filtered)
print('labels_filtered:', labels_filtered)
print('tags:', tags)
probs_filtered: [39 10 9 4 1] labels_filtered: ['dock' 'pier' 'suspension bridge' 'palace' 'paddlewheel'] tags: dock (39%), pier (10%), suspension bridge (9%), palace (4%), paddlewheel (1%),
plt.figure()
plt.title(tags)
plt.imshow(test_images[TEST_IMAGE_INDEX]);
plt.show()
for image_index in range(0, len(test_images)):
test_image = test_images[image_index]
test_image_preprocessed = test_images_preprocessed[image_index]
probabilities = model(test_image_preprocessed)
tags, labels_filtered, probs_filtered = get_tags(probabilities.numpy()[0], labels)
plt.figure()
plt.title(tags)
plt.imshow(test_image);
plt.show()
model_name = 'image_classification_mobilenet_v2.h5'
model.save(model_name, save_format='h5')
To use this model on the web we need to convert it into the format that will be understandable by tensorflowjs. To do so we may use tfjs-converter as following:
tensorflowjs_converter --input_format keras \
./experiments/image_classification_mobilenet_v2/image_classification_mobilenet_v2.h5 \
./demos/public/models/image_classification_mobilenet_v2
You find this experiment in the Demo app and play around with it right in you browser to see how the model performs in real life.