def test_vgg16_architecture(self): vgg16 = architectures.vgg16() self.assertShapesEqual(vgg16.input_shape, (None, 224, 224, 3)) self.assertShapesEqual(vgg16.output_shape, (None, 1000)) random_input = asfloat(np.random.random((2, 224, 224, 3))) prediction = self.eval(vgg16.output(random_input)) self.assertEqual(prediction.shape, (2, 1000))
def test_vgg16_architecture(self): vgg16 = architectures.vgg16() self.assertEqual(vgg16.input_shape, (3, 224, 224)) self.assertEqual(vgg16.output_shape, (1000, )) vgg16_predict = vgg16.compile() random_input = asfloat(np.random.random((7, 3, 224, 224))) prediction = vgg16_predict(random_input) self.assertEqual(prediction.shape, (7, 1000))
import os from neupy import storage, architectures from imagenet_tools import (CURRENT_DIR, FILES_DIR, load_image, print_top_n, download_file) VGG16_WEIGHTS_FILE = os.path.join(FILES_DIR, 'vgg16.hdf5') vgg16 = architectures.vgg16() if not os.path.exists(VGG16_WEIGHTS_FILE): download_file( url= "http://neupy.s3.amazonaws.com/tensorflow/imagenet-models/vgg16.hdf5", filepath=VGG16_WEIGHTS_FILE, description='Downloading weights') storage.load(vgg16, VGG16_WEIGHTS_FILE) dog_image = load_image(os.path.join(CURRENT_DIR, 'images', 'dog.jpg'), image_size=(256, 256), crop_size=(224, 224)) output = vgg16.predict(dog_image) print_top_n(output, n=5)