Skip to main content

Simple python package to shut up Tensorflow warnings and logs.

Project description

Pypi project Pypi total project downloads

Simple python package to shut up Tensorflow warnings and logs, letting you focus on the important errors.

How do I install this package?

As usual, just download it using pip:

pip install silence_tensorflow

How do I use it?

You only need to import the package before import Tensorflow:

from silence_tensorflow import silence_tensorflow
silence_tensorflow()
import tensorflow as tf

...

# your code

Can it be done within the import?

Sure, you can do everything with a single line by importing the submodule auto:

import silence_tensorflow.auto
import tensorflow as tf

...

# your code

How can I get pylint to ignore the unused import?

You can use the flag ‘disable=unused-import’ as such:

import silence_tensorflow.auto  # pylint: disable=unused-import
import tensorflow as tf

...

# your code

How can I get pylint to ignore the unused variable?

If you import silence_tensorflow in the context of a function you will get a different warning from pyling: unused variable. You can use the flag ‘disable=unused-variable’ as such:

def func():
    import silence_tensorflow.auto  # pylint: disable=unused-variable
    import tensorflow as tf

    ...

    # your code

How does this work under the hood?

This package will set the KMP_AFFINITY system variable to “noverbose”, TF_CPP_MIN_LOG_LEVEL to level 3 (only errors logged).

If you need a custom value for KMP_AFFINITY you should reset it after importing the package, as follows:

import os
from silence_tensorflow import silence_tensorflow
backup = os.environ["KMP_AFFINITY"]
silence_tensorflow()
os.environ["KMP_AFFINITY"] = backup

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

silence_tensorflow-1.2.1.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file silence_tensorflow-1.2.1.tar.gz.

File metadata

  • Download URL: silence_tensorflow-1.2.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.63.1 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.9

File hashes

Hashes for silence_tensorflow-1.2.1.tar.gz
Algorithm Hash digest
SHA256 b59e8ede929c46d244e1742c6e11ee91164d3e654ac6868061507031a788bf1c
MD5 dda2c2b04a99a5fcdb86364f230a8792
BLAKE2b-256 2e1c5c4aef549a6963b2c0eb90261a58d79af8fd1c893b613818a3ea6becfc2f

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page