tensorflow/models

View on GitHub
official/core/input_reader.py

Summary

Maintainability
F
3 days
Test Coverage

File input_reader.py has 472 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2024 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: Minor
Found in official/core/input_reader.py - About 7 hrs to fix

    Function _read_data_source has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

      def _read_data_source(
          self,
          matched_files: Union[Dict[str, List[str]], List[str]],
          dataset_fn,
          input_context: Optional[tf.distribute.InputContext] = None,
    Severity: Minor
    Found in official/core/input_reader.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 match_files has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def match_files(input_path: Union[Sequence[str], str]) -> List[str]:
      """Matches files from an input_path."""
      matched_files = []
      # Read dataset from files.
      usage = ('`input_path` should be either (1) a str indicating a file '
    Severity: Minor
    Found in official/core/input_reader.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 _read_tfds has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    def _read_tfds(tfds_name: Text,
                   tfds_data_dir: Text,
                   tfds_split: Text,
                   tfds_skip_decoding_feature: Text,
                   tfds_as_supervised: bool,
    Severity: Minor
    Found in official/core/input_reader.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 _decode_and_parse_dataset has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      def _decode_and_parse_dataset(
          self,
          dataset: Union[tf.data.Dataset, Dict[Text, tf.data.Dataset]],
          batch_size: int,
          input_context: Optional[tf.distribute.InputContext] = None
    Severity: Minor
    Found in official/core/input_reader.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 a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      def __init__(
          self,
          params: cfg.DataConfig,
          dataset_fn=tf.data.TFRecordDataset,
          decoder_fn: Optional[Callable[..., Any]] = None,
    Severity: Minor
    Found in official/core/input_reader.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 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def __init__(
          self,
          params: cfg.DataConfig,
          dataset_fn=tf.data.TFRecordDataset,
          decoder_fn: Optional[Callable[..., Any]] = None,
    Severity: Minor
    Found in official/core/input_reader.py - About 1 hr to fix

      Function _read_tfds has 11 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def _read_tfds(tfds_name: Text,
      Severity: Major
      Found in official/core/input_reader.py - About 1 hr to fix

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

        def _shard_files_then_read(matched_files: List[str],
        Severity: Major
        Found in official/core/input_reader.py - About 1 hr to fix

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

            def __init__(
          Severity: Major
          Found in official/core/input_reader.py - About 1 hr to fix

            Function _maybe_apply_data_service has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def _maybe_apply_data_service(
                  self,
                  dataset: tf.data.Dataset,
                  input_context: Optional[tf.distribute.InputContext] = None
              ) -> tf.data.Dataset:
            Severity: Minor
            Found in official/core/input_reader.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 _shard_files_then_read has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

            def _shard_files_then_read(matched_files: List[str],
                                       dataset_fn,
                                       input_context: Optional[
                                           tf.distribute.InputContext] = None,
                                       seed: Optional[Union[int, tf.Tensor]] = None,
            Severity: Minor
            Found in official/core/input_reader.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 _read_files_then_shard has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def _read_files_then_shard(matched_files: List[str],
            Severity: Minor
            Found in official/core/input_reader.py - About 35 mins to fix

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

                def read(self,
                         input_context: Optional[tf.distribute.InputContext] = None,
                         dataset: Optional[tf.data.Dataset] = None) -> tf.data.Dataset:
                  """Generates a tf.data.Dataset object."""
                  if dataset is None:
              Severity: Minor
              Found in official/core/input_reader.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

              There are no issues that match your filters.

              Category
              Status