<jupyter_start><jupyter_text>Transfer Learning in Keras with ``Computer Vision`` ModelsA way to short-cut this process is to re-use the model weights from pre-trained models that were developed for standard computer vision benchmark datasets, such as the ImageNet image recognition tasks. Top performing models can be downloaded and used directly, or integrated into a new model for your own computer vision problems.> ✔ Usefull Resource: [ILSVRC](https://image-net.org/challenges/LSVRC/) Keras Applications[Keras Applications](https://keras.io/api/applications/) are deep learning models that are made available alongside pre-trained weights. These models can be used for prediction, feature extraction, and fine-tuning. Loading different models from `tf.keras.applications`<jupyter_code>import tensorflow as tf
import tensorflow.keras as keras
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.preprocessing import image<jupyter_output><empty_output><jupyter_text>Classify ImageNet classes with ``ResNet50``<jupyter_code>from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions, ResNet50
model = ResNet50(weights='imagenet')
model.summary()
image = keras.preprocessing.image.load_img('images/elephant.jpg', target_size=(224, 224))
image
image_array = keras.preprocessing.image.img_to_array(image)
elephants = np.expand_dims(image_array, axis=0)
elephant = preprocess_input(elephants)
predictions = model.predict(elephant)
decode_predictions(predictions)<jupyter_output><empty_output><jupyter_text>Extract features with ``VGG16``<jupyter_code>from tensorflow.keras.applications.vgg16 import preprocess_input, VGG16
model = VGG16(weights='imagenet')
model.summary()<jupyter_output>A local file was found, but it seems to be incomplete or outdated because the auto file hash does not match the original value of 64373286793e3c8b2b4e3219cbf3544b so we will re-download the data.
Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/vgg16/vgg16_weights_tf_dim_ordering_tf_kernels.h5
400179200/553467096 [====================>.........] - ETA: 2:49<jupyter_text>> 💎[Docs](https://keras.io/api/applications/)  Extract features from an arbitrary intermediate layer with ``VGG19``<jupyter_code>from tensorflow.keras.applications.vgg19 import preprocess_input, VGG19
from tensorflow.keras import Model
model = VGG19(weights="imagenet")
model.summary()
base_model = VGG19(weights='imagenet')
model = Model(inputs=base_model.input, outputs=base_model.get_layer('block4_pool').output)
block4_pool_features = model.predict(elephant)
block4_pool_features<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09717514124293786, 'fraction_numerical': 0.032015065913371, 'mean_word_length': 7.45859872611465, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 19, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '154602', 'license': 'MIT', 'n_tokens_mistral': 861, 'n_tokens_neox': 803, 'n_words': 216, 'path': 'tf-transfare-learning/01_Transfare_Learning_Docs_Intro.ipynb', 'repo_name': 'CrispenGari/tensorflow-python', 'size': '2655'}