<jupyter_start><jupyter_text>Import Libraries<jupyter_code>import numpy as np
from PIL import Image
from keras.applications.vgg16 import VGG16
from keras.applications.vgg16 import preprocess_input, decode_predictions<jupyter_output><empty_output><jupyter_text>Weights of trained model<jupyter_code>model = VGG16(weights='imagenet', include_top=True)<jupyter_output>Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/vgg16/vgg16_weights_tf_dim_ordering_tf_kernels.h5
553467904/553467096 [==============================] - 3s 0us/step<jupyter_text>Layers<jupyter_code>layers = dict([(layer.name, layer.output) for layer in model.layers])
# print(layers)
model.summary()<jupyter_output>Model: "vgg16"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         [(None, 224, 224, 3)]     0         
_________________________________________________________________
block1_conv1 (Conv2D)        (None, 224, 224, 64)      1792      
_________________________________________________________________
block1_conv2 (Conv2D)        (None, 224, 224, 64)      36928     
_________________________________________________________________
block1_pool (MaxPooling2D)   (None, 112, 112, 64)      0         
_________________________________________________________________
block2_conv1 (Conv2D)        (None, 112, 112, 128)     73856     
_________________________________________________________________
block2_conv2 (Conv2D)        (None, 112, 112, 128)     147584    
_____________________________________________________________[...]<jupyter_text>Parameters counting<jupyter_code>model.count_params()<jupyter_output><empty_output><jupyter_text>Go to image path<jupyter_code>from google.colab import drive
drive.mount('/gdrive')
%cd /gdrive
import os
os.chdir('/gdrive/My Drive/Colab Notebooks')
!ls<jupyter_output>araba.jpg		  'Img_Class_w_VGG16.ipynb adlı not defterinin kopyası'
 ddef.jpg		   kepce.jpg
 dog1.jpg		   MNIST_Ornek.ipynb
 Evrisim.ipynb		   Pomeranian_01.jpeg
 f35.jpg		   tree.jpg
 Fashion_MNIST.ipynb	   Untitled0.ipynb
 Img_Class_w_VGG16.ipynb  'VGG16 in Keras.ipynb'<jupyter_text>Get the image and preprocess<jupyter_code>img_path = 'ddef.jpg'
image = Image.open(img_path)
image = image.resize((224,224))
image
x = np.array(image, dtype='float32')
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)<jupyter_output><empty_output><jupyter_text>Prediction | Classication<jupyter_code>pred = model.predict(x)
print(decode_predictions(pred, top=5)[0])
rate = int(decode_predictions(pred, top=1)[0][0][2]*100)
print('\n Object in the image is probably ', decode_predictions(pred, top=1)[0][0][1], '(probability rate=', rate, '%)')<jupyter_output>[('n02690373', 'airliner', 0.89494264), ('n04592741', 'wing', 0.08819905), ('n02692877', 'airship', 0.014380781), ('n04552348', 'warplane', 0.0021106156), ('n04273569', 'speedboat', 6.899322e-05)]

 Object in the image is probably  airliner (probability rate= 89 %)
StarcoderdataJupyterStructuredCleanDedup