text_plain_output_1.png
from glob import glob

import matplotlib.pyplot as plt

import tensorflow as tf

IMAGE_SIZE = 256
BATCH_SIZE = 16
MAX_TRAIN_IMAGES = 400

train_low_light_images = sorted(glob('/kaggle/input/lol-dataset/lol_dataset/our485/low/*'))[:MAX_TRAIN_IMAGES]
val_low_light_images = sorted(glob('/kaggle/input/lol-dataset/lol_dataset/our485/low/*'))[MAX_TRAIN_IMAGES:]
test_low_light_images = sorted(glob('/kaggle/input/lol-dataset/lol_dataset/eval15/low/*'))

def load_data(image_path):
    image = tf.io.read_file(image_path)
    image = tf.image.decode_png(image, channels=3)
    image = tf.image.resize(images=image, size=[IMAGE_SIZE, IMAGE_SIZE])
    image = image / 255.0
    return image
def data_generator(low_light_images):
    dataset = tf.data.Dataset.from_tensor_slices(low_light_images)
    dataset = dataset.map(load_data, num_parallel_calls=tf.data.AUTOTUNE)
    dataset = dataset.batch(BATCH_SIZE, drop_remainder=True)
    return dataset

train_dataset = data_generator(train_low_light_images)
val_dataset = data_generator(val_low_light_images)

zero_dce_model = ZeroDCE()
zero_dce_model.compile(learning_rate=0.0001)
history = zero_dce_model.fit(train_dataset, validation_data=val_dataset, epochs=100)
def plot_result(item):
    plt.plot(history.history[item], label=item)
    plt.plot(history.history['val_' + item], label='val_' + item)
    plt.xlabel('Epochs')
    plt.ylabel(item)
    plt.title('Train and Validation {} Over Epochs'.format(item), fontsize=14)
    plt.legend()
    plt.grid()
    plt.show()
plot_result('total_loss')
plot_result('illumination_smoothness_loss')
plot_result('spatial_constancy_loss')
plot_result('color_constancy_loss')
plot_result('exposure_loss')