Browse Source

fix unsafe functions and duplication files and redundant codes

tags/v0.2.0-alpha
ougongchang 5 years ago
parent
commit
e3c0bbac89
8 changed files with 53 additions and 43 deletions
  1. +1
    -0
      mindinsight/backend/__init__.py
  2. +1
    -0
      mindinsight/datavisual/common/__init__.py
  3. +15
    -15
      mindinsight/datavisual/data_transform/graph/graph.py
  4. +1
    -1
      mindinsight/datavisual/data_transform/graph/msgraph.py
  5. +32
    -26
      mindinsight/datavisual/data_transform/graph/node.py
  6. +1
    -0
      mindinsight/datavisual/data_transform/loader_generators/__init__.py
  7. +1
    -1
      mindinsight/datavisual/data_transform/summary_watcher.py
  8. +1
    -0
      tests/utils/__init__.py

+ 1
- 0
mindinsight/backend/__init__.py View File

@@ -12,3 +12,4 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
"""This module defines the methods associated with the web app."""

+ 1
- 0
mindinsight/datavisual/common/__init__.py View File

@@ -12,3 +12,4 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
"""This module defines the public methods that are relevant to the business."""

+ 15
- 15
mindinsight/datavisual/data_transform/graph/graph.py View File

@@ -206,8 +206,8 @@ class Graph:
for name_tmp, node_tmp in group.items(): for name_tmp, node_tmp in group.items():
node_tmp.polymeric_scope_name = polymeric_node_name node_tmp.polymeric_scope_name = polymeric_node_name
self._polymeric_nodes.update({name_tmp: node_tmp}) self._polymeric_nodes.update({name_tmp: node_tmp})
polymeric_node.update_input(node_tmp.input)
polymeric_node.update_output(node_tmp.output)
polymeric_node.update_input(node_tmp.inputs)
polymeric_node.update_output(node_tmp.outputs)


self._normal_nodes.update({polymeric_node_name: polymeric_node}) self._normal_nodes.update({polymeric_node_name: polymeric_node})


@@ -227,7 +227,7 @@ class Graph:
for node_name, group_node in group.items(): for node_name, group_node in group.items():
node_list = [] node_list = []
is_in_group = False is_in_group = False
for dst_name in group_node.output:
for dst_name in group_node.outputs:
node_tmp = self._leaf_nodes[dst_name] node_tmp = self._leaf_nodes[dst_name]
node_list.append(node_tmp) node_list.append(node_tmp)


@@ -245,7 +245,7 @@ class Graph:
if node_tmp in group.values(): if node_tmp in group.values():
is_in_group = True is_in_group = True
break break
for dst_name_tmp in node_tmp.output:
for dst_name_tmp in node_tmp.outputs:
run_count += 1 run_count += 1
node_tmp = self._leaf_nodes[dst_name_tmp] node_tmp = self._leaf_nodes[dst_name_tmp]
if visit_nodes.get(dst_name_tmp): if visit_nodes.get(dst_name_tmp):
@@ -273,23 +273,23 @@ class Graph:
def _update_input_output(self): def _update_input_output(self):
"""We need to update input and output attribute after build polymeric node.""" """We need to update input and output attribute after build polymeric node."""
for node in self._normal_nodes.values(): for node in self._normal_nodes.values():
for src_name, input_attr in node.input.items():
for src_name, input_attr in node.inputs.items():
if self._polymeric_nodes.get(src_name): if self._polymeric_nodes.get(src_name):
input_attr['scope'] = NodeTypeEnum.POLYMERIC_SCOPE.value input_attr['scope'] = NodeTypeEnum.POLYMERIC_SCOPE.value
node.update_input({src_name: input_attr}) node.update_input({src_name: input_attr})


for dst_name, output_attr in node.output.items():
for dst_name, output_attr in node.outputs.items():
if self._polymeric_nodes.get(dst_name): if self._polymeric_nodes.get(dst_name):
output_attr['scope'] = NodeTypeEnum.POLYMERIC_SCOPE.value output_attr['scope'] = NodeTypeEnum.POLYMERIC_SCOPE.value
node.update_output({dst_name: output_attr}) node.update_output({dst_name: output_attr})


for node in self._polymeric_nodes.values(): for node in self._polymeric_nodes.values():
for src_name, input_attr in node.input.items():
for src_name, input_attr in node.inputs.items():
if self._polymeric_nodes.get(src_name): if self._polymeric_nodes.get(src_name):
input_attr['scope'] = NodeTypeEnum.POLYMERIC_SCOPE.value input_attr['scope'] = NodeTypeEnum.POLYMERIC_SCOPE.value
node.update_input({src_name: input_attr}) node.update_input({src_name: input_attr})


for dst_name, output_attr in node.output.items():
for dst_name, output_attr in node.outputs.items():
if self._polymeric_nodes.get(dst_name): if self._polymeric_nodes.get(dst_name):
output_attr['scope'] = NodeTypeEnum.POLYMERIC_SCOPE.value output_attr['scope'] = NodeTypeEnum.POLYMERIC_SCOPE.value
node.update_output({dst_name: output_attr}) node.update_output({dst_name: output_attr})
@@ -297,21 +297,21 @@ class Graph:
def _update_polymeric_input_output(self): def _update_polymeric_input_output(self):
"""Calc polymeric input and output after build polymeric node.""" """Calc polymeric input and output after build polymeric node."""
for node in self._normal_nodes.values(): for node in self._normal_nodes.values():
polymeric_input = self._calc_polymeric_attr(node, 'input')
polymeric_input = self._calc_polymeric_attr(node, 'inputs')
node.update_polymeric_input(polymeric_input) node.update_polymeric_input(polymeric_input)


polymeric_output = self._calc_polymeric_attr(node, 'output')
polymeric_output = self._calc_polymeric_attr(node, 'outputs')
node.update_polymeric_output(polymeric_output) node.update_polymeric_output(polymeric_output)


for name, node in self._polymeric_nodes.items(): for name, node in self._polymeric_nodes.items():
polymeric_input = {} polymeric_input = {}
for src_name in node.input:
for src_name in node.inputs:
output_name = self._calc_dummy_node_name(name, src_name) output_name = self._calc_dummy_node_name(name, src_name)
polymeric_input.update({output_name: {'edge_type': EdgeTypeEnum.DATA.value}}) polymeric_input.update({output_name: {'edge_type': EdgeTypeEnum.DATA.value}})
node.update_polymeric_input(polymeric_input) node.update_polymeric_input(polymeric_input)


polymeric_output = {} polymeric_output = {}
for dst_name in node.output:
for dst_name in node.outputs:
polymeric_output = {} polymeric_output = {}
output_name = self._calc_dummy_node_name(name, dst_name) output_name = self._calc_dummy_node_name(name, dst_name)
polymeric_output.update({output_name: {'edge_type': EdgeTypeEnum.DATA.value}}) polymeric_output.update({output_name: {'edge_type': EdgeTypeEnum.DATA.value}})
@@ -410,12 +410,12 @@ class Graph:


# update the input and output of this to namescope node # update the input and output of this to namescope node
name_scope_with_slash = name_scope + '/' name_scope_with_slash = name_scope + '/'
for src_name, input_attr in node.input.items():
for src_name, input_attr in node.inputs.items():
if src_name.startswith(name_scope_with_slash): if src_name.startswith(name_scope_with_slash):
continue continue
name_scope_node.update_input({src_name: input_attr}) name_scope_node.update_input({src_name: input_attr})


for dst_name, output_attr in node.output.items():
for dst_name, output_attr in node.outputs.items():
if dst_name.startswith(name_scope_with_slash): if dst_name.startswith(name_scope_with_slash):
continue continue
name_scope_node.update_output({dst_name: output_attr}) name_scope_node.update_output({dst_name: output_attr})
@@ -428,7 +428,7 @@ class Graph:
nodes.extend(self._normal_nodes.values()) nodes.extend(self._normal_nodes.values())
nodes.extend(self._polymeric_nodes.values()) nodes.extend(self._polymeric_nodes.values())
for node in nodes: for node in nodes:
attrs = ['input', 'output', 'polymeric_input', 'polymeric_output']
attrs = ['inputs', 'outputs', 'polymeric_inputs', 'polymeric_outputs']
for item in attrs: for item in attrs:
tmp_dict = dict(getattr(node, item)) tmp_dict = dict(getattr(node, item))
for name, value in tmp_dict.items(): for name, value in tmp_dict.items():


+ 1
- 1
mindinsight/datavisual/data_transform/graph/msgraph.py View File

@@ -138,7 +138,7 @@ class MSGraph(Graph):
for name, node in self._leaf_nodes.items(): for name, node in self._leaf_nodes.items():
if node.node_type == NodeTypeEnum.CONST.value: if node.node_type == NodeTypeEnum.CONST.value:
continue continue
for src_name, input_attr in node.input.items():
for src_name, input_attr in node.inputs.items():
src_node = self._leaf_nodes[src_name] src_node = self._leaf_nodes[src_name]
if src_node.node_type == NodeTypeEnum.CONST.value: if src_node.node_type == NodeTypeEnum.CONST.value:
continue continue


+ 32
- 26
mindinsight/datavisual/data_transform/graph/node.py View File

@@ -39,11 +39,11 @@ class Node:
self._name = name self._name = name
self._type = "" self._type = ""
self._attr = dict() self._attr = dict()
self._input = dict()
self._inputs = dict()
self._output_i = -1 self._output_i = -1
self._output = {}
self._polymeric_input = {}
self._polymeric_output = {}
self._outputs = {}
self._polymeric_inputs = {}
self._polymeric_outputs = {}
self._polymeric_scope_name = "" self._polymeric_scope_name = ""
self._subnode_count = 0 self._subnode_count = 0
self._name_scope = "" self._name_scope = ""
@@ -55,11 +55,11 @@ class Node:
'name': self._name, 'name': self._name,
'type': self._type, 'type': self._type,
'attr': self._attr, 'attr': self._attr,
'input': self._input,
'input': self._inputs,
'output_i': self._output_i, 'output_i': self._output_i,
'output': self._output,
'polymeric_input': self._polymeric_input,
'polymeric_output': self._polymeric_output,
'output': self._outputs,
'polymeric_input': self._polymeric_inputs,
'polymeric_output': self._polymeric_outputs,
'subnode_count': self._subnode_count, 'subnode_count': self._subnode_count,
'polymeric_scope_name': self._polymeric_scope_name 'polymeric_scope_name': self._polymeric_scope_name
} }
@@ -99,28 +99,32 @@ class Node:
Update node attr. Update node attr.


Args: Args:
attr_dict (dict[str, str]): Format is {'<key>': '<value>'}.
attr_dict (dict[str, str]): The attr of node.
""" """
self._attr.update(attr_dict) self._attr.update(attr_dict)


@property @property
def input(self):
def inputs(self):
""" """
Get all input of current node. Get all input of current node.


Returns: Returns:
dict[str, dict], format is {'<src_name>': {'shape': [], 'edge_type', 'scope'}}. dict[str, dict], format is {'<src_name>': {'shape': [], 'edge_type', 'scope'}}.
""" """
return self._input
return self._inputs


def update_input(self, input_dict): def update_input(self, input_dict):
""" """
Update input. Update input.


Args: Args:
input_dict (dict[str, dict]): Format is {'<src_name>': {'shape': [], 'edge_type', 'scope'}}.
input_dict (dict[str, dict]): Key is a source node name, and the value is a dict.

- shape (list): The shape of input tensor.
- edge_type (str): The type of edge, optional value refer to `EdgeTypeEnum`.
- scope (str): The scope of this source node.
""" """
self._input.update(input_dict)
self._inputs.update(input_dict)


@property @property
def output_i(self): def output_i(self):
@@ -133,49 +137,51 @@ class Node:
self._output_i = output_i self._output_i = output_i


@property @property
def polymeric_input(self):
def polymeric_inputs(self):
""" """
The polymeric input is the input of the polymeric nodes. The polymeric input is the input of the polymeric nodes.


Returns: Returns:
dict[str, dict], format is {'<src_name>': {'edge_type': '<value>'}}. dict[str, dict], format is {'<src_name>': {'edge_type': '<value>'}}.
""" """
return self._polymeric_input
return self._polymeric_inputs


def update_polymeric_input(self, polymeric_input): def update_polymeric_input(self, polymeric_input):
"""The polymeric input is the input of the polymeric nodes.""" """The polymeric input is the input of the polymeric nodes."""
self._polymeric_input.update(polymeric_input)
self._polymeric_inputs.update(polymeric_input)


@property @property
def output(self):
def outputs(self):
"""The output node of this node.""" """The output node of this node."""
return self._output
return self._outputs


def update_output(self, output): def update_output(self, output):
""" """
Update output node. Update output node.


Args: Args:
output (dict[str, TypedDict('NodeType', {'type': str})]): Format
is {"<node_name>": {"type": "<node type>"}}.
output (dict[str, TypedDict('NodeType', {'type': str})]): Key is a dst node name, and value is a dict.

- type (str): The type of the dst node.
""" """
self._output.update(output)
self._outputs.update(output)


@property @property
def polymeric_output(self):
def polymeric_outputs(self):
"""Get polymeric output.""" """Get polymeric output."""
return self._polymeric_output
return self._polymeric_outputs


def update_polymeric_output(self, polymeric_output): def update_polymeric_output(self, polymeric_output):
""" """
Update polymeric output. Update polymeric output.


Args: Args:
polymeric_output (dict[str, dict): Format is {dst_node.polymeric_scope_name:
{'edge_type': EdgeTypeEnum.DATA.value}}).
polymeric_output (dict[str, dict): Key is the polymeric scope name of dst name, and value is dict.

- edge_type (str): The edge type of the dst node.


""" """
self._polymeric_output.update(polymeric_output)
self._polymeric_outputs.update(polymeric_output)


@property @property
def polymeric_scope_name(self): def polymeric_scope_name(self):


+ 1
- 0
mindinsight/datavisual/data_transform/loader_generators/__init__.py View File

@@ -12,3 +12,4 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
"""This module defines the generator for the loaders."""

+ 1
- 1
mindinsight/datavisual/data_transform/summary_watcher.py View File

@@ -32,7 +32,7 @@ class SummaryWatcher:
MAX_SUMMARY_DIR_COUNT = 999 MAX_SUMMARY_DIR_COUNT = 999
# scan at most 20000 files/directories (approximately 1 seconds) # scan at most 20000 files/directories (approximately 1 seconds)
# if overall=False in SummaryWatcher.list_summary_directories
# if overall is False in SummaryWatcher.list_summary_directories
# to avoid long-time blocking # to avoid long-time blocking
MAX_SCAN_COUNT = 20000 MAX_SCAN_COUNT = 20000


+ 1
- 0
tests/utils/__init__.py View File

@@ -12,3 +12,4 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# ============================================================================ # ============================================================================
"""This module defines common utility methods."""

Loading…
Cancel
Save