Instructionsο
We can skip the next cell if neural_de was installed from pip install.
[1]:
import sys
sys.path.append("..")
import time
print(sys.version)
3.9.21 | packaged by conda-forge | (main, Dec 5 2024, 13:51:40)
[GCC 13.3.0]
Letβs import from neural_de the brightness method
[2]:
from neural_de.transformations.brightness_enhancer import BrightnessEnhancer
import tensorflow as tf
2025-03-20 09:01:05.140737: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 AVX512F AVX512_VNNI FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2025-03-20 09:01:05.289629: I tensorflow/core/util/util.cc:169] 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`.
2025-03-20 09:01:05.324303: E tensorflow/stream_executor/cuda/cuda_blas.cc:2981] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2025-03-20 09:01:05.867344: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer.so.7'; dlerror: libnvinfer.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /opt/conda/envs/env-neural39/lib/python3.9/site-packages/cv2/../../lib64:
2025-03-20 09:01:05.867412: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libnvinfer_plugin.so.7'; dlerror: libnvinfer_plugin.so.7: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /opt/conda/envs/env-neural39/lib/python3.9/site-packages/cv2/../../lib64:
2025-03-20 09:01:05.867420: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Cannot dlopen some TensorRT libraries. If you would like to use Nvidia GPU with TensorRT, please make sure the missing libraries mentioned above are installed properly.
We load an example image
[3]:
import matplotlib.pyplot as plt
from pathlib import Path
import cv2
import os
print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))
start=time.time()
input_path = Path('../examples/images/test_brightness_car.jpg')
image = cv2.imread(str(input_path))
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
plt.title(image.shape)
plt.imshow(image)
Num GPUs Available: 0
2025-03-20 09:01:07.078976: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcusolver.so.11'; dlerror: libcusolver.so.11: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /opt/conda/envs/env-neural39/lib/python3.9/site-packages/cv2/../../lib64:
2025-03-20 09:01:07.079041: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1934] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
[3]:
<matplotlib.image.AxesImage at 0x7f08a01a3250>

Enhancing an imageο
We create an instance of BrightnessEnhancer :
[4]:
image_enhancer = BrightnessEnhancer()
[03-20 09:01:07] {/home/jovyan/Maturation/NeuralDE/examples/../neural_de/utils/twe_logger.py:123} INFO - Logger: name: neural_de_logger, handlers: [<StreamHandler stdout (DEBUG)>]
We apply the transform method to any number of images. For example, one image and then two images in a batch.
[5]:
enhanced_images = image_enhancer.transform([image])
[03-20 09:01:07] {/home/jovyan/Maturation/NeuralDE/examples/../neural_de/transformations/brightness_enhancer.py:55} INFO - Image normalized as between [0;1]
[6]:
plt.figure(figsize=(10,7))
plt.subplot(1,2,1)
plt.title("Before")
plt.imshow(image)
plt.subplot(1,2,2)
plt.title("After")
plt.imshow(enhanced_images[0])
plt.show()

Now an example with two images in a batch.
[7]:
ROOT_DIR = "../examples/images"
image_path_list = []
image_path_list.append(ROOT_DIR + "/test_brightness_xmass_tree.jpg")
image_path_list.append(ROOT_DIR + "/test_brightness_car.jpg")
image_list = []
for image_path_str in image_path_list:
input_path = Path(image_path_str)
image = cv2.imread(str(input_path))
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image_list.append(image)
plt.figure()
plt.title(image.shape)
plt.imshow(image)


[8]:
enhanced_images = image_enhancer.transform(image_list)
[03-20 09:01:08] {/home/jovyan/Maturation/NeuralDE/examples/../neural_de/transformations/brightness_enhancer.py:55} INFO - Image normalized as between [0;1]
[03-20 09:01:09] {/home/jovyan/Maturation/NeuralDE/examples/../neural_de/transformations/brightness_enhancer.py:55} INFO - Image normalized as between [0;1]
[9]:
for image_index_ in range(len(image_list)):
plt.figure(figsize=(10,7))
plt.subplot(1,2,1)
plt.title("Before")
plt.imshow(image_list[image_index_])
plt.subplot(1,2,2)
plt.title("After")
plt.imshow(enhanced_images[image_index_])
plt.show()


[10]:
end=time.time()
print("final duration : ",end-start)
final duration : 4.178200960159302
[ ]:
[ ]: