8080# File containing the TensorFlow graph definition. (Downloaded)
8181path_graph_def = "classify_image_graph_def.pb"
8282
83- ########################################################################
84- # Names for tensors in the computational graph.
85-
86- # Name of the tensor for feeding the input image as jpeg.
87- tensor_name_input_jpeg = "DecodeJpeg/contents:0"
88-
89- # Name of the tensor for feeding the decoded input image.
90- # Use this for feeding images in other formats than jpeg.
91- tensor_name_input_image = "DecodeJpeg:0"
92-
93- # Name of the tensor for the resized input image.
94- # This is used to retrieve the image after it has been resized.
95- tensor_name_resized_image = "ResizeBilinear:0"
96-
97- # Name of the tensor for the output of the softmax-classifier.
98- # This is used for classifying images with the Inception model.
99- tensor_name_softmax = "softmax:0"
100-
101- # Name of the tensor for the output of the Inception model.
102- # This is used for Transfer Learning.
103- tensor_name_transfer_layer = "pool_3:0"
104-
10583########################################################################
10684
10785
@@ -253,6 +231,28 @@ class Inception:
253231 The Inception model can also be used for Transfer Learning.
254232 """
255233
234+ # Name of the tensor for feeding the input image as jpeg.
235+ tensor_name_input_jpeg = "DecodeJpeg/contents:0"
236+
237+ # Name of the tensor for feeding the decoded input image.
238+ # Use this for feeding images in other formats than jpeg.
239+ tensor_name_input_image = "DecodeJpeg:0"
240+
241+ # Name of the tensor for the resized input image.
242+ # This is used to retrieve the image after it has been resized.
243+ tensor_name_resized_image = "ResizeBilinear:0"
244+
245+ # Name of the tensor for the output of the softmax-classifier.
246+ # This is used for classifying images with the Inception model.
247+ tensor_name_softmax = "softmax:0"
248+
249+ # Name of the tensor for the unscaled outputs of the softmax-classifier (aka. logits).
250+ tensor_name_softmax_logits = "softmax/logits:0"
251+
252+ # Name of the tensor for the output of the Inception model.
253+ # This is used for Transfer Learning.
254+ tensor_name_transfer_layer = "pool_3:0"
255+
256256 def __init__ (self ):
257257 # Mappings between class-numbers and class-names.
258258 # Used to print the class-name as a string e.g. "horse" or "plant".
@@ -288,13 +288,16 @@ def __init__(self):
288288
289289 # Get the output of the Inception model by looking up the tensor
290290 # with the appropriate name for the output of the softmax-classifier.
291- self .y_pred = self .graph .get_tensor_by_name (tensor_name_softmax )
291+ self .y_pred = self .graph .get_tensor_by_name (self .tensor_name_softmax )
292+
293+ # Get the unscaled outputs for the Inception model (aka. softmax-logits).
294+ self .y_logits = self .graph .get_tensor_by_name (self .tensor_name_softmax_logits )
292295
293296 # Get the tensor for the resized image that is input to the neural network.
294- self .resized_image = self .graph .get_tensor_by_name (tensor_name_resized_image )
297+ self .resized_image = self .graph .get_tensor_by_name (self . tensor_name_resized_image )
295298
296299 # Get the tensor for the last layer of the graph, aka. the transfer-layer.
297- self .transfer_layer = self .graph .get_tensor_by_name (tensor_name_transfer_layer )
300+ self .transfer_layer = self .graph .get_tensor_by_name (self . tensor_name_transfer_layer )
298301
299302 # Get the number of elements in the transfer-layer.
300303 self .transfer_len = self .transfer_layer .get_shape ()[3 ]
@@ -326,8 +329,7 @@ def _write_summary(self, logdir='summary/'):
326329 writer = tf .train .SummaryWriter (logdir = logdir , graph = self .graph )
327330 writer .close ()
328331
329- @staticmethod
330- def _create_feed_dict (image_path = None , image = None ):
332+ def _create_feed_dict (self , image_path = None , image = None ):
331333 """
332334 Create and return a feed-dict with an image.
333335
@@ -344,14 +346,14 @@ def _create_feed_dict(image_path=None, image=None):
344346
345347 if image is not None :
346348 # Image is passed in as a 3-dim array that is already decoded.
347- feed_dict = {tensor_name_input_image : image }
349+ feed_dict = {self . tensor_name_input_image : image }
348350
349351 elif image_path is not None :
350352 # Read the jpeg-image as an array of bytes.
351353 image_data = tf .gfile .FastGFile (image_path , 'rb' ).read ()
352354
353355 # Image is passed in as a jpeg-encoded image.
354- feed_dict = {tensor_name_input_jpeg : image_data }
356+ feed_dict = {self . tensor_name_input_jpeg : image_data }
355357
356358 else :
357359 raise ValueError ("Either image or image_path must be set." )
0 commit comments