Skip to content

Commit e14a898

Browse files
zsdonghaoluomai
authored andcommitted
fixed vgg19 example - codacy (#350)
1 parent 5fa98cf commit e14a898

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

example/tutorial_vgg19.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ def load_image(path):
3636
# load image
3737
img = skimage.io.imread(path)
3838
img = img / 255.0
39-
assert (0 <= img).all() and (img <= 1.0).all()
39+
if ((0 <= img).all() and (img <= 1.0).all()) is False:
40+
raise Exception("image value should be [0, 1]")
4041
# print "Original Image Shape: ", img.shape
4142
# we crop image from center
4243
short_edge = min(img.shape[:2])
@@ -78,9 +79,12 @@ def Vgg19(rgb):
7879
else: # TF 1.0
7980
print(rgb_scaled)
8081
red, green, blue = tf.split(rgb_scaled, 3, 3)
81-
assert red.get_shape().as_list()[1:] == [224, 224, 1]
82-
assert green.get_shape().as_list()[1:] == [224, 224, 1]
83-
assert blue.get_shape().as_list()[1:] == [224, 224, 1]
82+
if red.get_shape().as_list()[1:] != [224, 224, 1]:
83+
raise Exception("image size unmatch")
84+
if green.get_shape().as_list()[1:] != [224, 224, 1]:
85+
raise Exception("image size unmatch")
86+
if blue.get_shape().as_list()[1:] != [224, 224, 1]:
87+
raise Exception("image size unmatch")
8488
if tf.__version__ <= '0.11':
8589
bgr = tf.concat(3, [
8690
blue - VGG_MEAN[0],
@@ -94,7 +98,8 @@ def Vgg19(rgb):
9498
green - VGG_MEAN[1],
9599
red - VGG_MEAN[2],
96100
], axis=3)
97-
assert bgr.get_shape().as_list()[1:] == [224, 224, 3]
101+
if bgr.get_shape().as_list()[1:] != [224, 224, 3]:
102+
raise Exception("image size unmatch")
98103
# input layer
99104
net_in = InputLayer(bgr, name='input')
100105
# conv1
@@ -149,9 +154,12 @@ def Vgg19_simple_api(rgb):
149154
else: # TF 1.0
150155
print(rgb_scaled)
151156
red, green, blue = tf.split(rgb_scaled, 3, 3)
152-
assert red.get_shape().as_list()[1:] == [224, 224, 1]
153-
assert green.get_shape().as_list()[1:] == [224, 224, 1]
154-
assert blue.get_shape().as_list()[1:] == [224, 224, 1]
157+
if red.get_shape().as_list()[1:] != [224, 224, 1]:
158+
raise Exception("image size unmatch")
159+
if green.get_shape().as_list()[1:] != [224, 224, 1]:
160+
raise Exception("image size unmatch")
161+
if blue.get_shape().as_list()[1:] != [224, 224, 1]:
162+
raise Exception("image size unmatch")
155163
if tf.__version__ <= '0.11':
156164
bgr = tf.concat(3, [
157165
blue - VGG_MEAN[0],
@@ -165,7 +173,8 @@ def Vgg19_simple_api(rgb):
165173
green - VGG_MEAN[1],
166174
red - VGG_MEAN[2],
167175
], axis=3)
168-
assert bgr.get_shape().as_list()[1:] == [224, 224, 3]
176+
if bgr.get_shape().as_list()[1:] != [224, 224, 3]:
177+
raise Exception("image size unmatch")
169178
# input layer
170179
net_in = InputLayer(bgr, name='input')
171180
# conv1

0 commit comments

Comments
 (0)