<jupyter_start><jupyter_text>Pretrained Models - TF2.X<jupyter_code>import tensorflow as tf
print(tf.__version__)
!python --version
from tensorflow.keras.applications.vgg16 import VGG16
from tensorflow.keras.preprocessing import image
from tensorflow.keras.applications.vgg16 import preprocess_input
import numpy as np<jupyter_output><empty_output><jupyter_text>Downloading the VGG16 model:<jupyter_code>model = VGG16(weights='imagenet')<jupyter_output>Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/vgg16/vgg16_weights_tf_dim_ordering_tf_kernels.h5
553467904/553467096 [==============================] - 4s 0us/step<jupyter_text>Model Architecture:<jupyter_code>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>Loading an image:<jupyter_code>import matplotlib.pyplot as plt
%matplotlib inline
from google.colab import drive
drive.mount('/content/gdrive')
img_path = '/content/gdrive/MyDrive/Colab/CV-TF1.X-2.X/pics/dog.jpg'
img = image.load_img(img_path, target_size=(224, 224))
plt.figure(figsize=(8,8))
plt.imshow(img)
plt.axis('off')
plt.show()   
img = image.img_to_array(img)<jupyter_output><empty_output><jupyter_text>Reshape data for the model:<jupyter_code>img.shape
img = img.reshape((1, img.shape[0], img.shape[1], img.shape[2]))
img = preprocess_input(img)
img.shape<jupyter_output><empty_output><jupyter_text>Make a Prediction:<jupyter_code>pred = model.predict(img)<jupyter_output><empty_output><jupyter_text>Interpret Prediction:<jupyter_code>from keras.applications.vgg16 import decode_predictions
print('Predicted:', decode_predictions(pred, top=3)[0])<jupyter_output>Downloading data from https://storage.googleapis.com/download.tensorflow.org/data/imagenet_class_index.json
40960/35363 [==================================] - 0s 0us/step
49152/35363 [=========================================] - 0s 0us/step
Predicted: [('n02088364', 'beagle', 0.89202046), ('n02089973', 'English_foxhound', 0.06835977), ('n02089867', 'Walker_hound', 0.03904841)]
{'fraction_non_alphanumeric': 0.157947350883039, 'fraction_numerical': 0.07230923025658113, 'mean_word_length': 6.67774936061381, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '138826', 'license': 'Apache-2.0', 'n_tokens_mistral': 1065, 'n_tokens_neox': 908, 'n_words': 150, 'path': '3-ConvNets/Pretrained Models - TF 2.X.ipynb', 'repo_name': 'kevin801221/opencv', 'size': '3001'}