Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ Added a trainable version of the VGG19 `vgg19_trainable`. It support train from
A very simple testing is added `test_vgg19_trainable`, switch has demo about how to train, switch off train mode for verification, and how to save.

A seperated file is added (instead of changing existing one) because I want to keep the simplicity of the original VGG networks.
##Update 2018.03.07:
fix the tensorflow-version-bugs in vgg16.py, which are tf.split() and tf.concat().
modify the sytle of print in Vgg16.print_prob() in utils.py, and the result of prediction is more neat and clear after the modifications.
add a few pictures to the test_data floder, which can be used to assess the ability of prediction of VGG16
Binary file added test_data/3c528086d5241a5e5fb81d841cae8231.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/4a7ef3612f6dbb57960803c73f9a0192.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/5a7f5169b220d686631609b0c8e75a8a.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/78fcd6f44a4d77dd25b89be67337ad1f.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/bag.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/basketball.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/clothes.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/girl.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/laptop.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/man.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/shoe.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/tractor.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test_data/woman.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ def print_prob(prob, file_path):
# print prob
pred = np.argsort(prob)[::-1]

print('\n')#to make the displayed information more clear and neat
print("-------The predictions are as follow-------")
# Get top1 label
top1 = synset[pred[0]]
print("Top1: ", top1, prob[pred[0]])
# Get top5 label
top5 = [(synset[pred[i]], prob[pred[i]]) for i in range(5)]
print("Top5: ", top5)
print("Top5: ")#to make the displayed information more clear and neat
for i in range(5):
print(top5[i])
return top1


Expand Down
9 changes: 6 additions & 3 deletions vgg16.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, vgg16_npy_path=None):
path = os.path.abspath(os.path.join(path, os.pardir))
path = os.path.join(path, "vgg16.npy")
vgg16_npy_path = path
print path
print(path)#Python version 3.6 and above don not support the using"print path" but "print(path)"

self.data_dict = np.load(vgg16_npy_path, encoding='latin1').item()
print("npy file loaded")
Expand All @@ -25,18 +25,21 @@ def build(self, rgb):
load variable from npy to build the VGG

:param rgb: rgb image [batch, height, width, 3] values scaled [0, 1]
param rgb must be a tensor.
"""

start_time = time.time()
print("build model started")
rgb_scaled = rgb * 255.0

# Convert RGB to BGR
red, green, blue = tf.split(3, 3, rgb_scaled)
#In version 1.6.0, tf.split(value, num_or_size_splits, axis=0, num=None, name='split')
red, green, blue = tf.split(value=rgb_scaled,num_or_size_splits=[1,1,1],axis=3)
assert red.get_shape().as_list()[1:] == [224, 224, 1]
assert green.get_shape().as_list()[1:] == [224, 224, 1]
assert blue.get_shape().as_list()[1:] == [224, 224, 1]
bgr = tf.concat(3, [
#when the function is called, it is better that the keyword parameters is transmitted explicitly.
bgr = tf.concat(axis=3, values=[
blue - VGG_MEAN[0],
green - VGG_MEAN[1],
red - VGG_MEAN[2],
Expand Down