tensorflow/models

View on GitHub
research/pcl_rl/trainer.py

Summary

Maintainability
D
2 days
Test Coverage

File trainer.py has 397 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: Minor
Found in research/pcl_rl/trainer.py - About 5 hrs to fix

    Function run has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

      def run(self):
        """Run training."""
        is_chief = FLAGS.task_id == 0 or not FLAGS.supervisor
        sv = None
    
    
    Severity: Minor
    Found in research/pcl_rl/trainer.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 __init__ has 59 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def __init__(self):
        self.batch_size = FLAGS.batch_size
        self.replay_batch_size = FLAGS.replay_batch_size
        if self.replay_batch_size is None:
          self.replay_batch_size = self.batch_size
    Severity: Major
    Found in research/pcl_rl/trainer.py - About 2 hrs to fix

      Function get_objective has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        def get_objective(self):
          tau = self.tau
          if self.tau_decay is not None:
            assert self.tau_start >= self.tau
            tau = tf.maximum(
      Severity: Minor
      Found in research/pcl_rl/trainer.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

      Consider simplifying this complex logical expression.
      Open

            if (random.random() < 0.1 and summary and episode_rewards and
                is_chief and sv and sv._summary_writer):
              sv.summary_computed(sess, summary)
      
      
      Severity: Major
      Found in research/pcl_rl/trainer.py - About 40 mins to fix

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

                with tf.variable_scope(tf.get_variable_scope(), reuse=True):
                  self.eval_controller = self.get_controller(self.eval_env)
                  self.eval_controller.setup(train=False)
        Severity: Major
        Found in research/pcl_rl/trainer.py and 1 other location - About 1 hr to fix
        research/pcl_rl/trainer.py on lines 401..403

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

        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

              with tf.variable_scope(tf.get_variable_scope(), reuse=True):
                self.eval_controller = self.get_controller(self.eval_env)
                self.eval_controller.setup(train=False)
        Severity: Major
        Found in research/pcl_rl/trainer.py and 1 other location - About 1 hr to fix
        research/pcl_rl/trainer.py on lines 380..382

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

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

            return cls(self.env_spec, self.global_step,
                       target_network_lag=self.target_network_lag,
                       sample_from=self.sample_from,
                       get_policy=self.get_policy,
                       get_baseline=self.get_baseline,
        Severity: Major
        Found in research/pcl_rl/trainer.py and 4 other locations - About 50 mins to fix
        official/nlp/modeling/layers/relative_attention.py on lines 135..142
        official/projects/yolo/modeling/layers/nn_blocks.py on lines 1911..1921
        official/projects/yolo/ops/mosaic.py on lines 236..244
        research/audioset/vggish/vggish_input.py on lines 61..69

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

        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

            self.env = gym_wrapper.GymWrapper(self.env_str,
                                              distinct=FLAGS.batch_size // self.num_samples,
                                              count=self.num_samples)
        Severity: Minor
        Found in research/pcl_rl/trainer.py and 1 other location - About 40 mins to fix
        research/pcl_rl/trainer.py on lines 158..161

        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

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

            self.eval_env = gym_wrapper.GymWrapper(
                self.env_str,
                distinct=FLAGS.batch_size // self.num_samples,
                count=self.num_samples)
        Severity: Minor
        Found in research/pcl_rl/trainer.py and 1 other location - About 40 mins to fix
        research/pcl_rl/trainer.py on lines 155..157

        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