enhance-me / enhance_me /commons.py
geekyrakshit's picture
added mirnet class for training and inference
c8d52e7
raw
history blame
1.14 kB
import os
import wandb
import tensorflow as tf
import matplotlib.pyplot as plt
def read_image(image_path):
image = tf.io.read_file(image_path)
image = tf.image.decode_png(image, channels=3)
image.set_shape([None, None, 3])
image = tf.cast(image, dtype=tf.float32) / 255.0
return image
def peak_signal_noise_ratio(y_true, y_pred):
return tf.image.psnr(y_pred, y_true, max_val=255.0)
def plot_results(images, titles, figure_size=(12, 12)):
fig = plt.figure(figsize=figure_size)
for i in range(len(images)):
fig.add_subplot(1, len(images), i + 1).set_title(titles[i])
_ = plt.imshow(images[i])
plt.axis("off")
plt.show()
def closest_number(n, m):
q = int(n / m)
n1 = m * q
if (n * m) > 0:
n2 = m * (q + 1)
else:
n2 = m * (q - 1)
if abs(n - n1) < abs(n - n2):
return n1
return n2
def init_wandb(project_name, experiment_name, wandb_api_key):
if project_name is not None and experiment_name is not None:
os.environ['WANDB_API_KEY'] = wandb_api_key
wandb.init(project=project_name, name=experiment_name)