Selur's Little Message Board

Full Version: Deoldify Vapoursynth filter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
But it could be that this memory leak is due to the upgrade to Qt6 ?
It is present also in old versions ?

Dan
I'm pretty sure that this is not Qt related, but that vsViewer does not properly clean the Vapoursynth environment.
using something like:
Code:
# Imports
import vapoursynth as vs
# getting Vapoursynth core
import ctypes
import sys
import os
core = vs.core
# Import scripts folder
scriptPath = 'F:/Hybrid/64bit/vsscripts'
sys.path.insert(0, os.path.abspath(scriptPath))
# Loading Support Files
Dllref = ctypes.windll.LoadLibrary("F:/Hybrid/64bit/vsfilters/Support/libfftw3f-3.dll")
# loading plugins
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libsangnom.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/EEDI2.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SharpenFilter/AWarpSharp2/libawarpsharp2.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DebandFilter/Neof3kdb/neo-f3kdb.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/TTempSmooth/TTempSmooth.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/DCTFilter.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeblockFilter/Deblock/Deblock.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/FFT3DFilter/fft3dfilter.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/CTMF/CTMF.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libmvtools_sf_em64t.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/TCanny.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/FluxSmooth/libfluxsmooth.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DerainbowFilter/BiFrost/libbifrost.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/DePan.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/EEDI3m.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/vsznedi3.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/scenechange.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/DerainbowFilter/DeCross/libdecross.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/d2vSource/DGDecode.dll")
# Import scripts
import mvsfunc
import muvsfunc
import G41Fun
import lostfunc
import adjust
import havsfunc
import validate
# Source: 'C:\Users\Selur\Desktop\Sample\Sample.mpg'
# Current color space: YUV420P8, bit depth: 8, resolution: 720x480, frame rate: 29.97fps, scanorder: top field first, yuv luminance scale: limited, matrix: 470bg
# Loading C:\Users\Selur\Desktop\Sample\Sample.mpg using DGDecode
clip = core.dgdecode.MPEG2Source("J:/tmp/mpg_65ef6c100374fd10d8d2d894338abe7e_853323747.d2v",info=3)# 29.97 fps, scanorder: top field first
frame = clip.get_frame(0)
# Setting detected color matrix (470bg).
clip = core.std.SetFrameProps(clip=clip, _Matrix=5)
# setting color transfer (170), if it is not set.
if validate.transferIsInvalid(clip):
  clip = core.std.SetFrameProps(clip=clip, _Transfer=6)
# setting color primaries info (to 470), if it is not set.
if validate.primariesIsInvalid(clip):
  clip = core.std.SetFrameProps(clip=clip, _Primaries=5)
# setting color range to TV (limited) range.
clip = core.std.SetFrameProps(clip=clip, _ColorRange=1)
# making sure frame rate is set to 29.97fps
clip = core.std.AssumeFPS(clip=clip, fpsnum=30000, fpsden=1001)
# making sure the detected scan type is set (detected: top field first)
clip = core.std.SetFrameProps(clip=clip, _FieldBased=2) # tff
# rainbow removal using DeCross
clip = core.decross.DeCross(clip=clip)
# Deinterlacing using QTGMC
clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=True) # new fps: 29.97
# Making sure content is preceived as frame based
clip = core.std.SetFrameProps(clip=clip, _FieldBased=0) # progressive
clip = clip[::2] # selecting previously even frames
# adjusting color using Tweak
clip = adjust.Tweak(clip=clip, hue=0.01, sat=1.00, cont=1.00, coring=True)
# Fixing chroma bleeding using FixChromaBleedingMod
clip = havsfunc.FixChromaBleedingMod(input=clip)
clip = havsfunc.Vinverse(clp=clip)
# stabilizing using Stab
clip = lostfunc.Stab(clp=clip,range=0,mirror=15)
# rainbow removal using BiFrost
clip = core.bifrost.Bifrost(clip=clip, variation=3, interlaced=False)
# removing grain using STPresso
clip = havsfunc.STPresso(clp=clip, planes=[0])
# removing grain using TemporalDegrain2
clip = G41Fun.TemporalDegrain2(clip=clip, degrainPlane=4, meAlgPar=False, postFFT=0, fftThreads=1)
# denoising using MCTemporalDenoise
clip = havsfunc.MCTemporalDenoise(i=clip, settings="medium", ncpu=1)
# debanding using f3kdb
clip = core.neo_f3kdb.Deband(clip, y=44, cb=44, cr=44, grainy=34, grainc=44, dither_algo=2, keep_tv_range=True, output_depth=8)
# sharpening using AWarpSharp2
clip = core.warp.AWarpSharp2(clip=clip, thresh=64, blur=2, chroma=True, planes=[1,2])
clip = muvsfunc.BlindDeHalo3(clip, strength=25, sharpness=0.01, interlaced=False)
# deringing using HQDeringmod
clip = havsfunc.HQDeringmod(clip, nrmode=2, darkthr=3.0)
# line darkening using Toon
clip = havsfunc.Toon(input=clip,str=0.25)
# applying anti aliasing using santiag
clip = havsfunc.santiag(c=clip, nns=3, pscrn=2, aa=34)
# adding Grain using AddGrain
clip = core.grain.Add(clip=clip, var=0.00, uvar=0.30, constant=True)
# adjusting output color from: YUV420P8 to YUV420P10 for NVEncModel
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P10, range_s="limited")
# set output frame rate to 29.97fps (progressive)
clip = core.std.AssumeFPS(clip=clip, fpsnum=30000, fpsden=1001)
# output
clip.set_output()
each reload eats ~450MB additional RAM (I never noticed it since a. I got 64GB RAM b. I refuently close my Preview window c. don't refresh settings)

Cu Selur

Ps.: TemporalDegrain2 with extraSharp=True from G41Fun.py also crashes.
Argh even the latest version from https://github.com/YomikoR/VapourSynth-Editor has this issue.
Sad
created an issue entry there: https://github.com/YomikoR/VapourSynth-Editor/issues/55
In case YomikoR can fix it in his version I can probably adjust his version for vsViewer (this would probably would take me a week), or might even be able to adjus this fix to vsViewer. (fingers crossed)

Cu Selur
I was able to reproduce the problem.
It is just enough to close the preview and reopen it to observe a significant increase in the memory usage.

Dan

P.S.
I tested it with my coloring scripts. They use only DeSpot, mcdegrainsharp, ddeoldify, CAS
The memory usage increase to about 3.8GB, but then remain stable, I was unable to increase the memory usage ove 4GB, even closing and reopening, running the script several times.
I suspect that the memory leak is due to some filter used in your script.
It seems that the filter with memory leak in your script is the following

Code:
clip = core.bifrost.Bifrost(clip=clip, variation=3, interlaced=False)


Dan
Thanks, a lot!
You are right the main issue seems to be bifrost.
https://github.com/YomikoR/VapourSynth-E...2091617358
+
https://github.com/dubhater/vapoursynth-...t/issues/4
depending of whether dubhater can fix this in bifrost I will probably remove it from Hybrid.
Also I'll look into adjusting YomikoRs latest VapourSynth-Edit version to use it instead of current vsViewer.


Cu Selur
dubhaters reply: "Could be"
is priceless.
Seems like I should remove bifrost. Sad
Quote:please remove any grain from the clip, because it will create artifacts on colored frames.
Maybe adding extending the script with some prefiltering options might be a good idea.
So basically offer a bunch of denoisers (with fixed settings) and then:
1. take source and remember it
2. denoise source
3. feed denoised source to deoldify
4. Merge luma from original and chroma from denoised souce.

Cu Selur

Ps.: unless something comes up, I'll release a new version of Hybrid on Sunday.
Currently I'm using: DeSpot(), mcdegrainsharp() to remove the grain
Then I colorize the video and finally I use CAS(0.7) and eventually GLCAS.

Including DeSpot(), mcdegrainsharp()  I can skip the application of CAS/GLCAS.

I will add a degrain option in vsdeoldify in the next RC.

Thanks,
Dan
That looks wrong as a prefilter.
I would suggest using something way more aggressive. Smile
(despot is fine, but then I would use one of the denoisers as prefilter)
Remember the main goal of a pre-filter is not to retain details, but to remove details that hinder motion estimation, etc.
Look at your source with YUV split, and you see that usually your chroma doesn't usually hold much detail the chroma created by DeOldify (https://imgsli.com/MjYxMDUz), will not contain more details so using elaborate denoising is probably the wrong (unnecessary time-consuming) approach. First thing I would try is something like Bilaterla (GPU) as prefilter. Wink
Here to show what I mean in code:
Code:
# Imports
import vapoursynth as vs
# getting Vapoursynth core
import sys
import os
core = vs.core
# Import scripts folder
scriptPath = 'F:/Hybrid/64bit/vsscripts'
sys.path.insert(0, os.path.abspath(scriptPath))
# loading plugins
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/Support/libvs_placebo.dll")
core.std.LoadPlugin(path="F:/Hybrid/64bit/vsfilters/SourceFilter/DGDecNV/DGDecodeNV.dll")
# Import scripts
import validate
# Source: 'G:\clips\andygriffithtest.mkv'
# Current color space: YUV420P8, bit depth: 8, resolution: 1920x1080, frame rate: 23.976fps, scanorder: progressive, yuv luminance scale: limited, matrix: 709, transfer: bt.709, primaries: bt.709
# Loading G:\clips\andygriffithtest.mkv using DGSource
clip = core.dgdecodenv.DGSource("J:/tmp/mkv_821d49f4ca1bc226860d854a052a3269_853323747.dgi")# 23.976 fps, scanorder: progressive
frame = clip.get_frame(0)
# Setting detected color matrix (709).
clip = core.std.SetFrameProps(clip=clip, _Matrix=1)
# setting color transfer (709), if it is not set.
if validate.transferIsInvalid(clip):
  clip = core.std.SetFrameProps(clip=clip, _Transfer=1)
# setting color primaries info (to 709), if it is not set.
if validate.primariesIsInvalid(clip):
  clip = core.std.SetFrameProps(clip=clip, _Primaries=1)
# setting color range to TV (limited) range.
clip = core.std.SetFrameProps(clip=clip, _ColorRange=1)
# making sure frame rate is set to 23.976fps
clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
# making sure the detected scan type is set (detected: progressive)
clip = core.std.SetFrameProps(clip=clip, _FieldBased=0) # progressive
bw = clip

# PREFILTERING

# adjusting color space from YUV420P8 to YUV444P16 for vsGLSLBilateralve
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, range_s="limited")
with open("F:/Hybrid/64bit/vsfilters/GLSL/parameterized/Anime4K_Denoise_Bilateral_Mean.glsl") as glslf:
  glsl = glslf.read()
glsl = glsl.replace('#define INTENSITY_SIGMA 0.1', '#define INTENSITY_SIGMA 5')
glsl = glsl.replace('#define SPATIAL_SIGMA 1.0', '#define SPATIAL_SIGMA 3')
glsl = glsl.replace('#define INTENSITY_POWER_CURVE 1.0', '#define INTENSITY_POWER_CURVE 0')
clip = core.placebo.Shader(clip=clip, shader_s=glsl, width=clip.width, height=clip.height)
# changing range from limited to full range for vsDeOldify
clip = core.resize.Bicubic(clip, range_in_s="limited", range_s="full")
# setting color range to PC (full) range.
clip = core.std.SetFrameProps(clip=clip, _ColorRange=0)
# adjusting color space from YUV444P16 to RGB24 for vsDeOldify
clip = core.resize.Bicubic(clip=clip, format=vs.RGB24, matrix_in_s="709", range_s="full", dither_type="error_diffusion")

# COLORING

# adding colors using DeOldify
from vsdeoldify import ddeoldify_main
clip = ddeoldify_main(clip=clip)
# changing range from full to limited range for vsDeOldify
clip = core.resize.Bicubic(clip, range_in_s="full", range_s="limited")

# Merging
clip = core.resize.Bicubic(clip=clip, format=vs.YUV420P8, matrix_s="709", range_s="limited")
clip = core.std.ShufflePlanes(clips=[bw, clip, clip], planes=[0, 1, 2], colorfamily=vs.YUV)

# set output frame rate to 23.976fps (progressive)
clip = core.std.AssumeFPS(clip=clip, fpsnum=24000, fpsden=1001)
# output
clip.set_output()
Not sure this is useful at all,... or whether something like KNLMeans&Co should be used.

Quote:I will add a degrain option in vsdeoldify in the next RC.
Please don't unless you have already tested this intensively, and also don't think about adding another xy option array for this. (I will not add another option array in Hybrid.)

Cu Selur

Ps.: something completely different: https://imgsli.com/MjYxMDYy