Tensorflow "decode_png" keeps printing "Cleanup called..."
Asked Answered
A

3

6

I'm using tensorflow to open some .png images and every image it opens, an annoying message is printed.

def open_img(path):
    img = tf.io.read_file(path)
    img = tf.io.decode_png(img)
    return tf.image.resize(img, [IMG_HEIGHT, IMG_WIDTH])

Every time i try to open an image it says "Cleanup called...", even while training:

enter image description here

(This code is running on Kaggle)

tensorflow version: 2.6.3

How can i solve this annoying thing please?

Aluino answered 22/4, 2022 at 13:10 Comment(0)
J
4

Updating my TensorFlow installation to version 2.8 fixed the issue for me.

Jobi answered 2/5, 2022 at 9:6 Comment(1)
To add to that, you need to restart the kernel after the update for the fix to occur if you are using kaggle.Subarid
M
1

If you're running the code on Kaggle, upgrading Tensorflow to 2.8 will break CuDNN dependencies for GPU. I found that downgrading Tensorflow to 2.4.1 one will remove the debugging message while being able to work with GPU.

Midships answered 18/7, 2022 at 0:53 Comment(0)
U
1

I believe, these "Cleanup called..." lines might be generated by some C++ code running under the hood of TF, as I was not able to redirect them to a file using redirect_stdout(). Technically, it would be best to intercept those lines and just not output them or dump them to smth like /dev/null. E.g., here, Eli Bendersky showcases how to redirect C-level output, but in my case it didn't work out with Python 3.7. Perhaps, Eli's code needs adjustment for a Python version newer than 3.4.

Concerning the given answers with upgrading/downgrading, this likely won't work with committed Kaggle notebooks as, I believe, there is no way to restart the kernel once the notebook is committed.

For committed Kaggle notebooks, there is the following workaround w/o upgrading/downgrading anything: if you need to view the output of a cell that produces "Cleanup called…" later, log it to a file or both to a file and the console (here's a code snippet for doing so), and invoke the following code at the end of the cell:

from IPython.display import clear_output
clear_output()

This will clear the output of that cell so that, once you open the "Notebook" tab of the committed notebook after it's been finished, it won't be littered with "Cleanup called…" lines and, as such, will open swiftly. Simple logging to a file (like in the above linked snipped) will not capture "Cleanup called…" lines, so one will be able to view the entire log of that cell in that log file in the "Data" tab of the committed notebook. The "Logs" tab, sadly, will still be cluttered with "Cleanup called…" lines.

Unbiased answered 3/8, 2022 at 10:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.