nigroup/nideep

View on GitHub
nideep/eval/inference.py

Summary

Maintainability
D
3 days
Test Coverage

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

def infer_to_h5_fixed_dims(net, keys, n, dst_fpath, preserve_batch=False):
    """
    Run network inference for n batches and save results to file
    """
    with h5py.File(dst_fpath, "w") as f:
Severity: Minor
Found in nideep/eval/inference.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 est_min_num_fwd_passes has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

def est_min_num_fwd_passes(fpath_net, mode_str, key=None):
    """
    if multiple source for same mode, base num_passes on last
    fpath_net -- path to network definition
    mode_str -- train or test?
Severity: Minor
Found in nideep/eval/inference.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

Avoid deeply nested control flow statements.
Open

                    if batch_sz is None:
                        batch_sz = d[k].shape[0]
                        for k2 in keys:
                            shape_all = list(d[k2].shape)
                            shape_all[0] = n * batch_sz
Severity: Major
Found in nideep/eval/inference.py - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                        if k not in f:
                            shape_all = [n]
                            shape_all.extend(list(d_copy.shape))
                            f.create_dataset(k, tuple(shape_all), d_copy.dtype)
                        f[k][itr] = d_copy
    Severity: Major
    Found in nideep/eval/inference.py - About 45 mins to fix

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

      def infer_to_h5_fixed_dims(net, keys, n, dst_fpath, preserve_batch=False):
      Severity: Minor
      Found in nideep/eval/inference.py - About 35 mins to fix

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

        def response_to_lmdb(fpath_net,
        Severity: Minor
        Found in nideep/eval/inference.py - About 35 mins to fix

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

          def _infer_to_lmdb_cur_multi_key(net, keys, n, dbs):
              '''
              Run network inference for n batches and save results to an lmdb for each key.
              Higher time complexity but lower space complexity.
          
          
          Severity: Minor
          Found in nideep/eval/inference.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 ('hdf5data' in l.type.lower() and
                              (mode_str.lower() in l.hdf5_data_param.source.lower() or
                                  [x.phase for x in l.include] == [mode_num])):
                          num_entries = CreateDatasource.from_path(l.hdf5_data_param.source, key=key).num_entries()
                          num_passes = int(num_entries / l.hdf5_data_param.batch_size)
          Severity: Major
          Found in nideep/eval/inference.py and 1 other location - About 7 hrs to fix
          nideep/eval/inference.py on lines 173..181

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

          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 (mode_str.lower() in l.data_param.source.lower() or
                              [x.phase for x in l.include] == [mode_num]):
                          num_entries = CreateDatasource.from_path(l.data_param.source, key=key).num_entries()
                          num_passes = int(num_entries / l.data_param.batch_size)
                          if num_entries % l.data_param.batch_size != 0:
          Severity: Major
          Found in nideep/eval/inference.py and 1 other location - About 7 hrs to fix
          nideep/eval/inference.py on lines 163..172

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

          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

                              (mode_str.lower() in l.hdf5_data_param.source.lower() or
                                  [x.phase for x in l.include] == [mode_num])):
          Severity: Major
          Found in nideep/eval/inference.py and 1 other location - About 1 hr to fix
          nideep/eval/inference.py on lines 173..174

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

          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