Comments (5)
For this purpose, you need to write some lines of code to read and process a set of images.
You can check image_adaptive_lut_evaluation.py for reference.
from image-adaptive-3dlut.
from image-adaptive-3dlut.
from image-adaptive-3dlut.
非常感谢你的帮助,这份代码有些乱码,你能用txt文件保存再发给我吗?
…
Could you forward this txt to me, please? My mailbox is [email protected] and I'm curious if you've successfully tested a video in in demo_eval.py. I noticed that the author took part in the competition of NAIC2019 4K HDR and won the championship , which used this method for a video.
from image-adaptive-3dlut.
You can use the code below...
***Just describe the folder that contains the images on line 75 and edit the split method according to your file path on line 106
***Create a folder named 'output'
import argparse
import torch
import os
import numpy as np
import cv2
from PIL import Image
import time
from models_x import *
import torchvision_x_functional as TF_x
import torchvision.transforms.functional as TF
import glob
parser = argparse.ArgumentParser()
parser.add_argument("--image_dir", type=str, default="demo_images", help="directory of image")
parser.add_argument("--image_name", type=str, default="frame254.tif", help="name of image")
parser.add_argument("--input_color_space", type=str, default="sRGB", help="input color space: sRGB or XYZ")
parser.add_argument("--model_dir", type=str, default="pretrained_models", help="directory of pretrained models")
parser.add_argument("--output_dir", type=str, default="demo_results", help="directory to save results")
opt = parser.parse_args()
opt.model_dir = opt.model_dir + '/' + opt.input_color_space
#opt.image_path = opt.image_dir + '/' + opt.input_color_space + '/' + opt.image_name
os.makedirs(opt.output_dir, exist_ok=True)
# use gpu when detect cuda
cuda = True if torch.cuda.is_available() else False
# Tensor type
Tensor = torch.cuda.FloatTensor if cuda else torch.FloatTensor
criterion_pixelwise = torch.nn.MSELoss()
LUT0 = Generator3DLUT_identity()
LUT1 = Generator3DLUT_zero()
LUT2 = Generator3DLUT_zero()
#LUT3 = Generator3DLUT_zero()
#LUT4 = Generator3DLUT_zero()
classifier = Classifier()
trilinear_ = TrilinearInterpolation()
if cuda:
LUT0 = LUT0.cuda()
LUT1 = LUT1.cuda()
LUT2 = LUT2.cuda()
#LUT3 = LUT3.cuda()
#LUT4 = LUT4.cuda()
classifier = classifier.cuda()
criterion_pixelwise.cuda()
# Load pretrained models
LUTs = torch.load("%s/LUTs.pth" % opt.model_dir)
LUT0.load_state_dict(LUTs["0"])
LUT1.load_state_dict(LUTs["1"])
LUT2.load_state_dict(LUTs["2"])
#LUT3.load_state_dict(LUTs["3"])
#LUT4.load_state_dict(LUTs["4"])
LUT0.eval()
LUT1.eval()
LUT2.eval()
#LUT3.eval()
#LUT4.eval()
classifier.load_state_dict(torch.load("%s/classifier.pth" % opt.model_dir))
classifier.eval()
def generate_LUT(img):
pred = classifier(img).squeeze()
LUT = pred[0] * LUT0.LUT + pred[1] * LUT1.LUT + pred[2] * LUT2.LUT #+ pred[3] * LUT3.LUT + pred[4] * LUT4.LUT
return LUT
#Describe the folder that contains the images
path = glob.glob('***Images Folder Path***/*.jpg')
# ----------
# test
# ----------
# read image and transform to tensor
for file in path:
start = time.time()
if opt.input_color_space == 'sRGB':
img = cv2.imread(file)
img = TF.to_tensor(img).type(Tensor)
elif opt.input_color_space == 'XYZ':
img = cv2.imread(opt.image_path, -1)
img = np.array(img)
img = TF_x.to_tensor(img).type(Tensor)
img = img.unsqueeze(0)
LUT = generate_LUT(img)
# generate image
_, result = trilinear_(LUT, img)
# save image
ndarr = result.squeeze().mul_(255).add_(0.5).clamp_(0, 255).permute(1, 2, 0).to('cpu', torch.uint8).numpy()
im = Image.fromarray(ndarr)
im = np.array(im)
finish = time.time()
#you can change this split method for your file path
name_img = file.split('/')
name_img = name_img[5]
print(name_img)
#Create a folder named output
cv2.imwrite('output/'+ name_img , im)
print('Image was enhanced')
print('Time stamp: '+str(finish-start))
from image-adaptive-3dlut.
Related Issues (20)
- Eval images corrupt when training using unpaired dataset HOT 1
- 你好!当我将3DLUT模型的pth模型转换到onnx模型的时候,出现trilinearInterpolationFunction报错,该怎么解决呢?
- python3 image_adaptive_lut_train_paired.py
- Segmentation fault while training HOT 6
- how to solve 3dlut banding HOT 1
- Fatal Error (Is it a LUT?) HOT 3
- 3DLUT 参数量计算 HOT 2
- LUT 学习方式 HOT 1
- CPU和GPU的运行结果不一致
- AttributeError: module 'trilinear' has no attribute 'forward' HOT 3
- 关于LUT的问题 HOT 1
- About TV_3D loss
- 關於kernel size
- 为什么 classifier 采用复杂网络,性能狂掉?
- 直接跑预训练模型 视频调色比较稳定,但是自己训练的模型无法复现预训练效果?
- 请问LUT1和LUT2是初始化为零的表,无法更新,那让它们乘上权重有什么意义呢?
- Can you tell me how to convert hdrplus dataset to XYZ colorspace
- trilinear_kernel HOT 1
- Cube file
- Segmentation fault
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from image-adaptive-3dlut.