Important: If you rent a GPU from a cloud provider (such as AWS), don't forget to turn it off after you finish. It's not free and you might get a large bill at the end of the month.
- The keras applications has different pre-trained models with different architectures. We'll use the model Xception which takes the input image size of
(229, 229)
and each image pixels is scaled between-1
and1
- We create the instance of the pre-trained model using
model = Xception(weights='imagenet', input_shape=(299, 229, 3))
. Our model will use the weights from pre-trained imagenet and expecting the input shape (229, 229, 3) of the image - Along with image size, the model also expects the
batch_size
which is the size of the batches of data (default 32). If one image is passed to the model, then the expected shape of the model should be (1, 229, 229, 3) - The image data was proprcessed using
preprocess_input
function, therefore, we'll have to use this function on our data to make predictions, like so:X = preprocess_input(X)
- The
pred = model.predict(X)
function returns 2D array of shape(1, 1000)
, where 1000 is the probablity of the image classes.decode_predictions(pred)
can be used to get the class names and their probabilities in readable format. - In order to make the pre-trained model useful specific to our case, we'll have to do some tweak, which we'll do in the coming sections.
Classes, functions, and methods:
from tensorflow.keras.applications.xception import Xception
: import the model from keras applicationsfrom tensorflow.keras.application.xception import preprocess_input
: function to perform preprocessing on imagesfrom tensorflow.keras.applications.xception import decode_predictions
: extract the predctions class name in the form of tuple of listmodel.predict(X)
: function make predictions on the test images
Links:
- Renting a GPU with AWS SageMaker
- Keras Applications provide a list of pre-trained deep learning models
- ImageNet is an image database that has 1,431,167 images of 1000 classes
Add notes from the video (PRs are welcome)
The notes are written by the community. If you see an error here, please create a PR with a fix. |