tensorflow/tensorflow

View on GitHub
tensorflow/lite/tools/visualize.py

Summary

Maintainability
D
2 days
Test Coverage

File visualize.py has 426 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env python
# Copyright 2017 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Severity: Minor
Found in tensorflow/lite/tools/visualize.py - About 6 hrs to fix

    Function GenerateGraph has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

    def GenerateGraph(subgraph_idx, g, opcode_mapper):
      """Produces the HTML required to have a d3 visualization of the dag."""
    
      def TensorName(idx):
        return "t%d" % idx
    Severity: Minor
    Found in tensorflow/lite/tools/visualize.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function FlatbufferToDict has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    def FlatbufferToDict(fb, preserve_as_numpy):
      """Converts a hierarchy of FB objects into a nested dict.
    
      We avoid transforming big parts of the flat buffer into python arrays. This
      speeds conversion from ten minutes to a few seconds on big graphs.
    Severity: Minor
    Found in tensorflow/lite/tools/visualize.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function create_html has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def create_html(tflite_input, input_is_filepath=True):  # pylint: disable=invalid-name
      """Returns html description with the given tflite model.
    
      Args:
        tflite_input: TFLite flatbuffer model path or model object.
    Severity: Minor
    Found in tensorflow/lite/tools/visualize.py - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function GenerateTableHtml has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def GenerateTableHtml(items, keys_to_print, display_index=True):
      """Given a list of object values and keys to print, make an HTML table.
    
      Args:
        items: Items to print an array of dicts.
    Severity: Minor
    Found in tensorflow/lite/tools/visualize.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function NameListToString has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    def NameListToString(name_list):
      """Converts a list of integers to the equivalent ASCII string."""
      if isinstance(name_list, str):
        return name_list
      else:
    Severity: Minor
    Found in tensorflow/lite/tools/visualize.py - About 35 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Avoid too many return statements within this function.
    Open

        return fb
    Severity: Major
    Found in tensorflow/lite/tools/visualize.py - About 30 mins to fix

      Function __call__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def __call__(self, x):
          html = ""
          if x is None:
            return html
      
      
      Severity: Minor
      Found in tensorflow/lite/tools/visualize.py - About 25 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

      def TensorTypeToName(tensor_type):
        """Converts a numerical enum to a readable tensor type."""
        for name, value in schema_fb.TensorType.__dict__.items():
          if value == tensor_type:
            return name
      Severity: Major
      Found in tensorflow/lite/tools/visualize.py and 2 other locations - About 1 hr to fix
      tensorflow/lite/tools/flatbuffer_utils.py on lines 144..149
      tensorflow/lite/tools/visualize.py on lines 213..218

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 42.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 3 locations. Consider refactoring.
      Open

      def BuiltinCodeToName(code):
        """Converts a builtin op code enum to a readable name."""
        for name, value in schema_fb.BuiltinOperator.__dict__.items():
          if value == code:
            return name
      Severity: Major
      Found in tensorflow/lite/tools/visualize.py and 2 other locations - About 1 hr to fix
      tensorflow/lite/tools/flatbuffer_utils.py on lines 144..149
      tensorflow/lite/tools/visualize.py on lines 205..210

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 42.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      if not os.path.splitext(__file__)[0].endswith(
          os.path.join("tflite_runtime", "visualize")):
      Severity: Minor
      Found in tensorflow/lite/tools/visualize.py and 1 other location - About 40 mins to fix
      tensorflow/lite/python/interpreter.py on lines 25..26

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 34.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      There are no issues that match your filters.

      Category
      Status