@@ -54,11 +54,31 @@ def vgg19_simple_api(net_in, end_with):
5454 # with pixels values in the range of 0-255 and subtracts the mean image
5555 # values (calculated over the entire ImageNet training set).
5656
57- # Rescale the input tensor with pixels values in the range of 0-255
58- net_in .outputs = net_in .outputs * 255.0
59-
60- mean = tf .constant ([103.939 , 116.779 , 123.68 ], dtype = tf .float32 , shape = [1 , 1 , 1 , 3 ], name = 'img_mean' )
61- net_in .outputs = net_in .outputs - mean
57+ # # Rescale the input tensor with pixels values in the range of 0-255
58+ # net_in.outputs = net_in.outputs * 255.0
59+ # red, green, blue = tf.split(net_in.outputs, 3, 3)
60+ VGG_MEAN = [103.939 , 116.779 , 123.68 ]
61+ #
62+ # bgr = tf.concat([
63+ # blue - VGG_MEAN[0],
64+ # green - VGG_MEAN[1],
65+ # red - VGG_MEAN[2],
66+ # ], axis=3)
67+ # # mean = tf.constant([103.939, 116.779, 123.68], dtype=tf.float32, shape=[1, 1, 1, 3], name='img_mean')
68+ # # net_in.outputs = net_in.outputs - mean
69+ # net_in.outputs = bgr
70+ rgb = net_in .outputs
71+ rgb_scaled = rgb * 255.0
72+ # Convert RGB to BGR
73+ red , green , blue = tf .split (rgb_scaled , 3 , 3 )
74+
75+ bgr = tf .concat ([
76+ blue - VGG_MEAN [0 ],
77+ green - VGG_MEAN [1 ],
78+ red - VGG_MEAN [2 ],
79+ ], axis = 3 )
80+
81+ net_in .outputs = bgr
6282
6383 layers = [
6484 # conv1
@@ -163,6 +183,8 @@ def restore_params(self, sess):
163183 b = np .asarray (val [1 ][1 ])
164184 print (" Loading %s: %s, %s" % (val [0 ], W .shape , b .shape ))
165185 params .extend ([W , b ])
186+ if len (self .all_params ) == len (params ):
187+ break
166188
167189 print ("Restoring model from npz file" )
168190 assign_params (sess , params , self .net )
0 commit comments