diff --git a/list_gpus.py b/list_gpus.py index ad0ce9c..2beed62 100644 --- a/list_gpus.py +++ b/list_gpus.py @@ -1,24 +1,26 @@ import os import sys +from contextlib import redirect_stderr, redirect_stdout -# Try to mute and then load Tensorflow and Keras -# Muting seems to not work lately on Linux in any way -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' -stdin = sys.stdin -sys.stdin = open(os.devnull, 'w') -stderr = sys.stderr -sys.stderr = open(os.devnull, 'w') -import tensorflow as tf -tf.logging.set_verbosity(tf.logging.ERROR) -from tensorflow.python.client import device_lib -sys.stdin = stdin -sys.stderr = stderr +# Suppress excessive console output and then load Tensorflow and Keras +# NOTE: This will potentially swallow important or useful information about +# problems with your tensorflow/keras installation, but it works. +# (Tested on Linux) +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # FATAL +with open(os.devnull, "w") as null: + with redirect_stderr(null), redirect_stdout(null): + import tensorflow as tf + from tensorflow.python.client import device_lib + from tensorflow.python.util import deprecation + +deprecation._PRINT_DEPRECATION_WARNINGS = False +tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) # Get list of all devices devices = device_lib.list_local_devices() # Print GPUs only -print('\n\n\nList of found GPUs:') +print('\n\n\nList of available CUDNN GPUs:') for device in devices: if device.device_type == 'GPU': print(device.physical_device_desc) diff --git a/sources/agent.py b/sources/agent.py index c2d6a98..e4b66c0 100644 --- a/sources/agent.py +++ b/sources/agent.py @@ -6,24 +6,26 @@ import numpy as np from sources import CarlaEnv, STOP, models, ACTIONS_NAMES from collections import deque +from contextlib import redirect_stderr, redirect_stdout from threading import Thread from dataclasses import dataclass import cv2 -# Try to mute and then load Tensorflow and Keras -# Muting seems to not work lately on Linux in any way -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' -stdin = sys.stdin -sys.stdin = open(os.devnull, 'w') -stderr = sys.stderr -sys.stderr = open(os.devnull, 'w') -import tensorflow as tf -tf.logging.set_verbosity(tf.logging.ERROR) -import keras.backend.tensorflow_backend as backend -from keras.optimizers import Adam -from keras.models import load_model, Model -sys.stdin = stdin -sys.stderr = stderr +# Suppress excessive console output and then load Tensorflow and Keras +# NOTE: This will potentially swallow important or useful information about +# problems with your tensorflow/keras installation, but it works. +# (Tested on Linux) +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # FATAL +with open(os.devnull, "w") as null: + with redirect_stderr(null), redirect_stdout(null): + import tensorflow as tf + import keras.backend.tensorflow_backend as backend + from tensorflow.python.util import deprecation + from keras.optimizers import Adam + from keras.models import load_model, Model + +deprecation._PRINT_DEPRECATION_WARNINGS = False +tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) # Agent class diff --git a/sources/models.py b/sources/models.py index 9f3efb0..84ba249 100644 --- a/sources/models.py +++ b/sources/models.py @@ -1,21 +1,23 @@ import os import sys import settings - -# Try to mute and then load Tensorflow and Keras -# Muting seems to not work lately on Linux in any way -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' -stdin = sys.stdin -sys.stdin = open(os.devnull, 'w') -stderr = sys.stderr -sys.stderr = open(os.devnull, 'w') -import tensorflow as tf -tf.logging.set_verbosity(tf.logging.ERROR) -from keras.applications.xception import Xception -from keras.models import Sequential, Model -from keras.layers import Dense, GlobalAveragePooling2D, Input, Concatenate, Conv2D, AveragePooling2D, Activation, Flatten -sys.stdin = stdin -sys.stderr = stderr +from contextlib import redirect_stderr, redirect_stdout + +# Suppress excessive console output and then load Tensorflow and Keras +# NOTE: This will potentially swallow important or useful information about +# problems with your tensorflow/keras installation, but it works. +# (Tested on Linux) +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # FATAL +with open(os.devnull, "w") as null: + with redirect_stderr(null), redirect_stdout(null): + import tensorflow as tf + from tensorflow.python.util import deprecation + from keras.applications.xception import Xception + from keras.models import Sequential, Model + from keras.layers import Dense, GlobalAveragePooling2D, Input, Concatenate, Conv2D, AveragePooling2D, Activation, Flatten + +deprecation._PRINT_DEPRECATION_WARNINGS = False +tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) MODEL_NAME_PREFIX = '' diff --git a/sources/tensorboard.py b/sources/tensorboard.py index 1a31a9b..b580686 100644 --- a/sources/tensorboard.py +++ b/sources/tensorboard.py @@ -1,18 +1,20 @@ import os import sys +from contextlib import redirect_stderr, redirect_stdout -# Try to mute and then load TensorFlow and Keras -# Muting seems to not work lately on Linux in any way -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' -stdin = sys.stdin -sys.stdin = open(os.devnull, 'w') -stderr = sys.stderr -sys.stderr = open(os.devnull, 'w') -import tensorflow as tf -tf.logging.set_verbosity(tf.logging.ERROR) -from keras.callbacks import Callback -sys.stdin = stdin -sys.stderr = stderr +# Suppress excessive console output and then load Tensorflow and Keras +# NOTE: This will potentially swallow important or useful information about +# problems with your tensorflow/keras installation, but it works. +# (Tested on Linux) +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # FATAL +with open(os.devnull, "w") as null: + with redirect_stderr(null), redirect_stdout(null): + import tensorflow as tf + from tensorflow.python.util import deprecation + from keras.callbacks import Callback + +deprecation._PRINT_DEPRECATION_WARNINGS = False +tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) # Own Tensorboard class giving ability to use single writer across multiple .fit() calls # Allows us also to easily log additional data diff --git a/sources/trainer.py b/sources/trainer.py index 366b4f9..2e1d1f3 100644 --- a/sources/trainer.py +++ b/sources/trainer.py @@ -3,6 +3,7 @@ import settings from sources import ARTDQNAgent, TensorBoard, STOP, ACTIONS, ACTIONS_NAMES from collections import deque +from contextlib import redirect_stderr, redirect_stdout import time import random import numpy as np @@ -11,18 +12,19 @@ from dataclasses import dataclass from threading import Thread -# Try to mute and then load Tensorflow -# Muting seems to not work lately on Linux in any way -os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' -stdin = sys.stdin -sys.stdin = open(os.devnull, 'w') -stderr = sys.stderr -sys.stderr = open(os.devnull, 'w') -import tensorflow as tf -tf.logging.set_verbosity(tf.logging.ERROR) -import keras.backend.tensorflow_backend as backend -sys.stdin = stdin -sys.stderr = stderr +# Suppress excessive console output and then load Tensorflow and Keras +# NOTE: This will potentially swallow important or useful information about +# problems with your tensorflow/keras installation, but it works. +# (Tested on Linux) +os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # FATAL +with open(os.devnull, "w") as null: + with redirect_stderr(null), redirect_stdout(null): + import tensorflow as tf + import keras.backend.tensorflow_backend as backend + from tensorflow.python.util import deprecation + +deprecation._PRINT_DEPRECATION_WARNINGS = False +tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR) # Trainer class