Skip to content

Commit

Permalink
Prevent reimports for TF (cvat-ai#1713)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiltsov-max authored and Fernando Martínez González committed Aug 3, 2020
1 parent bddcfa7 commit 4a03ca2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions datumaro/datumaro/util/tf_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,23 @@ def check_import():
def import_tf(check=True):
import sys

tf = sys.modules.get('tensorflow', None)
if tf is not None:
not_found = object()
tf = sys.modules.get('tensorflow', not_found)
if tf is None:
import tensorflow as tf # emit default error
elif tf is not not_found:
return tf

# Reduce output noise, https://stackoverflow.com/questions/38073432/how-to-suppress-verbose-tensorflow-logging
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

if check:
check_import()
try:
check_import()
except Exception:
sys.modules['tensorflow'] = None # prevent further import
raise

import tensorflow as tf

Expand Down

0 comments on commit 4a03ca2

Please sign in to comment.