FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Refactor Python imports: layers · codeplaysoftware/tensorflow@be359cd · GitHub

Repository navigation

Commit be359cd

Browse files
authored andcommitted
Refactor Python imports: layers
Change: 141412543
1 parent 7b3f3ab commit be359cd

8 files changed

Lines changed: 595 additions & 492 deletions

File tree

‎tensorflow/python/BUILD‎

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,16 +2313,25 @@ py_tests(
23132313

23142314
py_library(
23152315
name = "layers",
2316-
srcs = glob(
2317-
["layers/*.py"],
2318-
),
2316+
srcs = [
2317+
"layers/__init__.py",
2318+
"layers/base.py",
2319+
"layers/conv_utils.py",
2320+
"layers/convolutional.py",
2321+
"layers/core.py",
2322+
"layers/layers.py",
2323+
"layers/normalization.py",
2324+
"layers/pooling.py",
2325+
],
23192326
srcs_version = "PY2AND3",
23202327
deps = [
23212328
":array_ops",
23222329
":framework",
23232330
":framework_for_generated_wrappers",
23242331
":init_ops",
2332+
":nn",
23252333
":standard_ops",
2334+
":training",
23262335
":util",
23272336
":variable_scope",
23282337
],
@@ -2337,8 +2346,13 @@ py_test(
23372346
main = "layers/base_test.py",
23382347
srcs_version = "PY2AND3",
23392348
deps = [
2349+
":client_testlib",
2350+
":framework_for_generated_wrappers",
2351+
":init_ops",
23402352
":layers",
2341-
"//tensorflow:tensorflow_py",
2353+
":math_ops",
2354+
":random_ops",
2355+
":variable_scope",
23422356
],
23432357
)
23442358

@@ -2351,8 +2365,15 @@ py_test(
23512365
main = "layers/core_test.py",
23522366
srcs_version = "PY2AND3",
23532367
deps = [
2368+
":array_ops",
2369+
":client_testlib",
2370+
":framework_for_generated_wrappers",
23542371
":layers",
2355-
"//tensorflow:tensorflow_py",
2372+
":math_ops",
2373+
":nn_ops",
2374+
":random_ops",
2375+
":variable_scope",
2376+
":variables",
23562377
],
23572378
)
23582379

@@ -2365,8 +2386,12 @@ py_test(
23652386
main = "layers/convolutional_test.py",
23662387
srcs_version = "PY2AND3",
23672388
deps = [
2389+
":client_testlib",
2390+
":framework_for_generated_wrappers",
23682391
":layers",
2369-
"//tensorflow:tensorflow_py",
2392+
":math_ops",
2393+
":nn_ops",
2394+
":random_ops",
23702395
],
23712396
)
23722397

@@ -2379,8 +2404,8 @@ py_test(
23792404
main = "layers/conv_utils_test.py",
23802405
srcs_version = "PY2AND3",
23812406
deps = [
2407+
":client_testlib",
23822408
":layers",
2383-
"//tensorflow:tensorflow_py",
23842409
],
23852410
)
23862411

@@ -2393,8 +2418,9 @@ py_test(
23932418
main = "layers/pooling_test.py",
23942419
srcs_version = "PY2AND3",
23952420
deps = [
2421+
":client_testlib",
23962422
":layers",
2397-
"//tensorflow:tensorflow_py",
2423+
":random_ops",
23982424
],
23992425
)
24002426

@@ -2407,8 +2433,13 @@ py_test(
24072433
main = "layers/normalization_test.py",
24082434
srcs_version = "PY2AND3",
24092435
deps = [
2436+
":array_ops",
2437+
":client_testlib",
2438+
":framework_for_generated_wrappers",
24102439
":layers",
2411-
"//tensorflow:tensorflow_py",
2440+
":math_ops",
2441+
":random_ops",
2442+
":variables",
24122443
],
24132444
)
24142445

‎tensorflow/python/layers/base_test.py‎

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@
1818
from __future__ import division
1919
from __future__ import print_function
2020

21-
import tensorflow as tf
22-
21+
from tensorflow.python.framework import ops
2322
from tensorflow.python.layers import base as base_layers
23+
from tensorflow.python.ops import init_ops
24+
from tensorflow.python.ops import math_ops
25+
from tensorflow.python.ops import random_ops
26+
from tensorflow.python.ops import variable_scope
27+
from tensorflow.python.platform import test
2428

2529

26-
class BaseLayerTest(tf.test.TestCase):
30+
class BaseLayerTest(test.TestCase):
2731

2832
def testLayerProperties(self):
2933
layer = base_layers._Layer(name='my_layer')
@@ -42,31 +46,34 @@ def testAddWeight(self):
4246
layer = base_layers._Layer(name='my_layer')
4347

4448
# Test basic variable creation.
45-
variable = layer._add_variable('my_var', [2, 2],
46-
initializer=tf.zeros_initializer)
49+
variable = layer._add_variable(
50+
'my_var', [2, 2], initializer=init_ops.zeros_initializer)
4751
self.assertEqual(variable.name, 'my_var:0')
4852
self.assertListEqual(layer.variables, [variable])
4953
self.assertListEqual(layer.trainable_variables, [variable])
5054
self.assertListEqual(layer.non_trainable_variables, [])
51-
self.assertListEqual(layer.variables,
52-
tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES))
55+
self.assertListEqual(
56+
layer.variables,
57+
ops.get_collection(ops.GraphKeys.TRAINABLE_VARIABLES))
5358

5459
# Test non-trainable variable creation.
5560
# layer._add_variable should work even outside `build` and `call`.
56-
variable_2 = layer._add_variable('non_trainable_var', [2, 2],
57-
initializer=tf.zeros_initializer,
58-
trainable=False)
61+
variable_2 = layer._add_variable(
62+
'non_trainable_var', [2, 2],
63+
initializer=init_ops.zeros_initializer,
64+
trainable=False)
5965
self.assertListEqual(layer.variables, [variable, variable_2])
6066
self.assertListEqual(layer.trainable_variables, [variable])
6167
self.assertListEqual(layer.non_trainable_variables, [variable_2])
6268
self.assertEqual(
63-
len(tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES)), 1)
69+
len(ops.get_collection(ops.GraphKeys.TRAINABLE_VARIABLES)), 1)
6470

6571
# Test with regularizer.
66-
regularizer = lambda x: tf.reduce_sum(x) * 1e-3
67-
variable = layer._add_variable('reg_var', [2, 2],
68-
initializer=tf.zeros_initializer,
69-
regularizer=regularizer)
72+
regularizer = lambda x: math_ops.reduce_sum(x) * 1e-3
73+
variable = layer._add_variable(
74+
'reg_var', [2, 2],
75+
initializer=init_ops.zeros_initializer,
76+
regularizer=regularizer)
7077
self.assertEqual(len(layer.losses), 1)
7178

7279
def testGetVariable(self):
@@ -77,14 +84,14 @@ def testGetVariable(self):
7784
class MyLayer(base_layers._Layer):
7885

7986
def build(self, input_shape):
80-
self.my_var = tf.get_variable('my_var', [2, 2],
81-
initializer=tf.zeros_initializer)
87+
self.my_var = variable_scope.get_variable(
88+
'my_var', [2, 2], initializer=init_ops.zeros_initializer)
8289

8390
def call(self, inputs):
8491
return inputs
8592

8693
layer = MyLayer(name='my_layer')
87-
inputs = tf.random_uniform((5,), seed=1)
94+
inputs = random_ops.random_uniform((5,), seed=1)
8895
_ = layer.apply(inputs)
8996
self.assertListEqual(layer.variables, [layer.my_var])
9097

@@ -93,10 +100,10 @@ def testCall(self):
93100
class MyLayer(base_layers._Layer):
94101

95102
def call(self, inputs):
96-
return tf.square(inputs)
103+
return math_ops.square(inputs)
97104

98105
layer = MyLayer(name='my_layer')
99-
inputs = tf.random_uniform((5,), seed=1)
106+
inputs = random_ops.random_uniform((5,), seed=1)
100107
outputs = layer.apply(inputs)
101108
self.assertEqual(layer.built, True)
102109
self.assertEqual(outputs.op.name, 'my_layer/Square')
@@ -111,21 +118,21 @@ def testNaming(self):
111118
my_layer1 = base_layers._Layer(name='my_layer')
112119
self.assertEqual(my_layer1.name, 'my_layer_1')
113120
# New graph has fully orthogonal names.
114-
with tf.Graph().as_default():
121+
with ops.Graph().as_default():
115122
my_layer_other_graph = base_layers._Layer(name='my_layer')
116123
self.assertEqual(my_layer_other_graph.name, 'my_layer')
117124
my_layer2 = base_layers._Layer(name='my_layer')
118125
self.assertEqual(my_layer2.name, 'my_layer_2')
119126
# Name scope shouldn't affect names.
120-
with tf.name_scope('some_name_scope'):
127+
with ops.name_scope('some_name_scope'):
121128
default_layer2 = base_layers._Layer()
122129
self.assertEqual(default_layer2.name, 'private__layer_2')
123130
my_layer3 = base_layers._Layer(name='my_layer')
124131
self.assertEqual(my_layer3.name, 'my_layer_3')
125132
other_layer = base_layers._Layer(name='other_layer')
126133
self.assertEqual(other_layer.name, 'other_layer')
127134
# Variable scope gets added to names.
128-
with tf.variable_scope('var_scope'):
135+
with variable_scope.variable_scope('var_scope'):
129136
default_layer_scoped = base_layers._Layer()
130137
self.assertEqual(default_layer_scoped.name, 'var_scope/private__layer')
131138
my_layer_scoped = base_layers._Layer(name='my_layer')
@@ -135,4 +142,4 @@ def testNaming(self):
135142

136143

137144
if __name__ == '__main__':
138-
tf.test.main()
145+
test.main()

‎tensorflow/python/layers/conv_utils_test.py‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
from __future__ import division
1919
from __future__ import print_function
2020

21-
import tensorflow as tf
22-
2321
from tensorflow.python.layers import conv_utils
22+
from tensorflow.python.platform import test
2423

2524

26-
class ConvUtilsTest(tf.test.TestCase):
25+
class ConvUtilsTest(test.TestCase):
2726

2827
def testConvertDataFormat(self):
2928
self.assertEqual(
@@ -39,9 +38,11 @@ def testConvertDataFormat(self):
3938

4039
def testNormalizeTuple(self):
4140
self.assertEqual(
42-
conv_utils.normalize_tuple(2, n=3, name='strides'), (2, 2, 2))
41+
conv_utils.normalize_tuple(
42+
2, n=3, name='strides'), (2, 2, 2))
4343
self.assertEqual(
44-
conv_utils.normalize_tuple((2, 1, 2), n=3, name='strides'), (2, 1, 2))
44+
conv_utils.normalize_tuple(
45+
(2, 1, 2), n=3, name='strides'), (2, 1, 2))
4546

4647
with self.assertRaises(ValueError):
4748
conv_utils.normalize_tuple((2, 1), n=3, name='strides')
@@ -59,14 +60,12 @@ def testNormalizeDataFormat(self):
5960
conv_utils.normalize_data_format('invalid')
6061

6162
def testNormalizePadding(self):
62-
self.assertEqual(
63-
conv_utils.normalize_padding('SAME'), 'same')
64-
self.assertEqual(
65-
conv_utils.normalize_padding('VALID'), 'valid')
63+
self.assertEqual(conv_utils.normalize_padding('SAME'), 'same')
64+
self.assertEqual(conv_utils.normalize_padding('VALID'), 'valid')
6665

6766
with self.assertRaises(ValueError):
6867
conv_utils.normalize_padding('invalid')
6968

7069

7170
if __name__ == '__main__':
72-
tf.test.main()
71+
test.main()

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL