From e6c18619ec65cc4eb15646ba1315ad27fb60219b Mon Sep 17 00:00:00 2001 From: Vandana Kannan Date: Wed, 13 Mar 2019 18:32:55 -0700 Subject: [PATCH 1/5] Check for kernel in Pooling --- python/mxnet/visualization.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/mxnet/visualization.py b/python/mxnet/visualization.py index 1ebdcb54f4ce..af8ce9112ed9 100644 --- a/python/mxnet/visualization.py +++ b/python/mxnet/visualization.py @@ -343,7 +343,8 @@ def looks_like_weight(name): attr["fillcolor"] = cm[2] elif op == "Pooling": label = r"Pooling\n%s, %s/%s" % (node["attrs"]["pool_type"], - "x".join(_str2tuple(node["attrs"]["kernel"])), + "x".join(_str2tuple(node["attrs"]["kernel"])) + if "kernel" in node["attrs"] else "[]", "x".join(_str2tuple(node["attrs"]["stride"])) if "stride" in node["attrs"] else "1") attr["fillcolor"] = cm[4] From c2878bd4035a32875a520070cc1b6e255e88d088 Mon Sep 17 00:00:00 2001 From: Vandana Kannan Date: Wed, 13 Mar 2019 18:53:29 -0700 Subject: [PATCH 2/5] Fix Leakyrelu visualization --- python/mxnet/visualization.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/python/mxnet/visualization.py b/python/mxnet/visualization.py index af8ce9112ed9..8eb20a8af990 100644 --- a/python/mxnet/visualization.py +++ b/python/mxnet/visualization.py @@ -339,7 +339,12 @@ def looks_like_weight(name): elif op == "BatchNorm": attr["fillcolor"] = cm[3] elif op in ('Activation', 'LeakyReLU'): - label = r"%s\n%s" % (op, node["attrs"]["act_type"]) + if op == "LeakyReLU": + attrs = node.get("attrs") + act_type = attrs.get("act_type", "Leaky") if attrs else "Leaky" + else: + act_type = node["attrs"]["act_type"] + label = r"%s\n%s" % (op, str(act_type)) attr["fillcolor"] = cm[2] elif op == "Pooling": label = r"Pooling\n%s, %s/%s" % (node["attrs"]["pool_type"], From d5dd193f28dbf2729d5acb3ca4630951cfb3a992 Mon Sep 17 00:00:00 2001 From: Vandana Kannan Date: Thu, 14 Mar 2019 10:56:38 -0700 Subject: [PATCH 3/5] Address review comments --- python/mxnet/visualization.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/python/mxnet/visualization.py b/python/mxnet/visualization.py index 8eb20a8af990..9152b19f5d9a 100644 --- a/python/mxnet/visualization.py +++ b/python/mxnet/visualization.py @@ -338,13 +338,14 @@ def looks_like_weight(name): attr["fillcolor"] = cm[1] elif op == "BatchNorm": attr["fillcolor"] = cm[3] - elif op in ('Activation', 'LeakyReLU'): - if op == "LeakyReLU": - attrs = node.get("attrs") - act_type = attrs.get("act_type", "Leaky") if attrs else "Leaky" - else: - act_type = node["attrs"]["act_type"] - label = r"%s\n%s" % (op, str(act_type)) + elif op == 'Activation': + act_type = node["attrs"]["act_type"] + label = '{operator}\n{activation}'.format(operator=op, activation=act_type) + attr["fillcolor"] = cm[2] + elif op == 'LeakyReLU': + attrs = node.get("attrs") + act_type = attrs.get("act_type", "Leaky") if attrs else "Leaky" + label = '{operator}\n{activation}'.format(operator=op, activation=act_type) attr["fillcolor"] = cm[2] elif op == "Pooling": label = r"Pooling\n%s, %s/%s" % (node["attrs"]["pool_type"], From 75cf8a304ae086885279940c357a1b65fd6cb253 Mon Sep 17 00:00:00 2001 From: Vandana Kannan Date: Thu, 14 Mar 2019 11:13:26 -0700 Subject: [PATCH 4/5] Change all occurences to string format --- python/mxnet/visualization.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/python/mxnet/visualization.py b/python/mxnet/visualization.py index 9152b19f5d9a..7caba030aaa1 100644 --- a/python/mxnet/visualization.py +++ b/python/mxnet/visualization.py @@ -205,7 +205,7 @@ def print_layer_summary(node, out_shape): print('=' * line_length) else: print('_' * line_length) - print('Total params: %s' % total_params) + print("Total params: {params}".format(params=total_params)) print('_' * line_length) def plot_network(symbol, title="plot", save_format='pdf', shape=None, node_attrs={}, @@ -328,30 +328,32 @@ def looks_like_weight(name): label = node["name"] attr["fillcolor"] = cm[0] elif op == "Convolution": - label = r"Convolution\n%s/%s, %s" % ("x".join(_str2tuple(node["attrs"]["kernel"])), - "x".join(_str2tuple(node["attrs"]["stride"])) - if "stride" in node["attrs"] else "1", - node["attrs"]["num_filter"]) + label = "Convolution\n{kernel}/{stride}, {filter}".format( + kernel="x".join(_str2tuple(node["attrs"]["kernel"])), + stride="x".join(_str2tuple(node["attrs"]["stride"])) + if "stride" in node["attrs"] else "1", + filter=node["attrs"]["num_filter"] + ) attr["fillcolor"] = cm[1] elif op == "FullyConnected": - label = r"FullyConnected\n%s" % node["attrs"]["num_hidden"] + label = "FullyConnected\n{hidden}".format(hidden=node["attrs"]["num_hidden"]) attr["fillcolor"] = cm[1] elif op == "BatchNorm": attr["fillcolor"] = cm[3] elif op == 'Activation': act_type = node["attrs"]["act_type"] - label = '{operator}\n{activation}'.format(operator=op, activation=act_type) + label = 'Activation\n{activation}'.format(activation=act_type) attr["fillcolor"] = cm[2] elif op == 'LeakyReLU': attrs = node.get("attrs") act_type = attrs.get("act_type", "Leaky") if attrs else "Leaky" - label = '{operator}\n{activation}'.format(operator=op, activation=act_type) + label = 'LeakyReLU\n{activation}'.format(activation=act_type) attr["fillcolor"] = cm[2] elif op == "Pooling": - label = r"Pooling\n%s, %s/%s" % (node["attrs"]["pool_type"], - "x".join(_str2tuple(node["attrs"]["kernel"])) + label = "Pooling\n{pooltype}, {kernel}/{stride}".format(pooltype=node["attrs"]["pool_type"], + kernel="x".join(_str2tuple(node["attrs"]["kernel"])) if "kernel" in node["attrs"] else "[]", - "x".join(_str2tuple(node["attrs"]["stride"])) + stride="x".join(_str2tuple(node["attrs"]["stride"])) if "stride" in node["attrs"] else "1") attr["fillcolor"] = cm[4] elif op in ("Concat", "Flatten", "Reshape"): From 28c14eabd368a99036d25ffe234ba723e242acb9 Mon Sep 17 00:00:00 2001 From: Vandana Kannan Date: Thu, 14 Mar 2019 12:26:10 -0700 Subject: [PATCH 5/5] Fix lint error --- python/mxnet/visualization.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/mxnet/visualization.py b/python/mxnet/visualization.py index 7caba030aaa1..ba8907a0bc3d 100644 --- a/python/mxnet/visualization.py +++ b/python/mxnet/visualization.py @@ -351,10 +351,10 @@ def looks_like_weight(name): attr["fillcolor"] = cm[2] elif op == "Pooling": label = "Pooling\n{pooltype}, {kernel}/{stride}".format(pooltype=node["attrs"]["pool_type"], - kernel="x".join(_str2tuple(node["attrs"]["kernel"])) - if "kernel" in node["attrs"] else "[]", - stride="x".join(_str2tuple(node["attrs"]["stride"])) - if "stride" in node["attrs"] else "1") + kernel="x".join(_str2tuple(node["attrs"]["kernel"])) + if "kernel" in node["attrs"] else "[]", + stride="x".join(_str2tuple(node["attrs"]["stride"])) + if "stride" in node["attrs"] else "1") attr["fillcolor"] = cm[4] elif op in ("Concat", "Flatten", "Reshape"): attr["fillcolor"] = cm[5]