def build_image_embeddings(self): """Builds the image model subgraph and generates image embeddings. Inputs: self.images Outputs: self.image_embeddings """ inception_output = image_embedding.inception_v3( self.images, trainable=self.train_inception, is_training=self.is_training()) self.inception_variables = tf.get_collection( tf.GraphKeys.GLOBAL_VARIABLES, scope="InceptionV3") # Compute the average pool of the outputs from inception context_tensor = tf.reduce_mean(inception_output, axis=[1, 2]) # Map inception output into embedding space. with tf.variable_scope("image_embedding") as scope: image_embeddings = tf.contrib.layers.fully_connected( inputs=context_tensor, num_outputs=self.config.embedding_size, activation_fn=None, weights_initializer=self.initializer, biases_initializer=None, scope=scope) # Save the embedding size in the graph. tf.constant(self.config.embedding_size, name="embedding_size") self.inception_output = inception_output self.image_embeddings = image_embeddings
def testTrainableTrueIsTrainingFalse(self): embeddings = image_embedding.inception_v3(self._images, trainable=True, is_training=False) self.assertEqual([self._batch_size, 2048], embeddings.get_shape().as_list()) self._verifyParameterCounts() self._assertCollectionSize(376, tf.GraphKeys.GLOBAL_VARIABLES) self._assertCollectionSize(188, tf.GraphKeys.TRAINABLE_VARIABLES) self._assertCollectionSize(0, tf.GraphKeys.UPDATE_OPS) self._assertCollectionSize(94, tf.GraphKeys.REGULARIZATION_LOSSES) self._assertCollectionSize(0, tf.GraphKeys.LOSSES) self._assertCollectionSize(23, tf.GraphKeys.SUMMARIES)