09.05.2023 Views

pdfcoffee

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Convolutional Neural Networks

Recognizing cats with a VGG16 Net

Now let us test the image of a cat:

Note that we are going to use predefined weights:

import cv2

im = cv2.resize(cv2.imread('cat.jpg'), (224, 224).astype(np.float32))

#im = im.transpose((2,0,1))

im = np.expand_dims(im, axis=0)

# Test pretrained model

model = VGG_16('/Users/antonio/.keras/models/vgg16_weights_tf_dim_

ordering_tf_kernels.h5')

model.summary()

model.compile(optimizer='sgd', loss='categorical_crossentropy')

out = model.predict(im)

print(np.argmax(out))

When the code is executed, the class 285 is returned, which corresponds (https://

gist.github.com/yrevar/942d3a0ac09ec9e5eb3a) to "Egyptian cat":

Figure 19: Image recognition results using a VGG16 Net

Impressive isn't it? Our VGG-16 network can successfully recognize images of cats!

A first important step for deep learning. It is only five years since the paper in [4],

but that was a game-changing moment.

[ 134 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!