Chapter 8: Tips and Tricks of the Trade
Activity 21: Classifying Images using InceptionV3
Solution:
- Create functions to get images and labels. Here
PATH
variable contains the path to the training dataset.from PIL import Image def get_input(file): return Image.open(PATH+file) def get_output(file): class_label = file.split('.')[0] if class_label == 'dog': label_vector = [1,0] elif class_label == 'cat': label_vector = [0,1] return label_vector
- Set
SIZE
andCHANNELS. SIZE
is the dimension of the square image input.CHANNELS
is the number of channels in the training data images. There are 3 channels in a RGB image.SIZE = 200 CHANNELS = 3
- Create a function to preprocess and augment images:
def preprocess_input(image): # Data preprocessing image = image...