code update

GIMP3-ML
DESKTOP-F04AGRR\Kritik Soman 3 years ago
parent a0d3e3e1c2
commit e69ab9f8d0

@ -11,7 +11,17 @@ import cv2
from data import colorize_image as CI
def get_deepcolor(layerimg, layerc = None, cpu_flag = False):
def get_weight_path():
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
return weight_path
def get_deepcolor(layerimg, layerc=None, cpu_flag=False, weight_path=None):
if weight_path is None:
weight_path = get_weight_path()
if layerc is not None:
input_ab = cv2.cvtColor(layerc[:, :, 0:3].astype(np.float32) / 255, cv2.COLOR_RGB2LAB)
mask = layerc[:, :, 3] > 0
@ -38,10 +48,7 @@ def get_deepcolor(layerimg, layerc = None, cpu_flag = False):
if __name__ == "__main__":
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
weight_path = get_weight_path()
image1 = cv2.imread(os.path.join(weight_path, '..', "cache0.png"), cv2.IMREAD_UNCHANGED)
image2 = cv2.imread(os.path.join(weight_path, '..', "cache1.png"), cv2.IMREAD_UNCHANGED)
with open(os.path.join(weight_path, '..', 'gimp_ml_run.pkl'), 'rb') as file:
@ -51,11 +58,11 @@ if __name__ == "__main__":
image1.shape[0] * image1.shape[1] * 4) > 0.8:
image2 = image2[:, :, [2, 1, 0]]
image1 = image1[:, :, [2, 1, 0, 3]]
output = get_deepcolor(image2, image1, cpu_flag=force_cpu)
output = get_deepcolor(image2, image1, cpu_flag=force_cpu, weight_path=weight_path)
else:
image1 = image1[:, :, [2, 1, 0]]
image2 = image2[:, :, [2, 1, 0, 3]]
output = get_deepcolor(image1, image2, cpu_flag=force_cpu)
output = get_deepcolor(image1, image2, cpu_flag=force_cpu, weight_path=weight_path)
cv2.imwrite(os.path.join(weight_path, '..', 'cache.png'), output[:, :, ::-1])
# with open(os.path.join(weight_path, 'gimp_ml_run.pkl'), 'wb') as file:
# pickle.dump({"run_success": True}, file)

@ -11,7 +11,17 @@ import numpy as np
import torch
def get_deblur(img, cpu_flag=False):
def get_weight_path():
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
return weight_path
def get_deblur(img, cpu_flag=False, weight_path=None):
if weight_path is None:
weight_path=get_weight_path()
predictor = Predictor(weights_path=os.path.join(weight_path, 'deblur', 'best_fpn.h5'), cf=cpu_flag)
if img.shape[2] == 4: # get rid of alpha channel
img = img[:, :, 0:3]
@ -20,15 +30,12 @@ def get_deblur(img, cpu_flag=False):
if __name__ == "__main__":
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
weight_path = get_weight_path()
image = cv2.imread(os.path.join(weight_path, '..', "cache.png"))[:, :, ::-1]
with open(os.path.join(weight_path, '..', 'gimp_ml_run.pkl'), 'rb') as file:
data_output = pickle.load(file)
force_cpu = data_output["force_cpu"]
output = get_deblur(image, cpu_flag=force_cpu)
output = get_deblur(image, cpu_flag=force_cpu, weight_path=weight_path)
cv2.imwrite(os.path.join(weight_path, '..', 'cache.png'), output[:, :, ::-1])
# with open(os.path.join(weight_path, 'gimp_ml_run.pkl'), 'wb') as file:
# pickle.dump({"run_success": True}, file)

@ -11,7 +11,17 @@ import numpy as np
import cv2
def get_dehaze(data_hazy, cpu_flag=False):
def get_weight_path():
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
return weight_path
def get_dehaze(data_hazy, cpu_flag=False, weight_path=None):
if weight_path is None:
weight_path = get_weight_path()
data_hazy = (data_hazy / 255.0)
data_hazy = torch.from_numpy(data_hazy).float()
data_hazy = data_hazy.permute(2, 0, 1)
@ -25,24 +35,22 @@ def get_dehaze(data_hazy, cpu_flag=False):
dehaze_net.load_state_dict(torch.load(os.path.join(weight_path, 'deepdehaze', 'dehazer.pth'),
map_location=torch.device("cpu")))
# gimp.progress_update(float(0.005))
# gimp.displays_flush()
data_hazy = data_hazy.unsqueeze(0)
clean_image = dehaze_net(data_hazy)
out = clean_image.detach().cpu().numpy()[0, :, :, :] * 255
out = np.clip(np.transpose(out, (1, 2, 0)), 0, 255).astype(np.uint8)
return out
# gimp.progress_update(float(0.005))
# gimp.displays_flush()
data_hazy = data_hazy.unsqueeze(0)
clean_image = dehaze_net(data_hazy)
out = clean_image.detach().cpu().numpy()[0, :, :, :] * 255
out = np.clip(np.transpose(out, (1, 2, 0)), 0, 255).astype(np.uint8)
return out
if __name__ == "__main__":
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
weight_path = get_weight_path()
image = cv2.imread(os.path.join(weight_path, '..', "cache.png"))[:, :, ::-1]
with open(os.path.join(weight_path, '..', 'gimp_ml_run.pkl'), 'rb') as file:
data_output = pickle.load(file)
force_cpu = data_output["force_cpu"]
output = get_dehaze(image, cpu_flag=force_cpu)
output = get_dehaze(image, cpu_flag=force_cpu, weight_path=weight_path)
cv2.imwrite(os.path.join(weight_path, '..', 'cache.png'), output[:, :, ::-1])
# with open(os.path.join(weight_path, 'gimp_ml_run.pkl'), 'wb') as file:
# pickle.dump({"run_success": True}, file)

@ -12,7 +12,17 @@ import cv2
import numpy as np
def get_denoise(Img, cpu_flag=False):
def get_weight_path():
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
return weight_path
def get_denoise(Img, cpu_flag=False, weight_path=None):
if weight_path is None:
weight_path = get_weight_path()
w, h, _ = Img.shape
opt = Namespace(color=1, cond=1, delog='logsdc', ext_test_noise_level=None,
k=0, keep_ind=None, mode='MC', num_of_layers=20, out_dir='results_bc',
@ -86,15 +96,12 @@ def get_denoise(Img, cpu_flag=False):
if __name__ == "__main__":
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
weight_path = get_weight_path()
image = cv2.imread(os.path.join(weight_path, '..', "cache.png"))[:, :, ::-1]
with open(os.path.join(weight_path, '..', 'gimp_ml_run.pkl'), 'rb') as file:
data_output = pickle.load(file)
force_cpu = data_output["force_cpu"]
output = get_denoise(image, cpu_flag=force_cpu)
output = get_denoise(image, cpu_flag=force_cpu, weight_path=weight_path)
cv2.imwrite(os.path.join(weight_path, '..', 'cache.png'), output[:, :, ::-1])
# with open(os.path.join(weight_path, 'gimp_ml_run.pkl'), 'wb') as file:
# pickle.dump({"run_success": True}, file)

@ -13,8 +13,17 @@ from enlighten_models.models import create_model
from enlighten_data.base_dataset import get_transform
def get_weight_path():
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
return weight_path
def get_enlighten(input_image, cpu_flag=False):
def get_enlighten(input_image, cpu_flag=False, weight_path=None):
if weight_path is None:
weight_path = get_weight_path()
opt = Namespace(D_P_times2=False, IN_vgg=False, aspect_ratio=1.0, batchSize=1,
checkpoints_dir=weight_path, dataroot='test_dataset',
dataset_mode='unaligned', display_id=1, display_port=8097,
@ -56,15 +65,12 @@ def get_enlighten(input_image, cpu_flag=False):
if __name__ == "__main__":
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
weight_path = get_weight_path()
image = cv2.imread(os.path.join(weight_path, '..', "cache.png"))[:, :, ::-1]
with open(os.path.join(weight_path, '..', 'gimp_ml_run.pkl'), 'rb') as file:
data_output = pickle.load(file)
force_cpu = data_output["force_cpu"]
output = get_enlighten(image, cpu_flag=force_cpu)
output = get_enlighten(image, cpu_flag=force_cpu, weight_path=weight_path)
cv2.imwrite(os.path.join(weight_path, '..', 'cache.png'), output[:, :, ::-1])
# with open(os.path.join(weight_path, 'gimp_ml_run.pkl'), 'wb') as file:
# pickle.dump({"run_success": True}, file)

@ -35,6 +35,14 @@ colors = np.array([[0, 0, 0],
colors = colors.astype(np.uint8)
def get_weight_path():
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
return weight_path
def getlabelmat(mask, idx):
x = np.zeros((mask.shape[0], mask.shape[1], 3))
x[mask == idx, 0] = colors[idx][0]
@ -50,7 +58,9 @@ def colorMask(mask):
return np.uint8(x)
def get_face(input_image, cpu_flag=False):
def get_face(input_image, cpu_flag=False, weight_path=None):
if weight_path is None:
weight_path = get_weight_path()
save_pth = os.path.join(weight_path, 'faceparse', '79999_iter.pth')
input_image = Image.fromarray(input_image)
@ -89,15 +99,12 @@ def get_face(input_image, cpu_flag=False):
if __name__ == "__main__":
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
weight_path = get_weight_path()
image = cv2.imread(os.path.join(weight_path, '..', "cache.png"))[:, :, ::-1]
with open(os.path.join(weight_path, '..', 'gimp_ml_run.pkl'), 'rb') as file:
data_output = pickle.load(file)
force_cpu = data_output["force_cpu"]
output = get_face(image, cpu_flag=force_cpu)
output = get_face(image, cpu_flag=force_cpu, weight_path=weight_path)
cv2.imwrite(os.path.join(weight_path, '..', 'cache.png'), output[:, :, ::-1])
# with open(os.path.join(weight_path, 'gimp_ml_run.pkl'), 'wb') as file:
# pickle.dump({"run_success": True}, file)

@ -14,6 +14,14 @@ from DFNet_core import DFNet
from RefinementNet_core import RefinementNet
def get_weight_path():
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
return weight_path
def to_numpy(tensor):
tensor = tensor.mul(255).byte().data.cpu().numpy()
tensor = np.transpose(tensor, [0, 2, 3, 1])
@ -109,7 +117,9 @@ def pad_image(image):
return padded
def get_inpaint(img, mask, cpu_flag=False):
def get_inpaint(img, mask, cpu_flag=False, weight_path=None):
if weight_path is None:
weight_path = get_weight_path()
if torch.cuda.is_available() and not cpu_flag:
device = torch.device('cuda')
else:
@ -143,10 +153,7 @@ def get_inpaint(img, mask, cpu_flag=False):
if __name__ == "__main__":
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
weight_path = get_weight_path()
image1 = cv2.imread(os.path.join(weight_path, '..', "cache0.png"))[:, :, ::-1]
image2 = cv2.imread(os.path.join(weight_path, '..', "cache1.png"))[:, :, ::-1]
with open(os.path.join(weight_path, '..', 'gimp_ml_run.pkl'), 'rb') as file:
@ -154,9 +161,9 @@ if __name__ == "__main__":
force_cpu = data_output["force_cpu"]
if (np.sum(image1 == [0, 0, 0]) + np.sum(image1 == [255, 255, 255])) / (
image1.shape[0] * image1.shape[1] * 3) > 0.8:
output = get_inpaint(image2, image1, cpu_flag=force_cpu)
output = get_inpaint(image2, image1, cpu_flag=force_cpu, weight_path=weight_path)
else:
output = get_inpaint(image1, image2, cpu_flag=force_cpu)
output = get_inpaint(image1, image2, cpu_flag=force_cpu, weight_path=weight_path)
cv2.imwrite(os.path.join(weight_path, '..', 'cache.png'), output[:, :, ::-1])
# with open(os.path.join(weight_path, 'gimp_ml_run.pkl'), 'wb') as file:
# pickle.dump({"run_success": True}, file)

@ -11,8 +11,17 @@ from torch.nn import functional as F
from rife_model import RIFE
import numpy as np
def get_weight_path():
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
return weight_path
def get_inter(img_s, img_e, string_path, cpu_flag=False):
def get_inter(img_s, img_e, string_path, cpu_flag=False, weight_path=None):
if weight_path is None:
weight_path = get_weight_path()
exp = 4
out_path = string_path
@ -68,17 +77,14 @@ def get_inter(img_s, img_e, string_path, cpu_flag=False):
if __name__ == "__main__":
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
weight_path = get_weight_path()
image1 = cv2.imread(os.path.join(weight_path, '..', "cache0.png"))[:, :, ::-1]
image2 = cv2.imread(os.path.join(weight_path, '..', "cache1.png"))[:, :, ::-1]
with open(os.path.join(weight_path, '..', 'gimp_ml_run.pkl'), 'rb') as file:
data_output = pickle.load(file)
force_cpu = data_output["force_cpu"]
gio_file = data_output["gio_file"]
get_inter(image1, image2, gio_file, cpu_flag=force_cpu)
get_inter(image1, image2, gio_file, cpu_flag=force_cpu, weight_path=weight_path)
# cv2.imwrite(os.path.join(weight_path, '..', 'cache.png'), output[:, :, [2, 1, 0, 3]])
# with open(os.path.join(weight_path, 'gimp_ml_run.pkl'), 'wb') as file:

@ -14,7 +14,17 @@ import numpy as np
from deploy import inference_img_whole
def get_matting(image, mask, cpu_flag=False):
def get_weight_path():
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
return weight_path
def get_matting(image, mask, cpu_flag=False, weight_path=None):
if weight_path is None:
weight_path = get_weight_path()
if image.shape[2] == 4: # get rid of alpha channel
image = image[:, :, 0:3]
if mask.shape[2] == 4: # get rid of alpha channel
@ -57,10 +67,7 @@ def get_matting(image, mask, cpu_flag=False):
if __name__ == "__main__":
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
weight_path = get_weight_path()
image1 = cv2.imread(os.path.join(weight_path, '..', "cache0.png"))[:, :, ::-1]
image2 = cv2.imread(os.path.join(weight_path, '..', "cache1.png"))[:, :, ::-1]
with open(os.path.join(weight_path, '..', 'gimp_ml_run.pkl'), 'rb') as file:
@ -68,9 +75,9 @@ if __name__ == "__main__":
force_cpu = data_output["force_cpu"]
if (np.sum(image1 == [0, 0, 0]) + np.sum(image1 == [255, 255, 255]) + np.sum(image1 == [128, 128, 128])) / (
image1.shape[0] * image1.shape[1] * 3) > 0.8:
output = get_matting(image2, image1, cpu_flag=force_cpu)
output = get_matting(image2, image1, cpu_flag=force_cpu, weight_path=weight_path)
else:
output = get_matting(image1, image2, cpu_flag=force_cpu)
output = get_matting(image1, image2, cpu_flag=force_cpu, weight_path=weight_path)
cv2.imwrite(os.path.join(weight_path, '..', 'cache.png'), output[:, :, [2, 1, 0, 3]])
# with open(os.path.join(weight_path, 'gimp_ml_run.pkl'), 'wb') as file:
# pickle.dump({"run_success": True}, file)

@ -10,10 +10,22 @@ from monodepth_net import MonoDepthNet
import MiDaS_utils as MiDaS_utils
import numpy as np
import cv2
# import torch
def get_weight_path():
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
return weight_path
def get_mono_depth(input_image, cpu_flag=False, weight_path=None):
if weight_path is None:
weight_path = get_weight_path()
def get_mono_depth(input_image, cpu_flag=False):
image = input_image / 255.0
out = run_depth(image, os.path.join(weight_path, 'MiDaS', 'model.pt'), MonoDepthNet, MiDaS_utils, target_w=640,
f=cpu_flag)
@ -24,15 +36,12 @@ def get_mono_depth(input_image, cpu_flag=False):
if __name__ == "__main__":
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
weight_path = get_weight_path()
image = cv2.imread(os.path.join(weight_path, '..', "cache.png"))[:, :, ::-1]
with open(os.path.join(weight_path, '..', 'gimp_ml_run.pkl'), 'rb') as file:
data_output = pickle.load(file)
force_cpu = data_output["force_cpu"]
output = get_mono_depth(image, cpu_flag=force_cpu)
output = get_mono_depth(image, cpu_flag=force_cpu, weight_path=weight_path)
cv2.imwrite(os.path.join(weight_path, '..', 'cache.png'), output[:, :, ::-1])
# with open(os.path.join(weight_path, 'gimp_ml_run.pkl'), 'wb') as file:
# pickle.dump({"run_success": True}, file)

@ -13,7 +13,17 @@ import cv2
import os
def get_seg(input_image, cpu_flag=False):
def get_weight_path():
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
return weight_path
def get_seg(input_image, cpu_flag=False, weight_path=None):
if weight_path is None:
weight_path = get_weight_path()
model = torch.load(os.path.join(weight_path, 'deeplabv3', 'deeplabv3+model.pt'))
model.eval()
preprocess = transforms.Compose([
@ -46,15 +56,12 @@ def get_seg(input_image, cpu_flag=False):
if __name__ == "__main__":
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
weight_path = get_weight_path()
image = cv2.imread(os.path.join(weight_path, '..', "cache.png"))[:, :, ::-1]
with open(os.path.join(weight_path, '..', 'gimp_ml_run.pkl'), 'rb') as file:
data_output = pickle.load(file)
force_cpu = data_output["force_cpu"]
output = get_seg(image, cpu_flag=force_cpu)
output = get_seg(image, cpu_flag=force_cpu, weight_path=weight_path)
cv2.imwrite(os.path.join(weight_path, '..', 'cache.png'), output[:, :, ::-1])
# with open(os.path.join(weight_path, 'gimp_ml_run.pkl'), 'wb') as file:
# pickle.dump({"run_success": True}, file)

@ -13,7 +13,17 @@ from PIL import Image
import cv2
def get_super(input_image, s=4, cpu_flag=False, fFlag=True):
def get_weight_path():
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
return weight_path
def get_super(input_image, s=4, cpu_flag=False, fFlag=True, weight_path=None):
if weight_path is None:
weight_path = get_weight_path()
opt = Namespace(cuda=torch.cuda.is_available() and not cpu_flag,
model=os.path.join(weight_path, "superresolution", "model_srresnet.pth"),
dataset='Set5', scale=s, gpus=0)
@ -74,10 +84,7 @@ def get_super(input_image, s=4, cpu_flag=False, fFlag=True):
if __name__ == "__main__":
config_path = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(config_path, 'gimp_ml_config.pkl'), 'rb') as file:
data_output = pickle.load(file)
weight_path = data_output["weight_path"]
weight_path = get_weight_path()
image = cv2.imread(os.path.join(weight_path, '..', "cache.png"))[:, :, ::-1]
with open(os.path.join(weight_path, '..', 'gimp_ml_run.pkl'), 'rb') as file:
data_output = pickle.load(file)
@ -85,7 +92,7 @@ if __name__ == "__main__":
s = data_output["scale"]
filter = data_output["filter"]
output = get_super(image, s=s, cpu_flag=force_cpu, fFlag=filter)
output = get_super(image, s=s, cpu_flag=force_cpu, fFlag=filter, weight_path=weight_path)
cv2.imwrite(os.path.join(weight_path, '..', 'cache.png'), output[:, :, ::-1])
# with open(os.path.join(weight_path, 'gimp_ml_run.pkl'), 'wb') as file:
# pickle.dump({"run_success": True}, file)

Loading…
Cancel
Save