Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lanpa committed Jan 4, 2018
1 parent f334a9c commit e951aef
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 2 additions & 2 deletions demo_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def forward(self, x):
x = F.relu(self.fc1(x))
x = F.dropout(x, training=self.training)
x = self.fc2(x)
x = F.softmax(x)
x = F.softmax(x, dim=1)
return x


Expand All @@ -46,7 +46,7 @@ def forward(self, x):
x = F.dropout(x, training=self.training)
x = self.fc2(x)
# x = F.log_softmax(x) no scopename(JIT bug)
x = F.softmax(x)
x = F.softmax(x, dim=1)
return x

dummy_input = Variable(torch.rand(13, 1, 28, 28))
Expand Down
6 changes: 1 addition & 5 deletions tensorboardX/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
from .src.versions_pb2 import VersionDef
from .src.attr_value_pb2 import AttrValue
from .src.tensor_shape_pb2 import TensorShapeProto
import torch


def replace(name, scope):
print(type(name), name)
return '/'.join([scope[name], name])


Expand All @@ -32,24 +30,22 @@ def parse(graph):
nodes.append({'name': replace(uname, scope), 'op': n.kind(), 'inputs': inputs, 'attr': attrs})

for n in graph.inputs():
print(n.type())
uname = n.uniqueName()
nodes.append({'name': replace(uname, scope), 'op': 'Parameter', 'inputs': [], 'attr': str(n.type())})

return nodes


def graph(model, args):
import torch
with torch.onnx.set_training(model, False):
trace, _ = torch.jit.trace(model, args)
torch.onnx._optimize_trace(trace, False)
graph = trace.graph()
print(graph)
list_of_nodes = parse(graph)
nodes = []
for node in list_of_nodes:
nodes.append(
NodeDef(name=node['name'], op=node['op'], input=node['inputs'],
attr={'lanpa': AttrValue(s=node['attr'].encode(encoding='utf_8'))}))
print(nodes)
return GraphDef(node=nodes, versions=VersionDef(producer=22))

1 comment on commit e951aef

@lanpa
Copy link
Owner Author

@lanpa lanpa commented on e951aef Jan 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed #65

Please sign in to comment.