DeepTrackAI / DeepTrack2

DeepTrack2
MIT License
157 stars 47 forks source link

Reduce warnings on GPU use #172

Closed gorkamunoz closed 6 months ago

gorkamunoz commented 1 year ago

Hi! Is there a way to prevent the warnings below from appearing? I understand that you may want to keep the cupy warning. The rest is due to Tensorflow, which in my case happens because I use a CUDA version not yet supported by Tensorflow.

image

There is an easy workaround, as explained here. You just need to add the following before importing tensorflow:

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

I added this to my code, but maybe you want to add something similar directly in deeptrack? Just to note, the version of tensorflow that I have was automatically installed when installing deeptrack.

BenjaminMidtvedt commented 1 year ago

I'm hesitant to change environment variables during import of deeptrack. First, it would forcibly overwrite any settings the user has set themselves. Second, it would only work if the default behavior is to silence the warnings, which I also hesitate to do. The only way to let the user configure the behavior of the import of deeptrack not to silence the warnings would be through another environment variable. At that point, one may as well just use the tensorflow variable.

However, I'm currently planning on deferring the import of tensorflow internally until it is used. The goal is to speed up the initial import of deeptrack. However, it can also make it possible to silence tensorflow. For example

import deeptrack as dt
dt.config.silence_warnings()

It is not a small amount of work to implement however, so I'd suspect it will not be implemented in the near future. I'd keep using the environment variable for now.

Perhaps I can catch the warnings and add a line on how to silence them?

If you have any other ideas, I'm open to suggestions. I also find the warnings irritating.

gorkamunoz commented 1 year ago

Hi! I understand your point, I think you are right about it. Also, deferring the import of Tensorflow would really help. I guess it is only used for the ML part of deeptrack? For instance, I was reluctant of putting deeptrack in the requirements of ANDI because it automatically installs tensorflow, which is usually quite heavy, and we don't use any tensorflow function (that I know, you may know better). Nonetheless, I guess you want to keep tensorflow in the requirements of deeptrack?

BenjaminMidtvedt commented 1 year ago

I completely understand that. In fact, we are currently working on separating deeptrack from tensorflow. We are moving to PyTorch due to tensorflow's abandonment of windows. The new integration with PyTorch will be through a separate package, as to not bloat deeptrack. Once this is complete, we can consider moving tensorflow to an optional dependency.

@giovannivolpe @JesusPinedaC what do you think?

giovannivolpe commented 1 year ago

Yes, I agree. The warnings are unfortunate, but they should be solved once we have completed the revision as outlined by Benjamin.