Python tensorflow.python.ops.variables.global_variables_initializer() Examples

The following are 30 code examples of tensorflow.python.ops.variables.global_variables_initializer(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tensorflow.python.ops.variables , or try the search function .
Example #1
Source File: resnet_v1_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def testUnknownBatchSize(self):
    batch = 2
    height, width = 65, 65
    global_pool = True
    num_classes = 10
    inputs = create_test_input(None, height, width, 3)
    with arg_scope(resnet_utils.resnet_arg_scope()):
      logits, _ = self._resnet_small(
          inputs, num_classes, global_pool, scope='resnet')
    self.assertTrue(logits.op.name.startswith('resnet/logits'))
    self.assertListEqual(logits.get_shape().as_list(),
                         [None, 1, 1, num_classes])
    images = create_test_input(batch, height, width, 3)
    with self.test_session() as sess:
      sess.run(variables.global_variables_initializer())
      output = sess.run(logits, {inputs: images.eval()})
      self.assertEqual(output.shape, (batch, 1, 1, num_classes)) 
Example #2
Source File: sample_inputs_op_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def testWeights(self):
    with self.test_session():
      variables.global_variables_initializer().run()
      (indices, feature_updates,
       threshold_updates) = (tensor_forest_ops.sample_inputs(
           self.input_data, [], [], [], [0.5, 0.1, 0.8, 0.7],
           self.node_map,
           self.leaves,
           self.split_features,
           self.split_thresholds,
           input_spec=self.data_spec,
           split_initializations_per_input=1,
           split_sampling_random_seed=3))
      self.assertAllEqual([1, 0], indices.eval())
      self.assertAllEqual([[1, 0, 0], [-1, -1, -1]], feature_updates.eval())
      self.assertAllEqual([[5., -2., 20.], [0., 0., 0.]],
                          threshold_updates.eval()) 
Example #3
Source File: sample_inputs_op_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def testBadInput(self):
    del self.split_features[1]
    with self.test_session():
      variables.global_variables_initializer().run()
      with self.assertRaisesOpError(
          'split_features and split_thresholds should be the same shape.'):
        indices, _, _ = tensor_forest_ops.sample_inputs(
            self.input_data, [], [], [], [],
            self.node_map,
            self.leaves,
            self.split_features,
            self.split_thresholds,
            input_spec=self.data_spec,
            split_initializations_per_input=1,
            split_sampling_random_seed=3)
        self.assertAllEqual([], indices.eval()) 
Example #4
Source File: sample_inputs_op_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def testSimple(self):
    with self.test_session():
      variables.global_variables_initializer().run()
      (indices, feature_updates,
       threshold_updates) = (tensor_forest_ops.sample_inputs(
           self.input_data, [], [], [], [],
           self.node_map,
           self.leaves,
           self.split_features,
           self.split_thresholds,
           split_initializations_per_input=1,
           input_spec=self.data_spec,
           split_sampling_random_seed=2))
      self.assertAllEqual([1, 0], indices.eval())
      self.assertAllEqual([[1, 0, 1], [1, 1, -1]], feature_updates.eval())
      self.assertAllEqual([[5., -2., 50.], [10., 2., 0.]],
                          threshold_updates.eval()) 
Example #5
Source File: main_op_impl.py    From lambda-packs with MIT License 6 votes vote down vote up
def main_op():
  """Returns a main op to init variables and tables.

  Returns the main op including the group of ops that initializes all
  variables, initializes local variables and initialize all tables.

  Returns:
    The set of ops to be run as part of the main op upon the load operation.
  """
  init = variables.global_variables_initializer()
  init_local = variables.local_variables_initializer()
  init_tables = lookup_ops.tables_initializer()
  return control_flow_ops.group(init, init_local, init_tables)


# TODO(sukritiramesh): Integrate with Saver for complete restore functionality. 
Example #6
Source File: supervisor.py    From lambda-packs with MIT License 6 votes vote down vote up
def _init_init_op(self, init_op=USE_DEFAULT, init_feed_dict=None):
    """Initializes init_op.

    Args:
      init_op: `Operation` to initialize the variables. If set to USE_DEFAULT,
        create an op that initializes all variables and tables.
      init_feed_dict: A dictionary that maps `Tensor` objects to feed values.
        This feed dictionary will be used when `init_op` is evaluated.
    """
    if init_op is Supervisor.USE_DEFAULT:
      init_op = self._get_first_op_from_collection(ops.GraphKeys.INIT_OP)
      if init_op is None:
        init_op = variables.global_variables_initializer()
        ops.add_to_collection(ops.GraphKeys.INIT_OP, init_op)
    self._init_op = init_op
    self._init_feed_dict = init_feed_dict 
Example #7
Source File: session_debug_testlib.py    From lambda-packs with MIT License 6 votes vote down vote up
def testDebugCondWatchingWholeGraphWorks(self):
    with session.Session() as sess:
      x = variables.Variable(10.0, name="x")
      y = variables.Variable(20.0, name="y")
      cond = control_flow_ops.cond(
          x > y, lambda: math_ops.add(x, 1), lambda: math_ops.add(y, 1))

      sess.run(variables.global_variables_initializer())

      run_options = config_pb2.RunOptions(output_partition_graphs=True)
      debug_utils.watch_graph(run_options,
                              sess.graph,
                              debug_urls=self._debug_urls())
      run_metadata = config_pb2.RunMetadata()
      self.assertEqual(
          21, sess.run(cond, options=run_options, run_metadata=run_metadata))

      dump = debug_data.DebugDumpDir(
          self._dump_root, partition_graphs=run_metadata.partition_graphs)
      self.assertAllClose(
          [21.0], dump.get_tensors("cond/Merge", 0, "DebugIdentity")) 
Example #8
Source File: session_bundle_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def setUp(self):
    self.base_path = os.path.join(test.get_temp_dir(), "no_vars")
    if not os.path.exists(self.base_path):
      os.mkdir(self.base_path)

    # Create a simple graph with a variable, then convert variables to
    # constants and export the graph.
    with ops.Graph().as_default() as g:
      x = array_ops.placeholder(dtypes.float32, name="x")
      w = variables.Variable(3.0)
      y = math_ops.subtract(w * x, 7.0, name="y")  # pylint: disable=unused-variable
      ops.add_to_collection("meta", "this is meta")

      with self.test_session(graph=g) as session:
        variables.global_variables_initializer().run()
        new_graph_def = graph_util.convert_variables_to_constants(
            session, g.as_graph_def(), ["y"])

      filename = os.path.join(self.base_path, constants.META_GRAPH_DEF_FILENAME)
      saver.export_meta_graph(
          filename, graph_def=new_graph_def, collection_list=["meta"]) 
Example #9
Source File: learning_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def testNoneGlobalStep(self):
    with ops.Graph().as_default():
      random_seed.set_random_seed(0)
      tf_inputs = constant_op.constant(self._inputs, dtype=dtypes.float32)
      tf_labels = constant_op.constant(self._labels, dtype=dtypes.float32)

      tf_predictions = BatchNormClassifier(tf_inputs)
      loss_ops.log_loss(tf_predictions, tf_labels)
      total_loss = loss_ops.get_total_loss()
      optimizer = gradient_descent.GradientDescentOptimizer(learning_rate=1.0)

      train_op = learning.create_train_op(
          total_loss, optimizer, global_step=None)

      global_step = variables_lib2.get_or_create_global_step()

      with session.Session() as sess:
        # Initialize all variables
        sess.run(variables_lib.global_variables_initializer())

        for _ in range(10):
          sess.run([train_op])
        global_step = global_step.eval()
        # Since train_op don't use global_step it shouldn't change.
        self.assertAllClose(global_step, 0) 
Example #10
Source File: learning_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def testUseGlobalStep(self):
    with ops.Graph().as_default():
      random_seed.set_random_seed(0)
      tf_inputs = constant_op.constant(self._inputs, dtype=dtypes.float32)
      tf_labels = constant_op.constant(self._labels, dtype=dtypes.float32)

      tf_predictions = BatchNormClassifier(tf_inputs)
      loss_ops.log_loss(tf_predictions, tf_labels)
      total_loss = loss_ops.get_total_loss()
      optimizer = gradient_descent.GradientDescentOptimizer(learning_rate=1.0)

      train_op = learning.create_train_op(total_loss, optimizer)

      global_step = variables_lib2.get_or_create_global_step()

      with session.Session() as sess:
        # Initialize all variables
        sess.run(variables_lib.global_variables_initializer())

        for _ in range(10):
          sess.run([train_op])
        global_step = global_step.eval()
        # After 10 updates global_step should be 10.
        self.assertAllClose(global_step, 10) 
Example #11
Source File: stepper_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def setUp(self):
    self.a = variables.Variable(2.0, name="a")
    self.b = variables.Variable(3.0, name="b")

    self.c = math_ops.multiply(self.a, self.b, name="c")  # Should be 6.0.
    self.d = math_ops.multiply(self.a, self.a, name="d")  # Should be 4.0.

    self.e = math_ops.multiply(self.d, self.c, name="e")  # Should be 24.0.

    self.f_y = constant_op.constant(0.30, name="f_y")
    self.f = math_ops.div(self.b, self.f_y, name="f")  # Should be 10.0.

    # The there nodes x, y and z form a graph with "cross-links" in. I.e., x
    # and y are both direct inputs to z, but x is also a direct input to y.
    self.x = variables.Variable(2.0, name="x")  # Should be 2.0
    self.y = math_ops.negative(self.x, name="y")  # Should be -2.0.

    self.z = math_ops.multiply(self.x, self.y, name="z")  # Should be -4.0.

    self.sess = session.Session()
    self.sess.run(variables.global_variables_initializer())

    self.sess = session.Session()
    self.sess.run(variables.global_variables_initializer()) 
Example #12
Source File: supervisor.py    From ctw-baseline with MIT License 6 votes vote down vote up
def _init_init_op(self, init_op=USE_DEFAULT, init_feed_dict=None):
    """Initializes init_op.

    Args:
      init_op: `Operation` to initialize the variables. If set to USE_DEFAULT,
        create an op that initializes all variables and tables.
      init_feed_dict: A dictionary that maps `Tensor` objects to feed values.
        This feed dictionary will be used when `init_op` is evaluated.
    """
    if init_op is Supervisor.USE_DEFAULT:
      init_op = self._get_first_op_from_collection(ops.GraphKeys.INIT_OP)
      if init_op is None:
        init_op = variables.global_variables_initializer()
        ops.add_to_collection(ops.GraphKeys.INIT_OP, init_op)
    self._init_op = init_op
    self._init_feed_dict = init_feed_dict 
Example #13
Source File: resnet_v1_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def testAtrousFullyConvolutionalValues(self):
    """Verify dense feature extraction with atrous convolution."""
    nominal_stride = 32
    for output_stride in [4, 8, 16, 32, None]:
      with arg_scope(resnet_utils.resnet_arg_scope(is_training=False)):
        with ops.Graph().as_default():
          with self.test_session() as sess:
            random_seed.set_random_seed(0)
            inputs = create_test_input(2, 81, 81, 3)
            # Dense feature extraction followed by subsampling.
            output, _ = self._resnet_small(
                inputs, None, global_pool=False, output_stride=output_stride)
            if output_stride is None:
              factor = 1
            else:
              factor = nominal_stride // output_stride
            output = resnet_utils.subsample(output, factor)
            # Make the two networks use the same weights.
            variable_scope.get_variable_scope().reuse_variables()
            # Feature extraction at the nominal network rate.
            expected, _ = self._resnet_small(inputs, None, global_pool=False)
            sess.run(variables.global_variables_initializer())
            self.assertAllClose(
                output.eval(), expected.eval(), atol=1e-4, rtol=1e-4) 
Example #14
Source File: inception_v2_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def testUnknownImageShape(self):
    ops.reset_default_graph()
    batch_size = 2
    height, width = 224, 224
    num_classes = 1000
    input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
    with self.test_session() as sess:
      inputs = array_ops.placeholder(
          dtypes.float32, shape=(batch_size, None, None, 3))
      logits, end_points = inception_v2.inception_v2(inputs, num_classes)
      self.assertTrue(logits.op.name.startswith('InceptionV2/Logits'))
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes])
      pre_pool = end_points['Mixed_5c']
      feed_dict = {inputs: input_np}
      variables.global_variables_initializer().run()
      pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
      self.assertListEqual(list(pre_pool_out.shape), [batch_size, 7, 7, 1024]) 
Example #15
Source File: inception_v3_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def testUnknownImageShape(self):
    ops.reset_default_graph()
    batch_size = 2
    height, width = 299, 299
    num_classes = 1000
    input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
    with self.test_session() as sess:
      inputs = array_ops.placeholder(
          dtypes.float32, shape=(batch_size, None, None, 3))
      logits, end_points = inception_v3.inception_v3(inputs, num_classes)
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes])
      pre_pool = end_points['Mixed_7c']
      feed_dict = {inputs: input_np}
      variables.global_variables_initializer().run()
      pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
      self.assertListEqual(list(pre_pool_out.shape), [batch_size, 8, 8, 2048]) 
Example #16
Source File: resnet_v2_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def testAtrousFullyConvolutionalValues(self):
    """Verify dense feature extraction with atrous convolution."""
    nominal_stride = 32
    for output_stride in [4, 8, 16, 32, None]:
      with arg_scope(resnet_utils.resnet_arg_scope(is_training=False)):
        with ops.Graph().as_default():
          with self.test_session() as sess:
            random_seed.set_random_seed(0)
            inputs = create_test_input(2, 81, 81, 3)
            # Dense feature extraction followed by subsampling.
            output, _ = self._resnet_small(
                inputs, None, global_pool=False, output_stride=output_stride)
            if output_stride is None:
              factor = 1
            else:
              factor = nominal_stride // output_stride
            output = resnet_utils.subsample(output, factor)
            # Make the two networks use the same weights.
            variable_scope.get_variable_scope().reuse_variables()
            # Feature extraction at the nominal network rate.
            expected, _ = self._resnet_small(inputs, None, global_pool=False)
            sess.run(variables.global_variables_initializer())
            self.assertAllClose(
                output.eval(), expected.eval(), atol=1e-4, rtol=1e-4) 
Example #17
Source File: inception_v3_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def testTrainEvalWithReuse(self):
    train_batch_size = 5
    eval_batch_size = 2
    height, width = 150, 150
    num_classes = 1000

    train_inputs = random_ops.random_uniform(
        (train_batch_size, height, width, 3))
    inception_v3.inception_v3(train_inputs, num_classes)
    eval_inputs = random_ops.random_uniform((eval_batch_size, height, width, 3))
    logits, _ = inception_v3.inception_v3(
        eval_inputs, num_classes, is_training=False, reuse=True)
    predictions = math_ops.argmax(logits, 1)

    with self.test_session() as sess:
      sess.run(variables.global_variables_initializer())
      output = sess.run(predictions)
      self.assertEquals(output.shape, (eval_batch_size,)) 
Example #18
Source File: inception_v1_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def testUnknownImageShape(self):
    ops.reset_default_graph()
    batch_size = 2
    height, width = 224, 224
    num_classes = 1000
    input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
    with self.test_session() as sess:
      inputs = array_ops.placeholder(
          dtypes.float32, shape=(batch_size, None, None, 3))
      logits, end_points = inception_v1.inception_v1(inputs, num_classes)
      self.assertTrue(logits.op.name.startswith('InceptionV1/Logits'))
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes])
      pre_pool = end_points['Mixed_5c']
      feed_dict = {inputs: input_np}
      variables.global_variables_initializer().run()
      pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
      self.assertListEqual(list(pre_pool_out.shape), [batch_size, 7, 7, 1024]) 
Example #19
Source File: inception_v1_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def testTrainEvalWithReuse(self):
    train_batch_size = 5
    eval_batch_size = 2
    height, width = 224, 224
    num_classes = 1000

    train_inputs = random_ops.random_uniform(
        (train_batch_size, height, width, 3))
    inception_v1.inception_v1(train_inputs, num_classes)
    eval_inputs = random_ops.random_uniform((eval_batch_size, height, width, 3))
    logits, _ = inception_v1.inception_v1(eval_inputs, num_classes, reuse=True)
    predictions = math_ops.argmax(logits, 1)

    with self.test_session() as sess:
      sess.run(variables.global_variables_initializer())
      output = sess.run(predictions)
      self.assertEquals(output.shape, (eval_batch_size,)) 
Example #20
Source File: evaluation_test.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def testRestoredModelPerformance(self):
    checkpoint_path = os.path.join(self.get_temp_dir(), 'model.ckpt')
    log_dir = os.path.join(self.get_temp_dir(), 'log_dir1/')

    # First, save out the current model to a checkpoint:
    init_op = control_flow_ops.group(variables.global_variables_initializer(),
                                     variables.local_variables_initializer())
    saver = saver_lib.Saver(write_version=saver_pb2.SaverDef.V1)
    with self.test_session() as sess:
      sess.run(init_op)
      saver.save(sess, checkpoint_path)

    # Next, determine the metric to evaluate:
    value_op, update_op = metric_ops.streaming_accuracy(self._predictions,
                                                        self._labels)

    # Run the evaluation and verify the results:
    accuracy_value = evaluation.evaluate_once(
        '', checkpoint_path, log_dir, eval_op=update_op, final_op=value_op)
    self.assertAlmostEqual(accuracy_value, self._expected_accuracy) 
Example #21
Source File: inception_v2_test.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def testUnknownBatchSize(self):
    batch_size = 1
    height, width = 224, 224
    num_classes = 1000

    inputs = array_ops.placeholder(dtypes.float32, (None, height, width, 3))
    logits, _ = inception_v2.inception_v2(inputs, num_classes)
    self.assertTrue(logits.op.name.startswith('InceptionV2/Logits'))
    self.assertListEqual(logits.get_shape().as_list(), [None, num_classes])
    images = random_ops.random_uniform((batch_size, height, width, 3))

    with self.test_session() as sess:
      sess.run(variables.global_variables_initializer())
      output = sess.run(logits, {inputs: images.eval()})
      self.assertEquals(output.shape, (batch_size, num_classes)) 
Example #22
Source File: inception_v3_test.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def testEvaluation(self):
    batch_size = 2
    height, width = 299, 299
    num_classes = 1000

    eval_inputs = random_ops.random_uniform((batch_size, height, width, 3))
    logits, _ = inception_v3.inception_v3(
        eval_inputs, num_classes, is_training=False)
    predictions = math_ops.argmax(logits, 1)

    with self.test_session() as sess:
      sess.run(variables.global_variables_initializer())
      output = sess.run(predictions)
      self.assertEquals(output.shape, (batch_size,)) 
Example #23
Source File: inception_v3_test.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def testUnknownBatchSize(self):
    batch_size = 1
    height, width = 299, 299
    num_classes = 1000

    inputs = array_ops.placeholder(dtypes.float32, (None, height, width, 3))
    logits, _ = inception_v3.inception_v3(inputs, num_classes)
    self.assertTrue(logits.op.name.startswith('InceptionV3/Logits'))
    self.assertListEqual(logits.get_shape().as_list(), [None, num_classes])
    images = random_ops.random_uniform((batch_size, height, width, 3))

    with self.test_session() as sess:
      sess.run(variables.global_variables_initializer())
      output = sess.run(logits, {inputs: images.eval()})
      self.assertEquals(output.shape, (batch_size, num_classes)) 
Example #24
Source File: sample_inputs_op_test.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def testSparse(self):
    sparse_shape = [4, 10]
    sparse_indices = [[0, 0], [0, 4], [0, 9],
                      [1, 0], [1, 7],
                      [2, 0],
                      [3, 1], [3, 4]]
    sparse_values = [3.0, -1.0, 0.5,
                     1.5, 6.0,
                     -2.0,
                     -0.5, 2.0]

    spec_proto = data_ops.TensorForestDataSpec()
    f1 = spec_proto.sparse.add()
    f1.name = 'f1'
    f1.original_type = data_ops.DATA_FLOAT
    f1.size = -1

    spec_proto.dense_features_size = 0
    data_spec = spec_proto.SerializeToString()

    with self.test_session():
      variables.global_variables_initializer().run()
      (indices, feature_updates,
       threshold_updates) = (tensor_forest_ops.sample_inputs(
           [],
           sparse_indices,
           sparse_values,
           sparse_shape, [],
           self.node_map,
           self.leaves,
           self.split_features,
           self.split_thresholds,
           input_spec=data_spec,
           split_initializations_per_input=1,
           split_sampling_random_seed=3))
      self.assertAllEqual([1, 0], indices.eval())
      self.assertAllEqual([[1, 0, 0], [4, 0, -1]], feature_updates.eval())

      self.assertAllEqual([[5., -2., -2.], [-1., 1.5, 0.]],
                          threshold_updates.eval()) 
Example #25
Source File: scatter_add_ndim_op_test.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def test1dim(self):
    input_data = variables.Variable(
        [1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12.])
    indices = [[1], [10]]
    updates = [100., 200.]

    with self.test_session():
      variables.global_variables_initializer().run()
      tensor_forest_ops.scatter_add_ndim(input_data, indices, updates).run()
      self.assertAllEqual(
          [1., 102., 3., 4., 5., 6., 7., 8., 9., 10., 211., 12.],
          input_data.eval()) 
Example #26
Source File: vgg_test.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def testForward(self):
    batch_size = 1
    height, width = 224, 224
    with self.test_session() as sess:
      inputs = random_ops.random_uniform((batch_size, height, width, 3))
      logits, _ = vgg.vgg_16(inputs)
      sess.run(variables.global_variables_initializer())
      output = sess.run(logits)
      self.assertTrue(output.any()) 
Example #27
Source File: vgg_test.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def testForward(self):
    batch_size = 1
    height, width = 224, 224
    with self.test_session() as sess:
      inputs = random_ops.random_uniform((batch_size, height, width, 3))
      logits, _ = vgg.vgg_19(inputs)
      sess.run(variables.global_variables_initializer())
      output = sess.run(logits)
      self.assertTrue(output.any()) 
Example #28
Source File: inception_v2_test.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def testLogitsNotSqueezed(self):
    num_classes = 25
    images = random_ops.random_uniform([1, 224, 224, 3])
    logits, _ = inception_v2.inception_v2(
        images, num_classes=num_classes, spatial_squeeze=False)

    with self.test_session() as sess:
      variables.global_variables_initializer().run()
      logits_out = sess.run(logits)
      self.assertListEqual(list(logits_out.shape), [1, 1, 1, num_classes]) 
Example #29
Source File: inception_v1_test.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def testUnknownBatchSize(self):
    batch_size = 1
    height, width = 224, 224
    num_classes = 1000

    inputs = array_ops.placeholder(dtypes.float32, (None, height, width, 3))
    logits, _ = inception_v1.inception_v1(inputs, num_classes)
    self.assertTrue(logits.op.name.startswith('InceptionV1/Logits'))
    self.assertListEqual(logits.get_shape().as_list(), [None, num_classes])
    images = random_ops.random_uniform((batch_size, height, width, 3))

    with self.test_session() as sess:
      sess.run(variables.global_variables_initializer())
      output = sess.run(logits, {inputs: images.eval()})
      self.assertEquals(output.shape, (batch_size, num_classes)) 
Example #30
Source File: inception_v2_test.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def testEvaluation(self):
    batch_size = 2
    height, width = 224, 224
    num_classes = 1000

    eval_inputs = random_ops.random_uniform((batch_size, height, width, 3))
    logits, _ = inception_v2.inception_v2(
        eval_inputs, num_classes, is_training=False)
    predictions = math_ops.argmax(logits, 1)

    with self.test_session() as sess:
      sess.run(variables.global_variables_initializer())
      output = sess.run(predictions)
      self.assertEquals(output.shape, (batch_size,))