3737"""
3838
3939import os
40- import sys
41- import time
42- import numpy as np
43- import tensorflow as tf
4440import tensorlayer as tl
4541from scipy .misc import imread , imresize
4642from tensorlayer .layers import *
5248
5349
5450def conv_layers (net_in ):
55- with tf .name_scope ('preprocess' ) as scope :
51+ with tf .name_scope ('preprocess' ):
5652 """
5753 Notice that we include a preprocessing layer that takes the RGB image
5854 with pixels values in the range of 0-255 and subtracts the mean image
5955 values (calculated over the entire ImageNet training set).
6056 """
6157 mean = tf .constant ([123.68 , 116.779 , 103.939 ], dtype = tf .float32 , shape = [1 , 1 , 1 , 3 ], name = 'img_mean' )
6258 net_in .outputs = net_in .outputs - mean
63- """ conv1 """
59+
60+ # conv1
6461 network = Conv2dLayer (
6562 net_in ,
6663 act = tf .nn .relu ,
@@ -76,7 +73,8 @@ def conv_layers(net_in):
7673 padding = 'SAME' ,
7774 name = 'conv1_2' )
7875 network = PoolLayer (network , ksize = [1 , 2 , 2 , 1 ], strides = [1 , 2 , 2 , 1 ], padding = 'SAME' , pool = tf .nn .max_pool , name = 'pool1' )
79- """ conv2 """
76+
77+ # conv2
8078 network = Conv2dLayer (
8179 network ,
8280 act = tf .nn .relu ,
@@ -92,7 +90,8 @@ def conv_layers(net_in):
9290 padding = 'SAME' ,
9391 name = 'conv2_2' )
9492 network = PoolLayer (network , ksize = [1 , 2 , 2 , 1 ], strides = [1 , 2 , 2 , 1 ], padding = 'SAME' , pool = tf .nn .max_pool , name = 'pool2' )
95- """ conv3 """
93+
94+ # conv3
9695 network = Conv2dLayer (
9796 network ,
9897 act = tf .nn .relu ,
@@ -115,7 +114,8 @@ def conv_layers(net_in):
115114 padding = 'SAME' ,
116115 name = 'conv3_3' )
117116 network = PoolLayer (network , ksize = [1 , 2 , 2 , 1 ], strides = [1 , 2 , 2 , 1 ], padding = 'SAME' , pool = tf .nn .max_pool , name = 'pool3' )
118- """ conv4 """
117+
118+ # conv4
119119 network = Conv2dLayer (
120120 network ,
121121 act = tf .nn .relu ,
@@ -138,7 +138,8 @@ def conv_layers(net_in):
138138 padding = 'SAME' ,
139139 name = 'conv4_3' )
140140 network = PoolLayer (network , ksize = [1 , 2 , 2 , 1 ], strides = [1 , 2 , 2 , 1 ], padding = 'SAME' , pool = tf .nn .max_pool , name = 'pool4' )
141- """ conv5 """
141+
142+ # conv5
142143 network = Conv2dLayer (
143144 network ,
144145 act = tf .nn .relu ,
@@ -173,25 +174,30 @@ def conv_layers_simple_api(net_in):
173174 """
174175 mean = tf .constant ([123.68 , 116.779 , 103.939 ], dtype = tf .float32 , shape = [1 , 1 , 1 , 3 ], name = 'img_mean' )
175176 net_in .outputs = net_in .outputs - mean
176- """ conv1 """
177+
178+ # conv1
177179 network = Conv2d (net_in , n_filter = 64 , filter_size = (3 , 3 ), strides = (1 , 1 ), act = tf .nn .relu , padding = 'SAME' , name = 'conv1_1' )
178180 network = Conv2d (network , n_filter = 64 , filter_size = (3 , 3 ), strides = (1 , 1 ), act = tf .nn .relu , padding = 'SAME' , name = 'conv1_2' )
179181 network = MaxPool2d (network , filter_size = (2 , 2 ), strides = (2 , 2 ), padding = 'SAME' , name = 'pool1' )
180- """ conv2 """
182+
183+ # conv2
181184 network = Conv2d (network , n_filter = 128 , filter_size = (3 , 3 ), strides = (1 , 1 ), act = tf .nn .relu , padding = 'SAME' , name = 'conv2_1' )
182185 network = Conv2d (network , n_filter = 128 , filter_size = (3 , 3 ), strides = (1 , 1 ), act = tf .nn .relu , padding = 'SAME' , name = 'conv2_2' )
183186 network = MaxPool2d (network , filter_size = (2 , 2 ), strides = (2 , 2 ), padding = 'SAME' , name = 'pool2' )
184- """ conv3 """
187+
188+ # conv3
185189 network = Conv2d (network , n_filter = 256 , filter_size = (3 , 3 ), strides = (1 , 1 ), act = tf .nn .relu , padding = 'SAME' , name = 'conv3_1' )
186190 network = Conv2d (network , n_filter = 256 , filter_size = (3 , 3 ), strides = (1 , 1 ), act = tf .nn .relu , padding = 'SAME' , name = 'conv3_2' )
187191 network = Conv2d (network , n_filter = 256 , filter_size = (3 , 3 ), strides = (1 , 1 ), act = tf .nn .relu , padding = 'SAME' , name = 'conv3_3' )
188192 network = MaxPool2d (network , filter_size = (2 , 2 ), strides = (2 , 2 ), padding = 'SAME' , name = 'pool3' )
189- """ conv4 """
193+
194+ # conv4
190195 network = Conv2d (network , n_filter = 512 , filter_size = (3 , 3 ), strides = (1 , 1 ), act = tf .nn .relu , padding = 'SAME' , name = 'conv4_1' )
191196 network = Conv2d (network , n_filter = 512 , filter_size = (3 , 3 ), strides = (1 , 1 ), act = tf .nn .relu , padding = 'SAME' , name = 'conv4_2' )
192197 network = Conv2d (network , n_filter = 512 , filter_size = (3 , 3 ), strides = (1 , 1 ), act = tf .nn .relu , padding = 'SAME' , name = 'conv4_3' )
193198 network = MaxPool2d (network , filter_size = (2 , 2 ), strides = (2 , 2 ), padding = 'SAME' , name = 'pool4' )
194- """ conv5 """
199+
200+ # conv5
195201 network = Conv2d (network , n_filter = 512 , filter_size = (3 , 3 ), strides = (1 , 1 ), act = tf .nn .relu , padding = 'SAME' , name = 'conv5_1' )
196202 network = Conv2d (network , n_filter = 512 , filter_size = (3 , 3 ), strides = (1 , 1 ), act = tf .nn .relu , padding = 'SAME' , name = 'conv5_2' )
197203 network = Conv2d (network , n_filter = 512 , filter_size = (3 , 3 ), strides = (1 , 1 ), act = tf .nn .relu , padding = 'SAME' , name = 'conv5_3' )
@@ -249,5 +255,3 @@ def fc_layers(net):
249255preds = (np .argsort (prob )[::- 1 ])[0 :5 ]
250256for p in preds :
251257 print (class_names [p ], prob [p ])
252-
253- #
0 commit comments