In [84]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

In [5]:
DATA = '../data/'

In [8]:
from scipy.misc import imsave, fromimage, toimage
from PIL import Image, ImageOps

WIDTH = HEIGHT = 224
def load_and_crop_image(filename, target_size):
    return ImageOps.fit(Image.open(filename), target_size)

Carga imágenes


In [15]:
gatos = np.array([fromimage(load_and_crop_image(DATA+'/gatos/cat.{:04}.jpg'.format(i), (WIDTH, HEIGHT))) for i in range(100)])
perros = np.array([fromimage(load_and_crop_image(DATA+'/gatos/dog.{:04}.jpg'.format(i), (WIDTH, HEIGHT))) for i in range(100)])

imágenes = np.concatenate((gatos, perros), axis=0)
labels = np.zeros(len(gatos) + len(perros), dtype=int)
labels[:len(gatos)] = 1

In [141]:
toimage(imágenes[0])


Out[141]:

Dividirlas en grupos


In [13]:
características = np.load(DATA+'/feats/all_feats.npy')
indices1 = np.load(DATA+'/feats/indices1.npy')
indices2 = np.load(DATA+'/feats/indices2.npy')

In [ ]:
imágenes1 = imágenes[indices1]
car1 = características[indices1]
imágenes2 = imágenes[indices2]
car2 = características[indices2]

In [122]:
len(imágenes1)


Out[122]:
10

In [123]:
toimage(imágenes1[0])


Out[123]:

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [69]:
%run vgg16.py


Using TensorFlow backend.
Model loaded.

In [77]:
all_cats


Out[77]:
[281, 282, 283, 284, 285, 286, 287]

In [145]:
preds[all_cats].sum()


Out[145]:
0.0013668686412984243

In [153]:
preds = model.predict(img_to_vgg_input(imágenes1[5]))[0]

In [152]:
[synsets[idx] for idx in np.argsort(preds)[::-1][:5]]


Out[152]:
[['n02123045', 'tabby, tabby cat'],
 ['n02124075', 'Egyptian cat'],
 ['n02123159', 'tiger cat'],
 ['n02123394', 'Persian cat'],
 ['n02127052', 'lynx, catamount']]

In [ ]: