def testModelVariables(self): batch_size = 5 height, width = 224, 224 num_classes = 1000 with self.cached_session(): inputs = random_ops.random_uniform((batch_size, height, width, 3)) alexnet.alexnet_v2(inputs, num_classes) expected_names = [ 'alexnet_v2/conv1/weights', 'alexnet_v2/conv1/biases', 'alexnet_v2/conv2/weights', 'alexnet_v2/conv2/biases', 'alexnet_v2/conv3/weights', 'alexnet_v2/conv3/biases', 'alexnet_v2/conv4/weights', 'alexnet_v2/conv4/biases', 'alexnet_v2/conv5/weights', 'alexnet_v2/conv5/biases', 'alexnet_v2/fc6/weights', 'alexnet_v2/fc6/biases', 'alexnet_v2/fc7/weights', 'alexnet_v2/fc7/biases', 'alexnet_v2/fc8/weights', 'alexnet_v2/fc8/biases', ] model_variables = [v.op.name for v in variables_lib.get_model_variables()] self.assertSetEqual(set(model_variables), set(expected_names))
def testForward(self): batch_size = 1 height, width = 224, 224 with self.cached_session() as sess: inputs = random_ops.random_uniform((batch_size, height, width, 3)) logits, _ = alexnet.alexnet_v2(inputs) sess.run(variables.global_variables_initializer()) output = sess.run(logits) self.assertTrue(output.any())
def testFullyConvolutional(self): batch_size = 1 height, width = 300, 400 num_classes = 1000 with self.cached_session(): inputs = random_ops.random_uniform((batch_size, height, width, 3)) logits, _ = alexnet.alexnet_v2(inputs, num_classes, spatial_squeeze=False) self.assertEqual(logits.op.name, 'alexnet_v2/fc8/BiasAdd') self.assertListEqual(logits.get_shape().as_list(), [batch_size, 4, 7, num_classes])
def testBuild(self): batch_size = 5 height, width = 224, 224 num_classes = 1000 with self.cached_session(): inputs = random_ops.random_uniform((batch_size, height, width, 3)) logits, _ = alexnet.alexnet_v2(inputs, num_classes) self.assertEqual(logits.op.name, 'alexnet_v2/fc8/squeezed') self.assertListEqual(logits.get_shape().as_list(), [batch_size, num_classes])
def testEvaluation(self): batch_size = 2 height, width = 224, 224 num_classes = 1000 with self.cached_session(): eval_inputs = random_ops.random_uniform((batch_size, height, width, 3)) logits, _ = alexnet.alexnet_v2(eval_inputs, is_training=False) self.assertListEqual(logits.get_shape().as_list(), [batch_size, num_classes]) predictions = math_ops.argmax(logits, 1) self.assertListEqual(predictions.get_shape().as_list(), [batch_size])
def testTrainEvalWithReuse(self): train_batch_size = 2 eval_batch_size = 1 train_height, train_width = 224, 224 eval_height, eval_width = 300, 400 num_classes = 1000 with self.cached_session(): train_inputs = random_ops.random_uniform( (train_batch_size, train_height, train_width, 3)) logits, _ = alexnet.alexnet_v2(train_inputs) self.assertListEqual(logits.get_shape().as_list(), [train_batch_size, num_classes]) variable_scope.get_variable_scope().reuse_variables() eval_inputs = random_ops.random_uniform( (eval_batch_size, eval_height, eval_width, 3)) logits, _ = alexnet.alexnet_v2( eval_inputs, is_training=False, spatial_squeeze=False) self.assertListEqual(logits.get_shape().as_list(), [eval_batch_size, 4, 7, num_classes]) logits = math_ops.reduce_mean(logits, [1, 2]) predictions = math_ops.argmax(logits, 1) self.assertEqual(predictions.get_shape().as_list(), [eval_batch_size])
def testEndPoints(self): batch_size = 5 height, width = 224, 224 num_classes = 1000 with self.cached_session(): inputs = random_ops.random_uniform((batch_size, height, width, 3)) _, end_points = alexnet.alexnet_v2(inputs, num_classes) expected_names = [ 'alexnet_v2/conv1', 'alexnet_v2/pool1', 'alexnet_v2/conv2', 'alexnet_v2/pool2', 'alexnet_v2/conv3', 'alexnet_v2/conv4', 'alexnet_v2/conv5', 'alexnet_v2/pool5', 'alexnet_v2/fc6', 'alexnet_v2/fc7', 'alexnet_v2/fc8' ] self.assertSetEqual(set(end_points.keys()), set(expected_names))