tensorflow/models

View on GitHub
research/object_detection/data_decoders/tf_example_decoder.py

Summary

Maintainability
F
1 wk
Test Coverage

File tf_example_decoder.py has 926 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# 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.
# You may obtain a copy of the License at
Severity: Major
Found in research/object_detection/data_decoders/tf_example_decoder.py - About 2 days to fix

    Function __init__ has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

      def __init__(self,
                   load_instance_masks=False,
                   instance_mask_type=input_reader_pb2.NUMERICAL_MASKS,
                   label_map_proto_file=None,
                   use_display_name=False,
    Severity: Minor
    Found in research/object_detection/data_decoders/tf_example_decoder.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 decode has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

      def decode(self, tf_example_string_tensor):
        """Decodes serialized tensorflow example and returns a tensor dictionary.
    
        Args:
          tf_example_string_tensor: a string tensor holding a serialized tensorflow
    Severity: Minor
    Found in research/object_detection/data_decoders/tf_example_decoder.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 __init__ has 14 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def __init__(self,
    Severity: Major
    Found in research/object_detection/data_decoders/tf_example_decoder.py - About 1 hr to fix

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

        def __init__(self,
      Severity: Minor
      Found in research/object_detection/data_decoders/tf_example_decoder.py - About 35 mins to fix

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

          def _reshape_keypoint_depths(self, keys_to_tensors):
            """Reshape keypoint depths.
        
            The keypoint depths are reshaped to [num_instances, num_keypoints]. The
            keypoint depth tensor is expected to have the same shape as the keypoint x
        research/object_detection/data_decoders/tf_example_decoder.py on lines 788..820

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

        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 _reshape_keypoint_depth_weights(self, keys_to_tensors):
            """Reshape keypoint depth weights.
        
            The keypoint depth weights are reshaped to [num_instances, num_keypoints].
            The keypoint depth weights tensor is expected to have the same shape as the
        research/object_detection/data_decoders/tf_example_decoder.py on lines 755..786

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

        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

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

          def _reshape_context_features(self, keys_to_tensors):
            """Reshape context features.
        
            The instance context_features are reshaped to
              [num_context_features, context_feature_length]
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 312..330

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

        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

            name_to_id_table = hash_table_class(
                initializer=lookup.KeyValueTensorInitializer(
                    keys=tf.constant(list(name_to_id.keys())),
                    values=tf.constant(list(name_to_id.values()), dtype=tf.int64)),
        research/object_detection/data_decoders/tf_example_decoder.py on lines 112..116
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 77..80

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

        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

            display_name_to_id_table = hash_table_class(
                initializer=lookup.KeyValueTensorInitializer(
                    keys=tf.constant(list(display_name_to_id.keys())),
                    values=tf.constant(
                        list(display_name_to_id.values()), dtype=tf.int64)),
        research/object_detection/data_decoders/tf_example_decoder.py on lines 103..106
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 77..80

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

        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 instance_mask_type in (input_reader_pb2.DEFAULT,
                                        input_reader_pb2.NUMERICAL_MASKS):
                self.keys_to_features['image/object/mask'] = (
                    tf.VarLenFeature(tf.float32))
                self.items_to_handlers[
        research/object_detection/data_decoders/tf_example_decoder.py on lines 406..412

        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

              elif instance_mask_type == input_reader_pb2.PNG_MASKS:
                self.keys_to_features['image/object/mask'] = tf.VarLenFeature(tf.string)
                self.items_to_handlers[
                    fields.InputDataFields.groundtruth_instance_masks] = (
                        slim_example_decoder.ItemHandlerCallback(
        research/object_detection/data_decoders/tf_example_decoder.py on lines 397..405

        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

            if load_track_id:
              self.keys_to_features['image/object/track/label'] = (
                  tf.VarLenFeature(tf.int64))
              self.items_to_handlers[
                  fields.InputDataFields.groundtruth_track_ids] = (
        research/object_detection/data_decoders/tf_example_decoder.py on lines 336..340

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

        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 load_multiclass_scores:
              self.keys_to_features[
                  'image/object/class/multiclass_scores'] = tf.VarLenFeature(tf.float32)
              self.items_to_handlers[fields.InputDataFields.multiclass_scores] = (
                  slim_example_decoder.Tensor('image/object/class/multiclass_scores'))
        research/object_detection/data_decoders/tf_example_decoder.py on lines 447..452

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

        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

        Identical blocks of code found in 4 locations. Consider refactoring.
        Open

              try:
                # Dynamically try to load the tf v2 lookup, falling back to contrib
                lookup = tf.compat.v2.lookup
                hash_table_class = tf.compat.v2.lookup.StaticHashTable
              except AttributeError:
        research/object_detection/builders/dataset_builder_test.py on lines 542..548
        research/object_detection/data_decoders/tf_example_decoder.py on lines 96..102
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 70..76

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

        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

        Identical blocks of code found in 4 locations. Consider refactoring.
        Open

            try:
              # Dynamically try to load the tf v2 lookup, falling back to contrib
              lookup = tf.compat.v2.lookup
              hash_table_class = tf.compat.v2.lookup.StaticHashTable
            except AttributeError:
        research/object_detection/builders/dataset_builder_test.py on lines 542..548
        research/object_detection/data_decoders/tf_example_decoder.py on lines 316..322
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 70..76

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

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

            if fields.InputDataFields.groundtruth_track_ids in tensor_dict:
              tensor_dict[fields.InputDataFields.groundtruth_track_ids] = tf.cast(
                  tensor_dict[fields.InputDataFields.groundtruth_track_ids],
                  dtype=tf.int32)
        Severity: Major
        Found in research/object_detection/data_decoders/tf_example_decoder.py and 6 other locations - About 55 mins to fix
        research/object_detection/data_decoders/tf_example_decoder.py on lines 709..711
        research/object_detection/data_decoders/tf_example_decoder.py on lines 712..714
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 268..270
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 271..272
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 302..305
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 302..308

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

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

              tensor_dict[fields.InputDataFields.groundtruth_dp_num_points] = tf.cast(
                  tensor_dict[fields.InputDataFields.groundtruth_dp_num_points],
                  dtype=tf.int32)
        Severity: Major
        Found in research/object_detection/data_decoders/tf_example_decoder.py and 6 other locations - About 55 mins to fix
        research/object_detection/data_decoders/tf_example_decoder.py on lines 712..714
        research/object_detection/data_decoders/tf_example_decoder.py on lines 716..719
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 268..270
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 271..272
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 302..305
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 302..308

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

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

              tensor_dict[fields.InputDataFields.groundtruth_dp_part_ids] = tf.cast(
                  tensor_dict[fields.InputDataFields.groundtruth_dp_part_ids],
                  dtype=tf.int32)
        Severity: Major
        Found in research/object_detection/data_decoders/tf_example_decoder.py and 6 other locations - About 55 mins to fix
        research/object_detection/data_decoders/tf_example_decoder.py on lines 709..711
        research/object_detection/data_decoders/tf_example_decoder.py on lines 716..719
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 268..270
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 271..272
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 302..305
        research/object_detection/data_decoders/tf_sequence_example_decoder.py on lines 302..308

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

        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