forked from WZMIAOMIAO/deep-learning-for-image-processing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62ff7b4
commit ed58342
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from model import vgg | ||
from PIL import Image | ||
import numpy as np | ||
import json | ||
import matplotlib.pyplot as plt | ||
|
||
im_height = 224 | ||
im_width = 224 | ||
|
||
# load image | ||
img = Image.open("../tulip.jpg") | ||
# resize image to 224x224 | ||
img = img.resize((im_width, im_height)) | ||
plt.imshow(img) | ||
|
||
# scaling pixel value to (0-1) | ||
img = np.array(img) / 255. | ||
|
||
# Add the image to a batch where it's the only member. | ||
img = (np.expand_dims(img, 0)) | ||
|
||
# read class_indict | ||
try: | ||
json_file = open('./class_indices.json', 'r') | ||
class_indict = json.load(json_file) | ||
except Exception as e: | ||
print(e) | ||
exit(-1) | ||
|
||
model = vgg("vgg16", 224, 224, 5) | ||
model.load_weights("./save_weights/myVGG.h5") | ||
result = np.squeeze(model.predict(img)) | ||
predict_class = np.argmax(result) | ||
print(class_indict[str(predict_class)], result[predict_class]) | ||
plt.show() |