April 2017
Intermediate to advanced
318 pages
7h 40m
English
Now let us suppose that we want to use the deep learning model we just trained for CIFAR-10 for a bulk evaluation of images. Since we saved the model and the weights, we do not need to train every time:
import numpy as npimport scipy.miscfrom keras.models import model_from_jsonfrom keras.optimizers import SGD#load modelmodel_architecture = 'cifar10_architecture.json'model_weights = 'cifar10_weights.h5'model = model_from_json(open(model_architecture).read())model.load_weights(model_weights)#load imagesimg_names = ['cat-standing.jpg', 'dog.jpg']imgs = [np.transpose(scipy.misc.imresize(scipy.misc.imread(img_name), (32, 32)),(1, 0, 2)).astype('float32')for img_name in img_names]imgs = np.array(imgs) / 255# trainoptim ...