Tensorflow won't STFU #12

Open
opened 2023-09-23 12:29:35 -06:00 by rs-sndid · 4 comments
Collaborator

Tensorflow 2.13.0 on x86_64, installed from pip, using CPU.

Tensorflow, by default, when run in the scripts outputs lines such as:

2023-09-22 14:42:37.059356: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2023-09-22 14:42:37.061652: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.
2023-09-22 14:42:37.112102: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.
2023-09-22 14:42:37.112659: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-09-22 14:42:37.971311: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT

This can be supressed by adding lines such as this to python:

os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'

As a side note, birdnetlib itself is quite noisy, so just getting a list of species spams the console with a bunch of prints that can't be controlled with a debug option. In Python, stdout and stderr can be controlled a bunch of different ways, but here's a way to silence birdnetlib:

from contextlib import redirect_stdout, redirect_stderr
# ...
f = io.StringIO()
with redirect_stdout(f), redirect_stderr(f):
    foo = SpeciesList()

The above silences all unwanted stdout/stderr except this line:

INFO: Created TensorFlow Lite XNNPACK delegate for CPU

It seems like the above should silence it, or perhaps another option, but nonesuch thing exists, afaict. The only two options are to rebuild tensorflow with debugging off (!!!! insanely tedious to suppress one line of INFO) or redirect in the shell ala 2>/dev/null.

The line in species.py that generates the noise:

self.meta_interpreter.allocate_tensors()

Others have noted this in tflite as well:

https://github.com/google/mediapipe/issues/3672
https://github.com/google/mediapipe/issues/2094
https://github.com/tensorflow/tensorflow/issues/58050

I don't see that the newly metioned TFLITE_LOG_SILENT or a variety of other approaches will silence it. I don't get how Python can't control the stderr of the freaking thing it is loading. Anyhoo.

Tensorflow 2.13.0 on x86_64, installed from pip, using CPU. Tensorflow, by default, when run in the scripts outputs lines such as: ``` 2023-09-22 14:42:37.059356: I tensorflow/core/util/port.cc:110] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 2023-09-22 14:42:37.061652: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used. 2023-09-22 14:42:37.112102: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used. 2023-09-22 14:42:37.112659: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. 2023-09-22 14:42:37.971311: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT ``` This can be supressed by adding lines such as this to python: ``` os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' ``` As a side note, `birdnetlib` itself is quite noisy, so just getting a list of species spams the console with a bunch of `prints` that can't be controlled with a debug option. In Python, stdout and stderr can be controlled a bunch of different ways, but here's a way to silence birdnetlib: ``` from contextlib import redirect_stdout, redirect_stderr # ... f = io.StringIO() with redirect_stdout(f), redirect_stderr(f): foo = SpeciesList() ``` The above silences all unwanted stdout/stderr except this line: ``` INFO: Created TensorFlow Lite XNNPACK delegate for CPU ``` It seems like the above should silence it, or perhaps another option, but nonesuch thing exists, afaict. The only two options are to rebuild tensorflow with debugging off (!!!! insanely tedious to suppress one line of `INFO`) or redirect in the shell ala `2>/dev/null`. The line in `species.py` that generates the noise: ``` self.meta_interpreter.allocate_tensors() ``` Others have noted this in tflite as well: https://github.com/google/mediapipe/issues/3672 https://github.com/google/mediapipe/issues/2094 https://github.com/tensorflow/tensorflow/issues/58050 I don't see that the newly metioned `TFLITE_LOG_SILENT` or a variety of other approaches will silence it. I don't get how Python can't control the stderr of the freaking thing it is loading. Anyhoo.
Poster
Collaborator

One of the various ways to silence other Tensorflow messages is this:

import silence_tensorflow.auto

That doesn't fix this noise though:

INFO: Created TensorFlow Lite XNNPACK delegate for CPU
One of the various ways to silence *other* Tensorflow messages is this: ``` import silence_tensorflow.auto ``` That doesn't fix this noise though: ``` INFO: Created TensorFlow Lite XNNPACK delegate for CPU ```
Poster
Collaborator

Minimal working example:

#!/usr/bin/env python3
import io
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
from contextlib import redirect_stdout, redirect_stderr
import silence_tensorflow.auto
from birdnetlib.species import SpeciesList

f = io.StringIO()
with redirect_stdout(f), redirect_stderr(f):
    foo = SpeciesList()

Outputs:

$ ./issue12.py 
INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Minimal working example: ``` #!/usr/bin/env python3 import io import os os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' from contextlib import redirect_stdout, redirect_stderr import silence_tensorflow.auto from birdnetlib.species import SpeciesList f = io.StringIO() with redirect_stdout(f), redirect_stderr(f): foo = SpeciesList() ``` Outputs: ``` $ ./issue12.py INFO: Created TensorFlow Lite XNNPACK delegate for CPU. ```
Poster
Collaborator

Wrapping in shell script for now:

#!/bin/bash
#
# STFU Tensorflow
# https://spacecruft.org/deepcrayon/sndid/issues/12
#
# Temporary workaround to silence Tensorflow

python3 sndid-list.py "$@" 2>/dev/null
Wrapping in shell script for now: ``` #!/bin/bash # # STFU Tensorflow # https://spacecruft.org/deepcrayon/sndid/issues/12 # # Temporary workaround to silence Tensorflow python3 sndid-list.py "$@" 2>/dev/null ```
Poster
Collaborator

This is slightly better, in that it only silences the obnoxious line, not other stderr:

python3 sndid.py "$@" {tmp}>&1 1>&2 2>&$tmp {tmp}>&- | \
  grep -v \
  -e 'INFO: Created TensorFlow Lite XNNPACK delegate for CPU.' 

But it breaks using other pipes and redirects when the script is run.
(E.g. the output from that can't be piped to grep to just search for one bird.)

This is slightly better, in that it only silences the obnoxious line, not other stderr: ``` python3 sndid.py "$@" {tmp}>&1 1>&2 2>&$tmp {tmp}>&- | \ grep -v \ -e 'INFO: Created TensorFlow Lite XNNPACK delegate for CPU.' ``` But it breaks using other pipes and redirects when the script is run. (E.g. the output from that can't be piped to grep to just search for one bird.)
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: deepcrayon/sndid#12
There is no content yet.