当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow.random_uniform方法代码示例

本文整理汇总了Python中tensorflow.random_uniform方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.random_uniform方法的具体用法?Python tensorflow.random_uniform怎么用?Python tensorflow.random_uniform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tensorflow的用法示例。


在下文中一共展示了tensorflow.random_uniform方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: structure

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_uniform [as 别名]
def structure(self, input_tensor):
        """
        Args:
            input_tensor: NHWC
        """
        rnd = tf.random_uniform((), 135, 160, dtype=tf.int32)
        rescaled = tf.image.resize_images(
            input_tensor, [rnd, rnd], method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)
        h_rem = 160 - rnd
        w_rem = 160 - rnd
        pad_left = tf.random_uniform((), 0, w_rem, dtype=tf.int32)
        pad_right = w_rem - pad_left
        pad_top = tf.random_uniform((), 0, h_rem, dtype=tf.int32)
        pad_bottom = h_rem - pad_top
        padded = tf.pad(rescaled, [[0, 0], [pad_top, pad_bottom], [
                        pad_left, pad_right], [0, 0]])
        padded.set_shape((input_tensor.shape[0], 160, 160, 3))
        output = tf.cond(tf.random_uniform(shape=[1])[0] < tf.constant(0.9),
                         lambda: padded, lambda: input_tensor)
        return output 
开发者ID:ppwwyyxx,项目名称:Adversarial-Face-Attack,代码行数:22,代码来源:face_attack.py

示例2: set_input_shape

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_uniform [as 别名]
def set_input_shape(self, input_shape):
        batch_size, dim = input_shape
        self.input_shape = [batch_size, dim]
        self.output_shape = [batch_size, self.num_hid]
        if self.init_mode == "norm":
            init = tf.random_normal([dim, self.num_hid], dtype=tf.float32)
            init = init / tf.sqrt(1e-7 + tf.reduce_sum(tf.square(init), axis=0,
                                                       keep_dims=True))
            init = init * self.init_scale
        elif self.init_mode == "uniform_unit_scaling":
            scale = np.sqrt(3. / dim)
            init = tf.random_uniform([dim, self.num_hid], dtype=tf.float32,
                                     minval=-scale, maxval=scale)
        else:
            raise ValueError(self.init_mode)
        self.W = PV(init)
        if self.use_bias:
            self.b = PV((np.zeros((self.num_hid,))
                         + self.init_b).astype('float32')) 
开发者ID:StephanZheng,项目名称:neural-fingerprinting,代码行数:21,代码来源:picklable_model.py

示例3: testEndPoints

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_uniform [as 别名]
def testEndPoints(self):
    batch_size = 5
    height, width = 231, 231
    num_classes = 1000
    with self.test_session():
      inputs = tf.random_uniform((batch_size, height, width, 3))
      _, end_points = overfeat.overfeat(inputs, num_classes)
      expected_names = ['overfeat/conv1',
                        'overfeat/pool1',
                        'overfeat/conv2',
                        'overfeat/pool2',
                        'overfeat/conv3',
                        'overfeat/conv4',
                        'overfeat/conv5',
                        'overfeat/pool5',
                        'overfeat/fc6',
                        'overfeat/fc7',
                        'overfeat/fc8'
                       ]
      self.assertSetEqual(set(end_points.keys()), set(expected_names)) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:22,代码来源:overfeat_test.py

示例4: testEndPoints

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_uniform [as 别名]
def testEndPoints(self):
    batch_size = 5
    height, width = 224, 224
    num_classes = 1000
    with self.test_session():
      inputs = tf.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)) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:22,代码来源:alexnet_test.py

示例5: testTrainEvalWithReuse

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_uniform [as 别名]
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.test_session():
      train_inputs = tf.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])
      tf.get_variable_scope().reuse_variables()
      eval_inputs = tf.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 = tf.reduce_mean(logits, [1, 2])
      predictions = tf.argmax(logits, 1)
      self.assertEquals(predictions.get_shape().as_list(), [eval_batch_size]) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:24,代码来源:alexnet_test.py

示例6: testEndPoints

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_uniform [as 别名]
def testEndPoints(self):
    batch_size = 5
    height, width = 224, 224
    num_classes = 1000
    with self.test_session():
      inputs = tf.random_uniform((batch_size, height, width, 3))
      _, end_points = vgg.vgg_a(inputs, num_classes)
      expected_names = ['vgg_a/conv1/conv1_1',
                        'vgg_a/pool1',
                        'vgg_a/conv2/conv2_1',
                        'vgg_a/pool2',
                        'vgg_a/conv3/conv3_1',
                        'vgg_a/conv3/conv3_2',
                        'vgg_a/pool3',
                        'vgg_a/conv4/conv4_1',
                        'vgg_a/conv4/conv4_2',
                        'vgg_a/pool4',
                        'vgg_a/conv5/conv5_1',
                        'vgg_a/conv5/conv5_2',
                        'vgg_a/pool5',
                        'vgg_a/fc6',
                        'vgg_a/fc7',
                        'vgg_a/fc8'
                       ]
      self.assertSetEqual(set(end_points.keys()), set(expected_names)) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:27,代码来源:vgg_test.py

示例7: testTrainEvalWithReuse

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_uniform [as 别名]
def testTrainEvalWithReuse(self):
    train_batch_size = 2
    eval_batch_size = 1
    train_height, train_width = 224, 224
    eval_height, eval_width = 256, 256
    num_classes = 1000
    with self.test_session():
      train_inputs = tf.random_uniform(
          (train_batch_size, train_height, train_width, 3))
      logits, _ = vgg.vgg_a(train_inputs)
      self.assertListEqual(logits.get_shape().as_list(),
                           [train_batch_size, num_classes])
      tf.get_variable_scope().reuse_variables()
      eval_inputs = tf.random_uniform(
          (eval_batch_size, eval_height, eval_width, 3))
      logits, _ = vgg.vgg_a(eval_inputs, is_training=False,
                            spatial_squeeze=False)
      self.assertListEqual(logits.get_shape().as_list(),
                           [eval_batch_size, 2, 2, num_classes])
      logits = tf.reduce_mean(logits, [1, 2])
      predictions = tf.argmax(logits, 1)
      self.assertEquals(predictions.get_shape().as_list(), [eval_batch_size]) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:24,代码来源:vgg_test.py

示例8: testBuildLogits

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_uniform [as 别名]
def testBuildLogits(self):
    batch_size = 5
    height, width = 299, 299
    num_classes = 1000
    with self.test_session():
      inputs = tf.random_uniform((batch_size, height, width, 3))
      logits, endpoints = inception.inception_resnet_v2(inputs, num_classes)
      self.assertTrue('AuxLogits' in endpoints)
      auxlogits = endpoints['AuxLogits']
      self.assertTrue(
          auxlogits.op.name.startswith('InceptionResnetV2/AuxLogits'))
      self.assertListEqual(auxlogits.get_shape().as_list(),
                           [batch_size, num_classes])
      self.assertTrue(logits.op.name.startswith('InceptionResnetV2/Logits'))
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes]) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:18,代码来源:inception_resnet_v2_test.py

示例9: testBuildEndPoints

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_uniform [as 别名]
def testBuildEndPoints(self):
    batch_size = 5
    height, width = 299, 299
    num_classes = 1000
    with self.test_session():
      inputs = tf.random_uniform((batch_size, height, width, 3))
      _, end_points = inception.inception_resnet_v2(inputs, num_classes)
      self.assertTrue('Logits' in end_points)
      logits = end_points['Logits']
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes])
      self.assertTrue('AuxLogits' in end_points)
      aux_logits = end_points['AuxLogits']
      self.assertListEqual(aux_logits.get_shape().as_list(),
                           [batch_size, num_classes])
      pre_pool = end_points['Conv2d_7b_1x1']
      self.assertListEqual(pre_pool.get_shape().as_list(),
                           [batch_size, 8, 8, 1536]) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:20,代码来源:inception_resnet_v2_test.py

示例10: testBuildAndCheckAllEndPointsUptoPreAuxLogits

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_uniform [as 别名]
def testBuildAndCheckAllEndPointsUptoPreAuxLogits(self):
    batch_size = 5
    height, width = 299, 299

    inputs = tf.random_uniform((batch_size, height, width, 3))
    _, end_points = inception.inception_resnet_v2_base(
        inputs, final_endpoint='PreAuxLogits')
    endpoints_shapes = {'Conv2d_1a_3x3': [5, 149, 149, 32],
                        'Conv2d_2a_3x3': [5, 147, 147, 32],
                        'Conv2d_2b_3x3': [5, 147, 147, 64],
                        'MaxPool_3a_3x3': [5, 73, 73, 64],
                        'Conv2d_3b_1x1': [5, 73, 73, 80],
                        'Conv2d_4a_3x3': [5, 71, 71, 192],
                        'MaxPool_5a_3x3': [5, 35, 35, 192],
                        'Mixed_5b': [5, 35, 35, 320],
                        'Mixed_6a': [5, 17, 17, 1088],
                        'PreAuxLogits': [5, 17, 17, 1088]
                       }

    self.assertItemsEqual(endpoints_shapes.keys(), end_points.keys())
    for endpoint_name in endpoints_shapes:
      expected_shape = endpoints_shapes[endpoint_name]
      self.assertTrue(endpoint_name in end_points)
      self.assertListEqual(end_points[endpoint_name].get_shape().as_list(),
                           expected_shape) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:27,代码来源:inception_resnet_v2_test.py

示例11: testBuildAndCheckAllEndPointsUptoPreAuxLogitsWithAlignedFeatureMaps

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_uniform [as 别名]
def testBuildAndCheckAllEndPointsUptoPreAuxLogitsWithAlignedFeatureMaps(self):
    batch_size = 5
    height, width = 299, 299

    inputs = tf.random_uniform((batch_size, height, width, 3))
    _, end_points = inception.inception_resnet_v2_base(
        inputs, final_endpoint='PreAuxLogits', align_feature_maps=True)
    endpoints_shapes = {'Conv2d_1a_3x3': [5, 150, 150, 32],
                        'Conv2d_2a_3x3': [5, 150, 150, 32],
                        'Conv2d_2b_3x3': [5, 150, 150, 64],
                        'MaxPool_3a_3x3': [5, 75, 75, 64],
                        'Conv2d_3b_1x1': [5, 75, 75, 80],
                        'Conv2d_4a_3x3': [5, 75, 75, 192],
                        'MaxPool_5a_3x3': [5, 38, 38, 192],
                        'Mixed_5b': [5, 38, 38, 320],
                        'Mixed_6a': [5, 19, 19, 1088],
                        'PreAuxLogits': [5, 19, 19, 1088]
                       }

    self.assertItemsEqual(endpoints_shapes.keys(), end_points.keys())
    for endpoint_name in endpoints_shapes:
      expected_shape = endpoints_shapes[endpoint_name]
      self.assertTrue(endpoint_name in end_points)
      self.assertListEqual(end_points[endpoint_name].get_shape().as_list(),
                           expected_shape) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:27,代码来源:inception_resnet_v2_test.py

示例12: testBuildAndCheckAllEndPointsUptoPreAuxLogitsWithOutputStrideEight

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_uniform [as 别名]
def testBuildAndCheckAllEndPointsUptoPreAuxLogitsWithOutputStrideEight(self):
    batch_size = 5
    height, width = 299, 299

    inputs = tf.random_uniform((batch_size, height, width, 3))
    _, end_points = inception.inception_resnet_v2_base(
        inputs, final_endpoint='PreAuxLogits', output_stride=8)
    endpoints_shapes = {'Conv2d_1a_3x3': [5, 149, 149, 32],
                        'Conv2d_2a_3x3': [5, 147, 147, 32],
                        'Conv2d_2b_3x3': [5, 147, 147, 64],
                        'MaxPool_3a_3x3': [5, 73, 73, 64],
                        'Conv2d_3b_1x1': [5, 73, 73, 80],
                        'Conv2d_4a_3x3': [5, 71, 71, 192],
                        'MaxPool_5a_3x3': [5, 35, 35, 192],
                        'Mixed_5b': [5, 35, 35, 320],
                        'Mixed_6a': [5, 33, 33, 1088],
                        'PreAuxLogits': [5, 33, 33, 1088]
                       }

    self.assertItemsEqual(endpoints_shapes.keys(), end_points.keys())
    for endpoint_name in endpoints_shapes:
      expected_shape = endpoints_shapes[endpoint_name]
      self.assertTrue(endpoint_name in end_points)
      self.assertListEqual(end_points[endpoint_name].get_shape().as_list(),
                           expected_shape) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:27,代码来源:inception_resnet_v2_test.py

示例13: testTrainEvalWithReuse

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_uniform [as 别名]
def testTrainEvalWithReuse(self):
    train_batch_size = 5
    eval_batch_size = 2
    height, width = 150, 150
    num_classes = 1000
    with self.test_session() as sess:
      train_inputs = tf.random_uniform((train_batch_size, height, width, 3))
      inception.inception_resnet_v2(train_inputs, num_classes)
      eval_inputs = tf.random_uniform((eval_batch_size, height, width, 3))
      logits, _ = inception.inception_resnet_v2(eval_inputs,
                                                num_classes,
                                                is_training=False,
                                                reuse=True)
      predictions = tf.argmax(logits, 1)
      sess.run(tf.global_variables_initializer())
      output = sess.run(predictions)
      self.assertEquals(output.shape, (eval_batch_size,)) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:19,代码来源:inception_resnet_v2_test.py

示例14: testBuildBaseNetwork

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_uniform [as 别名]
def testBuildBaseNetwork(self):
    batch_size = 5
    height, width = 224, 224

    inputs = tf.random_uniform((batch_size, height, width, 3))
    net, end_points = mobilenet_v1.mobilenet_v1_base(inputs)
    self.assertTrue(net.op.name.startswith('MobilenetV1/Conv2d_13'))
    self.assertListEqual(net.get_shape().as_list(),
                         [batch_size, 7, 7, 1024])
    expected_endpoints = ['Conv2d_0',
                          'Conv2d_1_depthwise', 'Conv2d_1_pointwise',
                          'Conv2d_2_depthwise', 'Conv2d_2_pointwise',
                          'Conv2d_3_depthwise', 'Conv2d_3_pointwise',
                          'Conv2d_4_depthwise', 'Conv2d_4_pointwise',
                          'Conv2d_5_depthwise', 'Conv2d_5_pointwise',
                          'Conv2d_6_depthwise', 'Conv2d_6_pointwise',
                          'Conv2d_7_depthwise', 'Conv2d_7_pointwise',
                          'Conv2d_8_depthwise', 'Conv2d_8_pointwise',
                          'Conv2d_9_depthwise', 'Conv2d_9_pointwise',
                          'Conv2d_10_depthwise', 'Conv2d_10_pointwise',
                          'Conv2d_11_depthwise', 'Conv2d_11_pointwise',
                          'Conv2d_12_depthwise', 'Conv2d_12_pointwise',
                          'Conv2d_13_depthwise', 'Conv2d_13_pointwise']
    self.assertItemsEqual(end_points.keys(), expected_endpoints) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:26,代码来源:mobilenet_v1_test.py

示例15: testBuildOnlyUptoFinalEndpoint

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import random_uniform [as 别名]
def testBuildOnlyUptoFinalEndpoint(self):
    batch_size = 5
    height, width = 224, 224
    endpoints = ['Conv2d_0',
                 'Conv2d_1_depthwise', 'Conv2d_1_pointwise',
                 'Conv2d_2_depthwise', 'Conv2d_2_pointwise',
                 'Conv2d_3_depthwise', 'Conv2d_3_pointwise',
                 'Conv2d_4_depthwise', 'Conv2d_4_pointwise',
                 'Conv2d_5_depthwise', 'Conv2d_5_pointwise',
                 'Conv2d_6_depthwise', 'Conv2d_6_pointwise',
                 'Conv2d_7_depthwise', 'Conv2d_7_pointwise',
                 'Conv2d_8_depthwise', 'Conv2d_8_pointwise',
                 'Conv2d_9_depthwise', 'Conv2d_9_pointwise',
                 'Conv2d_10_depthwise', 'Conv2d_10_pointwise',
                 'Conv2d_11_depthwise', 'Conv2d_11_pointwise',
                 'Conv2d_12_depthwise', 'Conv2d_12_pointwise',
                 'Conv2d_13_depthwise', 'Conv2d_13_pointwise']
    for index, endpoint in enumerate(endpoints):
      with tf.Graph().as_default():
        inputs = tf.random_uniform((batch_size, height, width, 3))
        out_tensor, end_points = mobilenet_v1.mobilenet_v1_base(
            inputs, final_endpoint=endpoint)
        self.assertTrue(out_tensor.op.name.startswith(
            'MobilenetV1/' + endpoint))
        self.assertItemsEqual(endpoints[:index+1], end_points) 
开发者ID:ringringyi,项目名称:DOTA_models,代码行数:27,代码来源:mobilenet_v1_test.py


注:本文中的tensorflow.random_uniform方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。