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
def prepare_image(fname): with open(IMAGENET_MEAN_FILE, 'rb') as f: # Mean values is the average image accros all training dataset. # if dataset (1000, 3, 224, 224) then mean image shape # is (3, 224, 224) and computes as data.mean(axis=0) mean_values = pickle.load(f) image = read_image(fname, image_size=(256, 256), crop_size=(224, 224)) # Convert RGB to BGR image[:, (0, 1, 2), :, :] = image[:, (2, 1, 0), :, :] return asfloat(image - mean_values) environment.speedup() resnet50 = architectures.resnet50() if not os.path.exists(RESNET50_WEIGHTS_FILE): download_file( url="http://neupy.s3.amazonaws.com/imagenet-models/resnet50.pickle", filepath=RESNET50_WEIGHTS_FILE, description='Downloading weights') storage.load(resnet50, RESNET50_WEIGHTS_FILE) predict = resnet50.compile() dog_image = prepare_image(DOG_IMAGE_PATH) output = predict(dog_image) print_top_n(output, n=5)
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)
[ [SliceChannels(0, 192), layers.Convolution((128, 3, 3), padding=1, name="conv_5_1"), layers.Relu()], [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)
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)
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=(256, 256), crop_size=(224, 224)) # Disables dropout layer with squeezenet.disable_training_state(): x = T.tensor4() predict = theano.function([x], squeezenet.output(x))
layers.Convolution((512, 3, 3), padding=1, name='conv4_1') > layers.Relu(), layers.Convolution((512, 3, 3), padding=1, name='conv4_2') > layers.Relu(), layers.Convolution((512, 3, 3), padding=1, name='conv4_3') > layers.Relu(), 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.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(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)) predict = vgg16.compile() output = predict(dog_image) print_top_n(output[0], n=5)
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)
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)) predict = vgg19.compile() output = predict(dog_image) print_top_n(output[0], n=5)
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) VGG19_WEIGHTS_FILE = os.path.join(FILES_DIR, 'vgg19.pickle') DOG_IMAGE_PATH = os.path.join(CURRENT_DIR, 'images', 'german-shepherd.jpg') theano.config.floatX = 'float32' vgg19 = architectures.vgg19() if not os.path.exists(VGG19_WEIGHTS_FILE): download_file( url="http://neupy.s3.amazonaws.com/imagenet-models/vgg19.pickle", filepath=VGG19_WEIGHTS_FILE, description='Downloading weights') storage.load(vgg19, VGG19_WEIGHTS_FILE) dog_image = load_image(DOG_IMAGE_PATH, image_size=(256, 256), crop_size=(224, 224)) predict = vgg19.compile() output = predict(dog_image) print_top_n(output, n=5)
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)
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)
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.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(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))
[ 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) predict = alexnet.compile() output = predict(dog_image) print_top_n(output[0], n=5)