-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathresnet50.py
More file actions
38 lines (26 loc) · 1.14 KB
/
resnet50.py
File metadata and controls
38 lines (26 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
from neupy import storage, architectures
from imagenet_tools import (CURRENT_DIR, FILES_DIR, load_image,
print_top_n, download_file)
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)