Esempio n. 1
0
RESNET50_WEIGHTS_FILE = os.path.join(FILES_DIR, 'resnet50.hdf5')
DOG_IMAGE_PATH = os.path.join(CURRENT_DIR, 'images', 'german-shepherd.jpg')


def download_resnet50_weights():
    if not os.path.exists(RESNET50_WEIGHTS_FILE):
        download_file(
            url=
            "http://neupy.s3.amazonaws.com/tensorflow/imagenet-models/resnet50.hdf5",
            filepath=RESNET50_WEIGHTS_FILE,
            description='Downloading weights')

    print("File with ResNet-50 weights: {}".format(RESNET50_WEIGHTS_FILE))
    return RESNET50_WEIGHTS_FILE


if __name__ == '__main__':
    resnet50_weights_filename = download_resnet50_weights()
    resnet50 = architectures.resnet50()

    print("Recovering ResNet-50 parameters...")
    storage.load(resnet50, resnet50_weights_filename)

    print("Making prediction...")
    dog_image = load_image(DOG_IMAGE_PATH,
                           image_size=(256, 256),
                           crop_size=(224, 224))

    output = resnet50.predict(dog_image)
    print_top_n(output, n=5)
Esempio n. 2
0
import os

from neupy import storage, architectures

from imagenet_tools import (CURRENT_DIR, FILES_DIR, load_image, print_top_n,
                            download_file)

SQUEEZENET_WEIGHTS_FILE = os.path.join(FILES_DIR, 'squeezenet.hdf5')

# Networks weight ~4.8 Mb
squeezenet = architectures.squeezenet()

if not os.path.exists(SQUEEZENET_WEIGHTS_FILE):
    download_file(
        url=
        "http://neupy.s3.amazonaws.com/tensorflow/imagenet-models/squeezenet.hdf5",
        filepath=SQUEEZENET_WEIGHTS_FILE,
        description='Downloading weights')

storage.load(squeezenet, SQUEEZENET_WEIGHTS_FILE)

monkey_image = load_image(os.path.join(CURRENT_DIR, 'images',
                                       'titi-monkey.jpg'),
                          image_size=(227, 227),
                          crop_size=(227, 227),
                          use_bgr=True)

output = squeezenet.predict(monkey_image)
print_top_n(output, n=5)
Esempio n. 3
0
        [SliceChannels(192, 384), layers.Convolution((128, 3, 3), padding=1, name="conv_5_2"), layers.Relu()],
    ],
    layers.Concatenate(),
    layers.MaxPooling((3, 3), stride=(2, 2)),
    layers.Reshape(),
    layers.Relu(4096, name="dense_1") > layers.Dropout(0.5),
    layers.Relu(4096, name="dense_2") > layers.Dropout(0.5),
    layers.Softmax(1000, name="dense_3"),
)

if not os.path.exists(ALEXNET_WEIGHTS_FILE):
    download_file(
        url=("http://srv70.putdrive.com/putstorage/DownloadFileHash/" "F497B1D43A5A4A5QQWE2295998EWQS/alexnet.pickle"),
        filepath=ALEXNET_WEIGHTS_FILE,
        description="Downloading weights",
    )

storage.load(alexnet, ALEXNET_WEIGHTS_FILE)

dog_image = load_image(
    os.path.join(CURRENT_DIR, "images", "dog.jpg"), image_size=(256, 256), crop_size=(227, 227), use_bgr=False
)

# Disables dropout layer
with alexnet.disable_training_state():
    x = T.tensor4()
    predict = theano.function([x], alexnet.output(x))

output = predict(dog_image)
print_top_n(output[0], n=5)
Esempio n. 4
0
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)
Esempio n. 5
0
    layers.Convolution((1000, 1, 1), padding='valid', name='conv10'),
    layers.GlobalPooling(function=T.mean),
    layers.Reshape(),
    layers.Softmax(),
)

if not os.path.exists(SQUEEZENET_WEIGHTS_FILE):
    download_file(
        url=(
            "http://srv70.putdrive.com/putstorage/DownloadFileHash/"
            "6B0A15B43A5A4A5QQWE2304100EWQS/squeezenet.pickle"
        ),
        filepath=SQUEEZENET_WEIGHTS_FILE,
        description='Downloading weights'
    )

storage.load(squeezenet, SQUEEZENET_WEIGHTS_FILE)

monkey_image = load_image(
    os.path.join(CURRENT_DIR, 'images', 'titi-monkey.jpg'),
    image_size=(256, 256),
    crop_size=(224, 224))

# Disables dropout layer
with squeezenet.disable_training_state():
    x = T.tensor4()
    predict = theano.function([x], squeezenet.output(x))

output = predict(monkey_image)
print_top_n(output[0], n=5)
Esempio n. 6
0
import os

import theano
from neupy import layers, storage, architectures

from imagenet_tools import (CURRENT_DIR, FILES_DIR, load_image, print_top_n,
                            download_file)

theano.config.floatX = 'float32'
ALEXNET_WEIGHTS_FILE = os.path.join(FILES_DIR, 'alexnet.pickle')

alexnet = architectures.alexnet()

if not os.path.exists(ALEXNET_WEIGHTS_FILE):
    download_file(
        url="http://neupy.s3.amazonaws.com/imagenet-models/alexnet.pickle",
        filepath=ALEXNET_WEIGHTS_FILE,
        description='Downloading weights')

storage.load(alexnet, ALEXNET_WEIGHTS_FILE)

dog_image = load_image(os.path.join(CURRENT_DIR, 'images', 'dog.jpg'),
                       image_size=(256, 256),
                       crop_size=(227, 227),
                       use_bgr=False)

predict = alexnet.compile()
output = predict(dog_image)
print_top_n(output, n=5)
Esempio n. 7
0
    layers.MaxPooling((2, 2)),
    layers.Convolution((512, 3, 3), padding=1, name="conv5_1") > layers.Relu(),
    layers.Convolution((512, 3, 3), padding=1, name="conv5_2") > layers.Relu(),
    layers.Convolution((512, 3, 3), padding=1, name="conv5_3") > layers.Relu(),
    layers.Convolution((512, 3, 3), padding=1, name="conv5_4") > layers.Relu(),
    layers.MaxPooling((2, 2)),
    layers.Reshape(),
    layers.Relu(4096, name="dense_1") > layers.Dropout(0.5),
    layers.Relu(4096, name="dense_2") > layers.Dropout(0.5),
    layers.Softmax(1000, name="dense_3"),
)

if not os.path.exists(VGG19_WEIGHTS_FILE):
    download_file(
        url=("http://srv70.putdrive.com/putstorage/DownloadFileHash/" "F9A70DEA3A5A4A5QQWE2301487EWQS/vgg19.pickle"),
        filepath=VGG19_WEIGHTS_FILE,
        description="Downloading weights",
    )

storage.load(vgg19, VGG19_WEIGHTS_FILE)

dog_image = load_image(os.path.join(CURRENT_DIR, "images", "dog.jpg"), image_size=(256, 256), crop_size=(224, 224))

# Disables dropout layer
with vgg19.disable_training_state():
    x = T.tensor4()
    predict = theano.function([x], vgg19.output(x))

output = predict(dog_image)
print_top_n(output[0], n=5)
Esempio n. 8
0
    layers.MaxPooling((2, 2)),
    Fire(32, 128, 128, name='fire5'),
    Fire(48, 192, 192, name='fire6'),
    Fire(48, 192, 192, name='fire7'),
    Fire(64, 256, 256, name='fire8'),
    layers.MaxPooling((2, 2)),
    Fire(64, 256, 256, name='fire9'),
    layers.Dropout(0.5),
    layers.Convolution((1000, 1, 1), padding='valid', name='conv10'),
    layers.GlobalPooling(function=T.mean),
    layers.Reshape(),
    layers.Softmax(),
)

if not os.path.exists(SQUEEZENET_WEIGHTS_FILE):
    download_file(url=("http://srv70.putdrive.com/putstorage/DownloadFileHash/"
                       "6B0A15B43A5A4A5QQWE2304100EWQS/squeezenet.pickle"),
                  filepath=SQUEEZENET_WEIGHTS_FILE,
                  description='Downloading weights')

storage.load(squeezenet, SQUEEZENET_WEIGHTS_FILE)

monkey_image = load_image(os.path.join(CURRENT_DIR, 'images',
                                       'titi-monkey.jpg'),
                          image_size=(224, 224))

predict = squeezenet.compile()
output = predict(monkey_image)

print_top_n(output[0], n=5)
Esempio n. 9
0
    layers.Reshape(),

    layers.Relu(4096, name='dense_1') > layers.Dropout(0.5),
    layers.Relu(4096, name='dense_2') > layers.Dropout(0.5),
    layers.Softmax(1000, name='dense_3'),
)

if not os.path.exists(VGG16_WEIGHTS_FILE):
    download_file(
        url=(
            "http://srv70.putdrive.com/putstorage/DownloadFileHash/"
            "5B7DCBF43A5A4A5QQWE2301430EWQS/vgg16.pickle"
        ),
        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))

# Disables dropout layer
with vgg16.disable_training_state():
    x = T.tensor4()
    predict = theano.function([x], vgg16.output(x))

output = predict(dog_image)
print_top_n(output[0], n=5)