-
Notifications
You must be signed in to change notification settings - Fork 6
/
val.py
42 lines (35 loc) · 1.12 KB
/
val.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import cv2
import sys
import glob
import time
import math
import argparse
import numpy as np
import tensorflow as tf
import generate_HDR_dataset
from HDR import *
from PIL import Image
from tensorflow.keras import Model, Input
from tensorflow.keras.layers import Concatenate, Conv2D, Input
def get_test_data(images_path):
imgs_np = np.zeros([1, 3, 256, 256, 6])
file1 = open(os.path.join(images_path, 'exposure.txt'), 'r')
Lines = file1.readlines()
t = [float(i) for i in Lines]
for j, f in enumerate(sorted(glob.glob(os.path.join(images_path, '*.tif')))):
ldr = (cv2.imread(f)/255.0).astype(np.float32)
ldr = cv2.resize(ldr, (256,256))
hdr = ldr**2.2 / (2**t[j])
# ldr = ldr *2.0 - 1
# hdr = hdr * 2.0 - 1
X = np.concatenate([ldr, hdr], axis=-1)
imgs_np[0,j,:,:,:] = X
return imgs_np
def run(config, model):
MU = 5000.0
SDR = get_test_data(config.test_path)
rs = model.predict(SDR)
out = rs[0]
out = tf.math.log(1 + MU * out) / tf.math.log(1 + MU)
cv2.imwrite(os.path.join(config.test_path, 'hdr.jpg'), np.uint8(out*255))