new depth model

GIMP3-ML
DESKTOP-F04AGRR\Kritik Soman 3 years ago
parent c7681d33a6
commit 2f408c76c0

@ -121,8 +121,6 @@ def monodepth(procedure, image, drawable, force_cpu, progress_bar, config_path_o
copy.set_mode(Gimp.LayerMode.NORMAL_LEGACY) # DIFFERENCE_LEGACY
image.insert_layer(copy, None, -1)
# Remove temporary layers that were saved
my_dir = os.path.join(weight_path, '..')
for f_name in os.listdir(my_dir):
@ -191,17 +189,17 @@ def run(procedure, run_mode, image, n_drawables, layer, args, data):
vbox.pack_start(label, False, False, 1)
label.show()
# Show ideal image size text
label = Gtk.Label(label="384 X 384 px | ")
grid.attach(label, 1, 0, 1, 1)
# vbox.pack_start(label, False, False, 1)
label.show()
# # Show ideal image size text
# label = Gtk.Label(label="384 X 384 px | ")
# grid.attach(label, 1, 0, 1, 1)
# # vbox.pack_start(label, False, False, 1)
# label.show()
# Force CPU parameter
spin = GimpUi.prop_check_button_new(config, "force_cpu", _("Force _CPU"))
spin.set_tooltip_text(_("If checked, CPU is used for model inference."
" Otherwise, GPU will be used if available."))
grid.attach(spin, 2, 0, 1, 1)
grid.attach(spin, 1, 0, 1, 1)
spin.show()
progress_bar = Gtk.ProgressBar()

@ -1,6 +1,8 @@
model,file_id,fileSize,mFName,md5sum
deepmatting,11dxJKH8p7xkcGtMtvzMUw-ua6pZ0vrfw,108,stage1_sad_57.1.pth,0cffb16b30fad67fa3eb5cfeeae0c7d5
MiDaS,11eap5jc-4SCX_sMMxYE6Bi5q_BKw894a,143,model.pt,74a1fcdde0b743212851d4b81be5f6eb
MiDaS,1hmv768Mrfv56SitcoMUlYp6zhUrj0HQv,493,dpt_hybrid-midas-501f0c75.pt,39beff6ce86ce03f6b94a29c6d11ee12
semseg,19rLDu8COUFSrOMnk124SBiEN9S9_QHBH,496,dpt_hybrid-ade20k-53898607.pt,d59f62cfba50297ffdef053bc4818a21
colorize,12tKfNIDewgJPbW3FiITV_AMbOtZWP0Eg,130,caffemodel.pth,efb7de5b0f3827d8a7e392ac287bca81
superresolution,11GwnqKsYo2jujACD_GMB9uMTQfsuk2RY,6,model_srresnet.pth,8f7ed4feb00402863e771a46013a93a8
faceparse,115nnWD0FoDkplTJYBY7lTQu1VNXFbCA_,51,79999_iter.pth,ff26a222ce48a618a1fa820b46223cae

1 model file_id fileSize mFName md5sum
2 deepmatting 11dxJKH8p7xkcGtMtvzMUw-ua6pZ0vrfw 108 stage1_sad_57.1.pth 0cffb16b30fad67fa3eb5cfeeae0c7d5
3 MiDaS 11eap5jc-4SCX_sMMxYE6Bi5q_BKw894a 143 model.pt 74a1fcdde0b743212851d4b81be5f6eb
4 MiDaS 1hmv768Mrfv56SitcoMUlYp6zhUrj0HQv 493 dpt_hybrid-midas-501f0c75.pt 39beff6ce86ce03f6b94a29c6d11ee12
5 semseg 19rLDu8COUFSrOMnk124SBiEN9S9_QHBH 496 dpt_hybrid-ade20k-53898607.pt d59f62cfba50297ffdef053bc4818a21
6 colorize 12tKfNIDewgJPbW3FiITV_AMbOtZWP0Eg 130 caffemodel.pth efb7de5b0f3827d8a7e392ac287bca81
7 superresolution 11GwnqKsYo2jujACD_GMB9uMTQfsuk2RY 6 model_srresnet.pth 8f7ed4feb00402863e771a46013a93a8
8 faceparse 115nnWD0FoDkplTJYBY7lTQu1VNXFbCA_ 51 79999_iter.pth ff26a222ce48a618a1fa820b46223cae

@ -1,13 +1,15 @@
import pickle
import os
import sys
import traceback
plugin_loc = os.path.dirname(os.path.realpath(__file__)) + '/'
sys.path.extend([plugin_loc + 'MiDaS'])
sys.path.extend([plugin_loc + 'DPT'])
from mono_run import run_depth
from monodepth_net import MonoDepthNet
import MiDaS_utils as MiDaS_utils
from monodepth_run import run
# from mono_run import run_depth
# from monodepth_net import MonoDepthNet
# import MiDaS_utils as MiDaS_utils
import numpy as np
import cv2
import torch
@ -21,13 +23,27 @@ def get_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()
# image = input_image / 255.0
# with torch.no_grad():
# out = run_depth(image, os.path.join(weight_path, 'MiDaS', 'model.pt'), MonoDepthNet, MiDaS_utils, target_w=640,
# f=cpu_flag)
# out = np.repeat(out[:, :, np.newaxis], 3, axis=2)
# d1, d2 = input_image.shape[:2]
# out = cv2.resize(out, (d2, d1))
# return out
def get_mono_depth(input_image, cpu_flag=False, weight_path=None):
if weight_path is None:
weight_path = get_weight_path()
image = input_image / 255.0
with torch.no_grad():
out = run_depth(image, os.path.join(weight_path, 'MiDaS', 'model.pt'), MonoDepthNet, MiDaS_utils, target_w=640,
f=cpu_flag)
out = run(input_image, os.path.join(weight_path, 'MiDaS', 'dpt_hybrid-midas-501f0c75.pt'), cpu_flag=cpu_flag, bits=2)
# out = run_depth(image, os.path.join(weight_path, 'MiDaS', 'model.pt'), MonoDepthNet, MiDaS_utils, target_w=640,
# f=cpu_flag)
out = np.repeat(out[:, :, np.newaxis], 3, axis=2)
d1, d2 = input_image.shape[:2]
out = cv2.resize(out, (d2, d1))
@ -42,7 +58,11 @@ if __name__ == "__main__":
force_cpu = data_output["force_cpu"]
try:
output = get_mono_depth(image, cpu_flag=force_cpu, weight_path=weight_path)
cv2.imwrite(os.path.join(weight_path, '..', 'cache.png'), output[:, :, ::-1])
# if bits == 1:
# cv2.imwrite(os.path.join(weight_path, '..', 'cache.png'), output.astype("uint8"), [cv2.IMWRITE_PNG_COMPRESSION, 0])
# elif bits == 2:
cv2.imwrite(os.path.join(weight_path, '..', 'cache.png'), output.astype("uint16"), [cv2.IMWRITE_PNG_COMPRESSION, 0])
# 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({"inference_status": "success", "force_cpu": force_cpu}, file)
@ -54,5 +74,8 @@ if __name__ == "__main__":
except Exception as error:
with open(os.path.join(weight_path, '..', 'gimp_ml_run.pkl'), 'wb') as file:
pickle.dump({"inference_status": "failed"}, file)
with open(os.path.join(weight_path, '..', 'error_log.txt'), 'w') as file:
file.write(str(error))
# with open(os.path.join(weight_path, '..', 'error_log.txt'), 'w') as file:
# file.write(str(error))
with open(os.path.join(weight_path, '..', 'error_log.txt'), 'w') as f:
f.write(str(error))
f.write(traceback.format_exc())

@ -70,7 +70,7 @@ setup(
# https://packaging.python.org/en/latest/requirements.html
install_requires=['numpy', 'future; python_version <= "2.7"',
'scipy', 'gdown', 'typing', 'enum; python_version <= "2.7"', 'requests', 'opencv-python<=4.3',
'pretrainedmodels', "scikit-image"]#, "torch==1.8", "torchvision"],
'pretrainedmodels', "scikit-image", "timm==0.4.5"]#, "torch==1.8", "torchvision"],
# Optional

Loading…
Cancel
Save