Skip to content

Commit 03e6f1f

Browse files
committed
update
1 parent 0363515 commit 03e6f1f

File tree

1 file changed

+14
-53
lines changed

1 file changed

+14
-53
lines changed

tensorgraph/layers/template.py

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,6 @@
22
import tensorflow as tf
33

44

5-
# def init_name_scope(self, func):
6-
# def decorated(obj, *args, **kwargs):
7-
# with tf.name_scope(self.__class__.__name__) as self.scope:
8-
# return func(self, *args, **kwargs)
9-
# return decorated
10-
#
11-
# def train_name_scope(func):
12-
# def decorated(self, *args, **kwargs):
13-
# with tf.name_scope(self.scope):
14-
# with tf.name_scope('train'):
15-
# return func(self, *args, **kwargs)
16-
# return decorated
17-
#
18-
# def test_name_scope(func):
19-
# def decorated(self, *args, **kwargs):
20-
# with tf.name_scope(self.scope):
21-
# with tf.name_scope('test'):
22-
# return func(self, *args, **kwargs)
23-
# return decorated
24-
#
25-
26-
# class init_name_scope(object):
27-
# def __init__(self, fun):
28-
# self.func = fun
29-
# def __call__(self, *args, **kwargs):
30-
# with tf.name_scope(self.__class__.__name__) as self.scope:
31-
# self.func(*args, **kwargs)
32-
#
33-
#
34-
# class test_name_scope(object):
35-
# def __init__(self, fun):
36-
# self.func = fun
37-
# def __call__(self, *args, **kwargs):
38-
# with tf.name_scope(self.scope):
39-
# with tf.name_scope('test'):
40-
# self.func(*args, **kwargs)
41-
#
42-
#
43-
# class train_name_scope(object):
44-
# def __init__(self, fun):
45-
# self.func = fun
46-
# def __call__(self, *args, **kwargs):
47-
# with tf.name_scope(self.scope):
48-
# with tf.name_scope('train'):
49-
# self.func(*args, **kwargs)
50-
51-
525
class ScopeDeco(object):
536

547
@classmethod
@@ -61,17 +14,25 @@ def decorated(self, *args, **kwargs):
6114
@classmethod
6215
def train_name_scope(cls, func):
6316
def decorated(self, *args, **kwargs):
64-
with tf.name_scope(self.scope):
65-
with tf.name_scope('train'):
66-
return func(self, *args, **kwargs)
17+
if hasattr(self, 'scope'):
18+
with tf.name_scope(self.scope):
19+
with tf.name_scope('train'):
20+
return func(self, *args, **kwargs)
21+
else:
22+
print('train_fprop: scope not initiated for {}'.format(self.__class__.__name__))
23+
return func(self, *args, **kwargs)
6724
return decorated
6825

6926
@classmethod
7027
def test_name_scope(cls, func):
7128
def decorated(self, *args, **kwargs):
72-
with tf.name_scope(self.scope):
73-
with tf.name_scope('test'):
74-
return func(self, *args, **kwargs)
29+
if hasattr(self, 'scope'):
30+
with tf.name_scope(self.scope):
31+
with tf.name_scope('test'):
32+
return func(self, *args, **kwargs)
33+
else:
34+
print('test_fprop: scope not initiated for {}'.format(self.__class__.__name__))
35+
return func(self, *args, **kwargs)
7536
return decorated
7637

7738

0 commit comments

Comments
 (0)