diff --git a/README.md b/README.md index 07387e1..03099dc 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/test_data/3c528086d5241a5e5fb81d841cae8231.jpg b/test_data/3c528086d5241a5e5fb81d841cae8231.jpg new file mode 100644 index 0000000..98246dc Binary files /dev/null and b/test_data/3c528086d5241a5e5fb81d841cae8231.jpg differ diff --git a/test_data/4a7ef3612f6dbb57960803c73f9a0192.jpg b/test_data/4a7ef3612f6dbb57960803c73f9a0192.jpg new file mode 100644 index 0000000..bad6249 Binary files /dev/null and b/test_data/4a7ef3612f6dbb57960803c73f9a0192.jpg differ diff --git a/test_data/5a7f5169b220d686631609b0c8e75a8a.jpg b/test_data/5a7f5169b220d686631609b0c8e75a8a.jpg new file mode 100644 index 0000000..660590c Binary files /dev/null and b/test_data/5a7f5169b220d686631609b0c8e75a8a.jpg differ diff --git a/test_data/78fcd6f44a4d77dd25b89be67337ad1f.jpg b/test_data/78fcd6f44a4d77dd25b89be67337ad1f.jpg new file mode 100644 index 0000000..2af7943 Binary files /dev/null and b/test_data/78fcd6f44a4d77dd25b89be67337ad1f.jpg differ diff --git a/test_data/bag.jpg b/test_data/bag.jpg new file mode 100644 index 0000000..9d972d4 Binary files /dev/null and b/test_data/bag.jpg differ diff --git a/test_data/basketball.jpg b/test_data/basketball.jpg new file mode 100644 index 0000000..7b3b10f Binary files /dev/null and b/test_data/basketball.jpg differ diff --git a/test_data/clothes.jpg b/test_data/clothes.jpg new file mode 100644 index 0000000..0894f4a Binary files /dev/null and b/test_data/clothes.jpg differ diff --git a/test_data/girl.jpg b/test_data/girl.jpg new file mode 100644 index 0000000..51ee99b Binary files /dev/null and b/test_data/girl.jpg differ diff --git a/test_data/laptop.jpg b/test_data/laptop.jpg new file mode 100644 index 0000000..521e6aa Binary files /dev/null and b/test_data/laptop.jpg differ diff --git a/test_data/man.jpg b/test_data/man.jpg new file mode 100644 index 0000000..432feae Binary files /dev/null and b/test_data/man.jpg differ diff --git a/test_data/shoe.jpg b/test_data/shoe.jpg new file mode 100644 index 0000000..7d558ef Binary files /dev/null and b/test_data/shoe.jpg differ diff --git a/test_data/tractor.jpg b/test_data/tractor.jpg new file mode 100644 index 0000000..833db60 Binary files /dev/null and b/test_data/tractor.jpg differ diff --git a/test_data/woman.jpg b/test_data/woman.jpg new file mode 100644 index 0000000..63672fc Binary files /dev/null and b/test_data/woman.jpg differ diff --git a/utils.py b/utils.py index 8398d47..168743f 100755 --- a/utils.py +++ b/utils.py @@ -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 diff --git a/vgg16.py b/vgg16.py index 67c5204..2551d83 100755 --- a/vgg16.py +++ b/vgg16.py @@ -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") @@ -25,6 +25,7 @@ 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() @@ -32,11 +33,13 @@ def build(self, rgb): 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],