Parcurcik
Parcurcik

Reputation: 310

How can I fix this error with tensorflow warning?

When the programme has been started in the console outputting:

WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.base has been moved to tensorflow.python.trackable.base. The old module will be deleted in version 2.11.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.checkpoint_management has been moved to tensorflow.python.checkpoint.checkpoint_management. The old module will be deleted in version 2.9.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.resource has been moved to tensorflow.python.trackable.resource. The old module will be deleted in version 2.11.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.util has been moved to tensorflow.python.checkpoint.checkpoint. The old module will be deleted in version 2.11.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.base_delegate has been moved to tensorflow.python.trackable.base_delegate. The old module will be deleted in version 2.11.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.graph_view has been moved to tensorflow.python.checkpoint.graph_view. The old module will be deleted in version 2.11.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.python_state has been moved to tensorflow.python.trackable.python_state. The old module will be deleted in version 2.11.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.saving.functional_saver has been moved to tensorflow.python.checkpoint.functional_saver. The old module will be deleted in version 2.11.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.saving.checkpoint_options has been moved to tensorflow.python.checkpoint.checkpoint_options. The old module will be deleted in version 2.11.

How to fix this?

update there

Upvotes: 4

Views: 4557

Answers (3)

danielcahall
danielcahall

Reputation: 2742

The logging occurs in this function:

  def getter(name):
    if getter not in _PRINTED_WARNING and _PRINT_DEPRECATION_WARNINGS:
      _PRINTED_WARNING[getter] = True
      logging.warning(
          'Please fix your imports. Module %s has been moved to %s. The old '
          'module will be deleted in version %s.', deprecated_name,
          new_module.__name__, deletion_version)
    return getattr(new_module, name)

  return getter

In various modules, you'll find:

deprecation.deprecate_moved_module(
    __name__, <MODULE_NAME>, "<VERSION_NUMBER>")

One example from the snippet provided is tensorflow.python.training.saving.checkpoint_options:

from tensorflow.python.checkpoint import checkpoint_options
from tensorflow.python.util import deprecation

__getattr__ = deprecation.deprecate_moved_module(
    __name__, checkpoint_options, "2.11")

which indicates importing from that module is being deprecated in 2.11 (although it will still technically work until then).

Based on the snippet provided, it does not appear you're directly importing these modules, but an external dependency or a different module may be. If fixing the imports is not possible, in the same deprecations module, there is a context manager called silence, which changes the global variable _PRINT_DEPRECATION_WARNINGS to False within the context block and will therefore prevent the warning logs from surfacing. The use would be something like:


from tensorflow.python.util import deprecation

with deprecation.silence():
    <INSERT_CODE_HERE>

Alternatively, if you don't want to put a large code block within a context manager, you could just set the variable _PRINT_DEPRECATION_WARNINGS directly at the top of your module:

from tensorflow.python.util import deprecation
deprecation._PRINT_DEPRECATION_WARNINGS = False
<INSERT_CODE_HERE>

Note that setting the environment variable TF_CPP_MIN_LOG_LEVEL to 1-3 for reduced logging does not apply for deprecation warnings, as discussed in this thread.

Upvotes: 1

Vijay Mariappan
Vijay Mariappan

Reputation: 17191

Can you try setting the log level before you import tensorflow?

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = "2"
import tensorflow as tf

Upvotes: 2

INGl0R1AM0R1
INGl0R1AM0R1

Reputation: 1628

To reduce the amount of warnings given by tensorflow all you need to do is define how much you want to avoid changing your os.environ variable here is a sample. 1 will make sure nothing is printed

import os.
import tensorflow as tf.
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1'

Upvotes: 2

Related Questions