computational_graph.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:chainer-deconv 作者: germanRos 项目源码 文件源码
def _to_dot(self):
        """Converts graph in dot format.

        `label` property of is used as short description of each node.
        Returns:
            str: The graph in dot format.

        """
        ret = "digraph graphname{"
        for node in self.nodes:
            assert isinstance(node, (variable.Variable, function.Function))
            if isinstance(node, variable.Variable):
                ret += DotNode(node, self.variable_style).label
            else:
                ret += DotNode(node, self.function_style).label
        for edge in self.edges:
            head, tail = edge
            if (isinstance(head, variable.Variable) and
                    isinstance(tail, function.Function)):
                head_attr = self.variable_style
                tail_attr = self.function_style
            elif (isinstance(head, function.Function) and
                  isinstance(tail, variable.Variable)):
                head_attr = self.function_style
                tail_attr = self.variable_style
            else:
                raise TypeError(
                    'head and tail should be the set of Variable and Function')
            head_node = DotNode(head, head_attr)
            tail_node = DotNode(tail, tail_attr)
            ret += "%s -> %s;" % (head_node.id_, tail_node.id_)
        ret += "}"
        return ret
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号