aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Malcolm Reynolds <mareynolds@google.com>2016-12-21 11:14:45 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-12-21 11:28:32 -0800
commit9248f9956023ce70c6516be5cc76e4ccc9351bcf (patch)
tree3c99245c0465672946398af6a3134b3e774fabd9
parent1583f18633925dfe414f4e122eb7dafa9c07d56e (diff)
Replace the Template .var_scope property with .variable_scope
This brings the codebase in closer alignment with the style guide: "... and do not abbreviate by deleting letters within a word." Change: 142681857
-rw-r--r--tensorflow/python/kernel_tests/template_test.py64
-rw-r--r--tensorflow/python/ops/template.py23
2 files changed, 51 insertions, 36 deletions
diff --git a/tensorflow/python/kernel_tests/template_test.py b/tensorflow/python/kernel_tests/template_test.py
index 56b5305391..84f46c6278 100644
--- a/tensorflow/python/kernel_tests/template_test.py
+++ b/tensorflow/python/kernel_tests/template_test.py
@@ -31,12 +31,12 @@ from tensorflow.python.platform import test
from tensorflow.python.training import gradient_descent
-def var_scoped_function():
+def variable_scoped_function():
return variable_scope.get_variable(
"dummy", shape=[1], initializer=init_ops.zeros_initializer())
-def internally_var_scoped_function(scope_name):
+def internally_variable_scoped_function(scope_name):
with variable_scope.variable_scope(scope_name):
return variable_scope.get_variable(
"dummy", shape=[1], initializer=init_ops.zeros_initializer())
@@ -99,8 +99,8 @@ class TemplateTest(test.TestCase):
self.assertNotEqual(len(first), len(result))
def test_template_with_name(self):
- tmpl1 = template.make_template("s1", var_scoped_function)
- tmpl2 = template.make_template("s1", var_scoped_function)
+ tmpl1 = template.make_template("s1", variable_scoped_function)
+ tmpl2 = template.make_template("s1", variable_scoped_function)
v1 = tmpl1()
v2 = tmpl1()
@@ -111,19 +111,23 @@ class TemplateTest(test.TestCase):
self.assertEqual("s1_1/dummy:0", v3.name)
def test_unique_name_raise_error(self):
- tmpl1 = template.make_template("_", var_scoped_function, unique_name_="s1")
+ tmpl1 = template.make_template(
+ "_", variable_scoped_function, unique_name_="s1")
tmpl1()
- tmpl2 = template.make_template("_", var_scoped_function, unique_name_="s1")
+ tmpl2 = template.make_template(
+ "_", variable_scoped_function, unique_name_="s1")
with self.assertRaises(ValueError):
tmpl2()
def test_unique_name_and_reuse(self):
- tmpl1 = template.make_template("_", var_scoped_function, unique_name_="s1")
+ tmpl1 = template.make_template(
+ "_", variable_scoped_function, unique_name_="s1")
v1 = tmpl1()
v2 = tmpl1()
variable_scope.get_variable_scope().reuse_variables()
- tmpl2 = template.make_template("_", var_scoped_function, unique_name_="s1")
+ tmpl2 = template.make_template(
+ "_", variable_scoped_function, unique_name_="s1")
v3 = tmpl2()
self.assertEqual(v1, v2)
@@ -131,8 +135,8 @@ class TemplateTest(test.TestCase):
self.assertEqual("s1/dummy:0", v1.name)
def test_template_in_scope(self):
- tmpl1 = template.make_template("s1", var_scoped_function)
- tmpl2 = template.make_template("s1", var_scoped_function)
+ tmpl1 = template.make_template("s1", variable_scoped_function)
+ tmpl2 = template.make_template("s1", variable_scoped_function)
with variable_scope.variable_scope("scope"):
v1 = tmpl1()
@@ -147,8 +151,8 @@ class TemplateTest(test.TestCase):
self.assertEqual("scope/s1_1/dummy:0", v3.name)
def test_template_with_internal_reuse(self):
- tmpl1 = template.make_template("s1", internally_var_scoped_function)
- tmpl2 = template.make_template("s1", internally_var_scoped_function)
+ tmpl1 = template.make_template("s1", internally_variable_scoped_function)
+ tmpl2 = template.make_template("s1", internally_variable_scoped_function)
v1 = tmpl1("test")
v2 = tmpl1("test")
@@ -163,14 +167,14 @@ class TemplateTest(test.TestCase):
def test_template_without_name(self):
with self.assertRaises(ValueError):
- template.make_template(None, var_scoped_function)
+ template.make_template(None, variable_scoped_function)
def test_make_template(self):
# Test both that we can call it with positional and keywords.
tmpl1 = template.make_template(
- "s1", internally_var_scoped_function, scope_name="test")
+ "s1", internally_variable_scoped_function, scope_name="test")
tmpl2 = template.make_template(
- "s1", internally_var_scoped_function, scope_name="test")
+ "s1", internally_variable_scoped_function, scope_name="test")
v1 = tmpl1()
v2 = tmpl1()
@@ -216,8 +220,8 @@ class TemplateTest(test.TestCase):
def test_nested_templates(self):
def nested_template():
- nested1 = template.make_template("nested", var_scoped_function)
- nested2 = template.make_template("nested", var_scoped_function)
+ nested1 = template.make_template("nested", variable_scoped_function)
+ nested2 = template.make_template("nested", variable_scoped_function)
v1 = nested1()
v2 = nested2()
self.assertNotEqual(v1, v2)
@@ -239,10 +243,12 @@ class TemplateTest(test.TestCase):
# capture the scope the first time it is called, and make_immediate_template
# should capture the scope at construction time.
with variable_scope.variable_scope("ctor_scope"):
- tmpl_immed = template.make_template("a", var_scoped_function,
- True) # create scope here
+ # Create scope here:
+ tmpl_immed = template.make_template("a", variable_scoped_function,
+ True)
+ # default: create scope at __call__
tmpl_defer = template.make_template(
- "b", var_scoped_function, False) # default: create scope at __call__
+ "b", variable_scoped_function, False)
with variable_scope.variable_scope("call_scope"):
inner_imm_var = tmpl_immed()
inner_defer_var = tmpl_defer()
@@ -262,23 +268,23 @@ class TemplateTest(test.TestCase):
# to having been made unique by variable_scope.
with variable_scope.variable_scope("foo"):
# Create two templates with the same name, ensure scopes are made unique.
- ta = template.make_template("bar", var_scoped_function, True)
- tb = template.make_template("bar", var_scoped_function, True)
+ ta = template.make_template("bar", variable_scoped_function, True)
+ tb = template.make_template("bar", variable_scoped_function, True)
# Ensure we can get the scopes before either template is actually called.
- self.assertEqual(ta.var_scope.name, "foo/bar")
- self.assertEqual(tb.var_scope.name, "foo/bar_1")
+ self.assertEqual(ta.variable_scope.name, "foo/bar")
+ self.assertEqual(tb.variable_scope.name, "foo/bar_1")
with variable_scope.variable_scope("foo_2"):
# Create a template which defers scope creation.
- tc = template.make_template("blah", var_scoped_function, False)
+ tc = template.make_template("blah", variable_scoped_function, False)
# Before we call the template, the scope property will be set to None.
- self.assertEqual(tc.var_scope, None)
+ self.assertEqual(tc.variable_scope, None)
tc()
# Template is called at the top level, so there is no preceding "foo_2".
- self.assertEqual(tc.var_scope.name, "blah")
+ self.assertEqual(tc.variable_scope.name, "blah")
def test_custom_getter(self):
# Custom getter that maintains call count and forwards to true getter
@@ -291,7 +297,7 @@ class TemplateTest(test.TestCase):
# Test that custom getter is called both when variables are created and
# subsequently accessed
tmpl1 = template.make_template(
- "s1", var_scoped_function, custom_getter_=custom_getter)
+ "s1", variable_scoped_function, custom_getter_=custom_getter)
self.assertEqual(custom_getter_count[0], 0)
tmpl1()
self.assertEqual(custom_getter_count[0], 1)
@@ -303,7 +309,7 @@ class TemplateTest(test.TestCase):
custom_getter_count[0] = 0
tmpl2 = template.make_template(
"s2",
- var_scoped_function,
+ variable_scoped_function,
custom_getter_=custom_getter,
create_scope_now_=True)
self.assertEqual(custom_getter_count[0], 0)
diff --git a/tensorflow/python/ops/template.py b/tensorflow/python/ops/template.py
index e600478b42..c9fbb854f0 100644
--- a/tensorflow/python/ops/template.py
+++ b/tensorflow/python/ops/template.py
@@ -24,6 +24,7 @@ import traceback
from tensorflow.python.framework import ops
from tensorflow.python.ops import variable_scope
from tensorflow.python.platform import tf_logging as logging
+from tensorflow.python.util.deprecation import deprecated
__all__ = ["make_template"]
@@ -199,9 +200,9 @@ class Template(object):
with variable_scope.variable_scope(
self._unique_name, self._name,
custom_getter=self._custom_getter) as vs:
- self._var_scope = vs
+ self._variable_scope = vs
else:
- self._var_scope = None
+ self._variable_scope = None
# This variable keeps track of whether the template has been called yet,
# which is not the same as whether the scope has been created.
self._variables_created = False
@@ -251,18 +252,18 @@ class Template(object):
raise
def __call__(self, *args, **kwargs):
- if self._var_scope:
+ if self._variable_scope:
if self._variables_created:
# This is not the first visit to __call__, so variables have already
# been created, and we want to reuse them.
- with variable_scope.variable_scope(self._var_scope, reuse=True):
+ with variable_scope.variable_scope(self._variable_scope, reuse=True):
return self._call_func(args, kwargs, check_for_new_variables=True)
else:
# This is the first visit to __call__, but the scope has already been
# created in the constructor. Set _variables_created so that subsequent
# calls take the if branch above.
self._variables_created = True
- with variable_scope.variable_scope(self._var_scope):
+ with variable_scope.variable_scope(self._variable_scope):
return self._call_func(args, kwargs, check_for_new_variables=False)
else:
# The scope was not created at construction time, so create it here.
@@ -271,10 +272,18 @@ class Template(object):
with variable_scope.variable_scope(
self._unique_name, self._name,
custom_getter=self._custom_getter) as vs:
- self._var_scope = vs
+ self._variable_scope = vs
return self._call_func(args, kwargs, check_for_new_variables=False)
@property
+ def variable_scope(self):
+ """Returns the variable scope object created by this Template."""
+ return self._variable_scope
+
+ @property
+ @deprecated(
+ "2017-02-21", "The .var_scope property is deprecated. Please change your "
+ "code to use the .variable_scope property")
def var_scope(self):
"""Returns the variable scope object created by this Template."""
- return self._var_scope
+ return self._variable_scope