File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 5
5
6
6
7
7
class TensorFlowNode (object ):
8
+ '''An intermediate representation for TensorFlow operations.'''
8
9
9
10
def __init__ (self , op , * args , ** kwargs ):
11
+ # A string corresponding to the TensorFlow operation
10
12
self .op = op
13
+ # Positional arguments for the operation
11
14
self .args = args
15
+ # Keyword arguments for the operation
12
16
self .kwargs = list (kwargs .items ())
17
+ # The source Caffe node
13
18
self .node = None
14
19
15
20
def format (self , arg ):
21
+ '''Returns a string representation for the given value.'''
16
22
return "'%s'" % arg if isinstance (arg , basestring ) else str (arg )
17
23
18
24
def pair (self , key , value ):
25
+ '''Returns key=formatted(value).'''
19
26
return '%s=%s' % (key , self .format (value ))
20
27
21
28
def emit (self ):
29
+ '''Emits the Python source for this node.'''
30
+ # Format positional arguments
22
31
args = map (self .format , self .args )
32
+ # Format any keyword arguments
23
33
if self .kwargs :
24
34
args += [self .pair (k , v ) for k , v in self .kwargs ]
35
+ # Set the node name
25
36
args .append (self .pair ('name' , self .node .name ))
26
37
args = ', ' .join (args )
27
38
return '%s(%s)' % (self .op , args )
You can’t perform that action at this time.
0 commit comments