tensorflow/models

View on GitHub
research/slim/datasets/build_imagenet_data.py

Summary

Maintainability
D
2 days
Test Coverage

File build_imagenet_data.py has 499 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2016 Google Inc. 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.
# You may obtain a copy of the License at
Severity: Minor
Found in research/slim/datasets/build_imagenet_data.py - About 1 day to fix

    Function _process_image_files_batch has 10 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def _process_image_files_batch(coder, thread_index, ranges, name, filenames,
    Severity: Major
    Found in research/slim/datasets/build_imagenet_data.py - About 1 hr to fix

      Function _convert_to_example has 8 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def _convert_to_example(filename, image_buffer, label, synset, human, bbox,
      Severity: Major
      Found in research/slim/datasets/build_imagenet_data.py - About 1 hr to fix

        Function _process_image_files has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def _process_image_files(name, filenames, synsets, labels, humans,
        Severity: Major
        Found in research/slim/datasets/build_imagenet_data.py - About 50 mins to fix

          Function _process_dataset has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def _process_dataset(name, directory, num_shards, synset_to_human,
          Severity: Minor
          Found in research/slim/datasets/build_imagenet_data.py - About 35 mins to fix

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

            def _process_image_files_batch(coder, thread_index, ranges, name, filenames,
                                           synsets, labels, humans, bboxes, num_shards):
              """Processes and saves list of images as TFRecord in 1 thread.
            
              Args:
            Severity: Minor
            Found in research/slim/datasets/build_imagenet_data.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

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

            def _build_bounding_box_lookup(bounding_box_file):
              """Build a lookup from image file to bounding boxes.
            
              Args:
                bounding_box_file: string, path to file with bounding boxes annotations.
            Severity: Minor
            Found in research/slim/datasets/build_imagenet_data.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 2 locations. Consider refactoring.
            Open

                if l:
                  parts = l.strip().split('\t')
                  assert len(parts) == 2
                  synset = parts[0]
                  human = parts[1]
            Severity: Major
            Found in research/slim/datasets/build_imagenet_data.py and 1 other location - About 3 hrs to fix
            research/slim/datasets/imagenet.py on lines 104..109

            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 62.

            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

            def _int64_feature(value):
              """Wrapper for inserting int64 features into Example proto."""
              if not isinstance(value, list):
                value = [value]
              return tf.train.Feature(int64_list=tf.train.Int64List(value=value))
            Severity: Major
            Found in research/slim/datasets/build_imagenet_data.py and 1 other location - About 2 hrs to fix
            research/slim/datasets/build_imagenet_data.py on lines 166..170

            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 52.

            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

            def _float_feature(value):
              """Wrapper for inserting float features into Example proto."""
              if not isinstance(value, list):
                value = [value]
              return tf.train.Feature(float_list=tf.train.FloatList(value=value))
            Severity: Major
            Found in research/slim/datasets/build_imagenet_data.py and 1 other location - About 2 hrs to fix
            research/slim/datasets/build_imagenet_data.py on lines 159..163

            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 52.

            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 6 locations. Consider refactoring.
            Open

            def _bytes_feature(value):
              """Wrapper for inserting bytes features into Example proto."""
              return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))
            Severity: Major
            Found in research/slim/datasets/build_imagenet_data.py and 5 other locations - About 40 mins to fix
            official/projects/pix2seq/dataloaders/pix2seq_input_test.py on lines 40..42
            official/projects/pix2seq/dataloaders/pix2seq_input_test.py on lines 45..47
            research/delf/delf/python/training/build_image_dataset.py on lines 211..213
            research/delf/delf/python/training/build_image_dataset.py on lines 216..218
            research/slim/datasets/dataset_utils.py on lines 69..78

            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