Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 3rd November 2018, 20:10   #101  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,717
I can't get it to work, I have the same problem.

Code:
source=DGSource("test.dgi",fulldepth=true)
b = -0.6 # optimize b = _n_ | -1..1 | b
c = 0.3  # optimize c = _n_ | -1..1 | c
filtered=BicubicResize(source, 1920, 800, b=b, c=c).Lanczos4Resize(3840, 1600)
I'm testing optimizing the downsizing parameters as mentioned earlier in this thread.

EDIT: changing to "b = 0.6 # optimize b = _n_ | -1..1 | b" got past the error.
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...

Last edited by Boulder; 3rd November 2018 at 20:28.
Boulder is offline   Reply With Quote
Old 3rd November 2018, 23:09   #102  |  Link
zorr
Registered User
 
Join Date: Mar 2018
Posts: 447
Quote:
Originally Posted by Boulder View Post
I can't get it to work, I have the same problem.

Code:
source=DGSource("test.dgi",fulldepth=true)
b = -0.6 # optimize b = _n_ | -1..1 | b
c = 0.3  # optimize c = _n_ | -1..1 | c
filtered=BicubicResize(source, 1920, 800, b=b, c=c).Lanczos4Resize(3840, 1600)
I'm testing optimizing the downsizing parameters as mentioned earlier in this thread.

EDIT: changing to "b = 0.6 # optimize b = _n_ | -1..1 | b" got past the error.
I have located the bug, the current version cannot read negative number values. Will be fixed in the next version.

Also note that floats are not supported, so with range -1..1 the optimizer will only try values -1, 0 and 1. You can get around this limitation by using something like this:

Code:
c = 30/100.0  # optimize c = _n_ | -100..100 | c
which would result in range -1.0 .. 1.0 with steps of 0.01.
zorr is offline   Reply With Quote
Old 3rd November 2018, 23:50   #103  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,717
I got it to run with this script, but the iterations all have the same SSIM value. If I open the script in VirtualDub2 and run it, the perFrameResults.txt is there but it is not produced when the script is run with optimizer.bat. I'm using the latest Avisynth+ build with your special plugins in x86 mode. If I run in x64 mode, I get the error message "java.lang.NumberFormatException: For input string: "I don't know what 'ssim' means." even though the plugins are in place and I have both environments of Avisynth+ installed.

Code:
source=DGSource("test.dgi",fulldepth=true)

b = 33/100 # optimize b = _n_/100 | -100..100 | b
c = 33/100 # optimize c = _n_/100 | -100..100 | c
denoised=BicubicResize(source, 1920, 800, b=b, c=c).Lanczos4Resize(3840, 1600)

# cut out the part used in quality / speed evaluation
source = source.Trim(MIDDLE_FRAME - TEST_FRAMES/2 + (TEST_FRAMES%2==0?1:0), MIDDLE_FRAME + TEST_FRAMES/2)
denoised = denoised.Trim(MIDDLE_FRAME - TEST_FRAMES/2 + (TEST_FRAMES%2==0?1:0), MIDDLE_FRAME + TEST_FRAMES/2)
last = denoised

global total = 0.0
global ssim_total = 0.0
FrameEvaluate(last, """
	global ssim = SSIM_FRAME(source, denoised)
	global ssim = (ssim == 1.0 ? 0.0 : ssim)
	global ssim_total = ssim_total + ssim	
""")	

# measure runtime, plugin writes the value to global avstimer variable
global avstimer = 0.0
AvsTimer(frames=1, type=0, total=false, name="Optimizer")

# per frame logging (ssim, time)
delimiter = "; "
resultFile = "perFrameResults.txt"	# output out1="ssim: MAX(float)" out2="time: MIN(time) ms" file="perFrameResults.txt"
WriteFile(resultFile, "current_frame", "delimiter", "ssim", "delimiter", "avstimer")

# write "stop" at the last frame to tell the optimizer that the script has finished
frame_count = FrameCount()
WriteFileIf(resultFile, "current_frame == frame_count-1", """ "stop " """, "ssim_total", append=true)

return last
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Old 4th November 2018, 01:40   #104  |  Link
zorr
Registered User
 
Join Date: Mar 2018
Posts: 447
Quote:
Originally Posted by Boulder View Post
I got it to run with this script, but the iterations all have the same SSIM value.
Code:
b = 33/100 # optimize b = _n_/100 | -100..100 | b
When you divide by 100 you must use a floating point number as the divisor (100.0), otherwise it's integer division and most results will then end up as 0 which explains the same SSIM value.

Quote:
Originally Posted by Boulder View Post
If I open the script in VirtualDub2 and run it, the perFrameResults.txt is there but it is not produced when the script is run with optimizer.bat.
That is normal, the optimizer changes the output file name and location, the files are at <optimizer_install_dir>/work.

Quote:
Originally Posted by Boulder View Post
If I run in x64 mode, I get the error message "java.lang.NumberFormatException: For input string: "I don't know what 'ssim' means." even though the plugins are in place and I have both environments of Avisynth+ installed.
I haven't tested x64 version myself so this could be a bug. Did you set the x64 mode with "-arch x64"?
zorr is offline   Reply With Quote
Old 4th November 2018, 01:50   #105  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,717
Quote:
Originally Posted by zorr View Post
When you divide by 100 you must use a floating point number as the divisor (100.0), otherwise it's integer division and most results will then end up as 0 which explains the same SSIM value.
Thanks, I think this should be mentioned this in the tutorial post. Float works only in the first parameter, not in the range call. In the range call you get "java.lang.NumberFormatException: For input string: "-100.0".

Quote:
I haven't tested x64 version myself so this could be a bug. Did you set the x64 mode with "-arch x64"?
It was already in the ini file as per my first test with a clean ini.
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Old 4th November 2018, 03:13   #106  |  Link
zorr
Registered User
 
Join Date: Mar 2018
Posts: 447
AvisynthOptimizer v0.9.9-beta released.

This version adds a new optimizer argument -initial. It's meant for setting the initial population and the choices are:
  • -random: the default value, creates a random initial population
  • -script: reads the values set in the script and makes one of the initial population members use those values. The rest of the population is random. (thanks Seedmanc for the suggestion)
  • -<log_file_name>: Read a log file (or files, using a wildcard *) and create the initial population from the pareto front of the results. If the pareto front is larger than the population size the chosen algorithm will prune the results (but the best result is always included). If the pareto front is smaller than the population size the rest will be filled with random individuals.

NOTE: -initial only works with the algorithm SPEA2 for now, I will add the support for the rest in the next version.


Also some much needed bug fixes:
-can now read and understand a negative value as the variable's original value in the script (thanks Seedmanc and Boulder for the report)
-optimizer will now stop when all parameter combinations have been tested. The population size will be set to number of combinations if it is larger than that (in order to avoid duplicate parameters). Thanks ChaosKing for the report.
-duplicate parameter combinations are no longer possible in the initial population (also thanks to ChaosKing for the report)
zorr is offline   Reply With Quote
Old 5th November 2018, 01:51   #107  |  Link
zorr
Registered User
 
Join Date: Mar 2018
Posts: 447
AvisynthOptimizer-0.9.10-beta released.

The -initial argument now works with the algorithms NSGA-II and mutation as well.

Some more bug fixes: the input script argument without any path component now works (thanks Seedmanc for the bug report). Also the wildcard didn't work with the -initial argument but does work now.
zorr is offline   Reply With Quote
Old 7th November 2018, 11:40   #108  |  Link
ChaosKing
Registered User
 
Join Date: Dec 2005
Location: Germany
Posts: 1,795
If you still plan to add VS support someday, there is a new filter now which can calculate a VMAF, PSNR, SSIM and MS-SSIM score (https://github.com/HomeOfVapourSynth...pourSynth-VMAF)
__________________
AVSRepoGUI // VSRepoGUI - Package Manager for AviSynth // VapourSynth
VapourSynth Portable FATPACK || VapourSynth Database
ChaosKing is offline   Reply With Quote
Old 7th November 2018, 14:03   #109  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,717
It would be really nice, high bitdepth support is already a big plus and also those other scores could be useful.
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Old 7th November 2018, 17:07   #110  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,717
Running this kind of downsizing test with only one frame will hit the "DUPLICATE PARAMS" phase quite soon after the process starts. It seems to try the same values over and over again. Setting sensitivity to false helps a bit but the safest way is to sample multiple frames which will then increase the runtime quite a lot.

In this case, I used -1000..1000 as the range, normally I would go for -100..100 but it has the same problem.

Code:
TEST_FRAMES = 1			# how many frames are tested
MIDDLE_FRAME = 0		# middle frame number

source=FFVideoSource("c:\avisynthoptimizer\churchill.avi",colorspace="yv12")

b = 330/1000.0 # optimize b = _n_/1000.0 | -1000..1000 | b
c = 330/1000.0 # optimize c = _n_/1000.0 | -1000..1000 | c

denoised=BicubicResize(source, 1280, 536, b=b, c=c).LanczosResize(1920, 800)
Code:
  c selected for mutation
  b selected for mutation
mutated c with 38.399986267089844, value 610 -> 609
mutated b with 38.399986267089844, value -149 -> -148
param values after resolve: b -148 c 609
DUPLICATE PARAMS -148 609
change counts: b 13c 19
  b selected for mutation
  c selected for mutation
mutated b with 38.399986267089844, value -149 -> -149
mutated c with 38.399986267089844, value 610 -> 610
param values after resolve: b -149 c 610
DUPLICATE PARAMS -149 610
change counts: b 13c 19
  c selected for mutation
  b selected for mutation
mutated c with 38.399986267089844, value 610 -> 610
mutated b with 38.399986267089844, value -149 -> -149
param values after resolve: b -149 c 610
DUPLICATE PARAMS -149 610
change counts: b 13c 19
  b selected for mutation
  c selected for mutation
mutated b with 38.399986267089844, value -149 -> -150
mutated c with 38.399986267089844, value 610 -> 609
param values after resolve: b -150 c 609
DUPLICATE PARAMS -150 609
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Old 7th November 2018, 17:58   #111  |  Link
zorr
Registered User
 
Join Date: Mar 2018
Posts: 447
Quote:
Originally Posted by Boulder View Post
Running this kind of downsizing test with only one frame will hit the "DUPLICATE PARAMS" phase quite soon after the process starts. It seems to try the same values over and over again.
That's weird, the v0.9.9-beta should have fixed that kind of problem. I will try your script and see what I can find. You're running the latest version right?
zorr is offline   Reply With Quote
Old 7th November 2018, 18:07   #112  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,717
Quote:
Originally Posted by zorr View Post
That's weird, the v0.9.9-beta should have fixed that kind of problem. I will try your script and see what I can find. You're running the latest version right?
Yes, I'm running v0.9.10-beta. Producing a 2-frame video clip and setting sensitivity to false works much better, about 14000 iterations done without the issue. This is what appears constantly:
Code:
Mutating 1 params by 30,0 %
mutation failed 1000 times, increasing mutation count to 2
mutation failed 1000 times, increasing mutation count to 2
mutation failed 1000 times, increasing mutation count to 2
mutation failed 1000 times, increasing mutation count to 2
mutation failed 1000 times, increasing mutation count to 2
mutation failed 1000 times, increasing mutation count to 2
mutation failed 1000 times, increasing mutation count to 2
mutation failed 1000 times, increasing mutation count to 2
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Old 8th November 2018, 00:40   #113  |  Link
zorr
Registered User
 
Join Date: Mar 2018
Posts: 447
AvisynthOptimizer v0.9.11-beta released.

This version mainly fixes bugs and makes some minor improvements.

So there was a bug in the JMetal metaheuristics library which I found and fixed, it affected SPEA2 algorithm's "archive truncation". There is a chance that SPEA2 will give better results after this fix, I haven't done a proper test yet to confirm.

Boulder reported a bug which made the sensitivity estimation go haywire, it happened when two consecutive population generations had the exact same runtimes. That one is fixed as well.

Also there were too many "mutation failed 1000 times..." log messages so I removed those. The situation is normal when almost all combinations have been tried already.

Series results count was sometimes reported as zero when autorefreshing chart started reading the log file at the same time, thanks for ChaosKing for the logs.

I made a text change to make it a bit clearer what the best and worst results are about: "Best result" -> "Best run", "Worst result" -> "Worst run". By comparing the best and worst you can determine how reliably the runs achieve a similar result.

Finally, the optimizer will stop running if it's unable to change parameter's value in the script (earlier it caused an error message in an infinite loop).
zorr is offline   Reply With Quote
Old 8th November 2018, 00:44   #114  |  Link
zorr
Registered User
 
Join Date: Mar 2018
Posts: 447
@Boulder, can you try the latest version and report if it fixes all your issues? You should now be able to use 100.0 as the divider as well.

Quote:
Originally Posted by Boulder View Post
Code:
TEST_FRAMES = 1			# how many frames are tested
MIDDLE_FRAME = 0		# middle frame number
When I tried your script I had to change MIDDLE_FRAME to 1 in order to get clip length of one frame. With zero it returned the whole clip. Does it work differently for you?
zorr is offline   Reply With Quote
Old 12th November 2018, 18:24   #115  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,717
Quote:
Originally Posted by zorr View Post
@Boulder, can you try the latest version and report if it fixes all your issues? You should now be able to use 100.0 as the divider as well.
Seems to work fine, thank you.

Quote:
When I tried your script I had to change MIDDLE_FRAME to 1 in order to get clip length of one frame. With zero it returned the whole clip. Does it work differently for you?
For me it worked as I was feeding a one-frame clip in the optimizer to test the resizing parameters. In Avisynth syntax, Trim(n,0) means that you get all the frames from frame n until the end of the clip. I was just thinking that the middle frame must be inside the clip range and in Avisynth, counting starts from zero.
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Old 12th November 2018, 21:06   #116  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,717
Gah, the issue appeared again quite close to the end. I set only -iters 100000 to test. At least it didn't happen right away like it did in the earlier version.

Code:
change counts: b 17c 17
  b selected for mutation
  c selected for mutation
mutated b with 1.463081955909729, value -68 -> 10
mutated c with 1.463081955909729, value 34 -> 100
param values after resolve: b 10 c 100
DUPLICATE PARAMS 10 100
change counts: b 17c 17
  b selected for mutation
  c selected for mutation
mutated b with 1.463081955909729, value -68 -> -13
mutated c with 1.463081955909729, value 34 -> -79
param values after resolve: b -13 c -79
DUPLICATE PARAMS -13 -79
change counts: b 17c 17
  c selected for mutation
  b selected for mutation
mutated c with 1.463081955909729, value 34 -> 100
mutated b with 1.463081955909729, value -68 -> 74
param values after resolve: b 74 c 100
DUPLICATE PARAMS 74 100
change counts: b 17c 17
  c selected for mutation
  b selected for mutation
mutated c with 1.463081955909729, value 34 -> 100
mutated b with 1.463081955909729, value -68 -> -30
param values after resolve: b -30 c 100
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Old 16th November 2018, 00:37   #117  |  Link
Seedmanc
Registered User
 
Join Date: Sep 2010
Location: Russia
Posts: 85
I'm trying to add MRecalculate to optimization with the following (partial) script:
Quote:
doRecalc = true # optimize doRecalc = _n_ | false,true | doRecalc
smooth=1 # optimize smooth=_n_ | 0,1 ; filter:doRecalc | smooth
RblockSize = 12 # optimize RblockSize = _n_ | 4,6,8,12,16,24,32,48,64 ; min:Rdivide 0 > 8 2 ? ; filter:doRecalc | RblockSize
RsearchAlgo = 5 # optimize RsearchAlgo = _n_ | 0..5 D ; filter:doRecalc | RsearchAlgo
RsearchRange = 4 # optimize RsearchRange = _n_ | 1..30 ; filter:doRecalc | RsearchRange
Rdivide=0 # optimize Rdivide=_n_ | 0..2 D ; max:RblockSize 8 >= 2 0 ? ; filter:doRecalc | Rdivide
Roverlap=4 # optimize Roverlap=_n_ | 0,4,8,12,16,20,24,28,32 ; max:RblockSize 2 / ; filter:doRecalc | Roverlap
Rdct = 0 # optimize Rdct = _n_ | 0,1,2,3,4,5,6,7,8,9,10 D ; filter:doRecalc | Rdct
Rmeander = true # optimize Rmeander = _n_ | false,true ; filter:doRecalc | Rmeander
RscaleCSAD = 2 # optimize RscaleCSAD = _n_ | -2..2 ; filter:doRecalc | RscaleCSAD
thsad = 200 # optimize thsad = _n_ | 0..10000 ; filter:doRecalc | thsad

bv = doRecalc ? MRecalculate(super_render, bv, thsad=thsad, smooth=smooth, blksize=RblockSize, search=RsearchAlgo, searchparam=RsearchRange, truemotion=false, overlap=Roverlap, dct=Rdct, divide=Rdivide, meander=Rmeander, scaleCSAD=RscaleCSAD) : bv
fv = doRecalc ? MRecalculate(super_render, fv, thsad=thsad, smooth=smooth, blksize=RblockSize, search=RsearchAlgo, searchparam=RsearchRange, truemotion=false, overlap=Roverlap, dct=Rdct, divide=Rdivide, meander=Rmeander, scaleCSAD=RscaleCSAD) : fv
but Optimizer fails with
Quote:
java.lang.Exception: Unknown element doRecalc
at avisynthoptimizer.parser.RPNParser.push(RPNParser.java:124)
at avisynthoptimizer.AviSynthOptimizer.filterValue(AviSynthOptimizer.jav
a:3709)
What could be wrong? I tried replacing filter with max, not helpful. For now I had to get rid of filtering by doRecalc, but that's wasting iterations.
Seedmanc is offline   Reply With Quote
Old 17th November 2018, 00:58   #118  |  Link
zorr
Registered User
 
Join Date: Mar 2018
Posts: 447
AvisynthOptimizer v0.9.12-beta released.

Some minor bug fixes and improvements:
  • set the logging threshold higher for reporting the mutation failures, now has to be at least 100 000 failed attempts before logging starts (thanks @Boulder for the report)
  • bugfix: conflict resolvation didn't support variables which had boolean types in min/max/filter definition, it does now. This is related to the bug @Seedmanc reported above, thanks! Also related: the optimizer will stop running if it's unable to resolve conflicts in 100 000 tries.
  • avsr version updated to latest v0.1.9. It has a cool new -frames argument which I'm going put to good use, but the new feature (automatic frame selection) using it is not finished yet. Thanks @Groucho2004!
zorr is offline   Reply With Quote
Old 17th November 2018, 01:27   #119  |  Link
zorr
Registered User
 
Join Date: Mar 2018
Posts: 447
Quote:
Originally Posted by Seedmanc View Post
I'm trying to add MRecalculate to optimization with the following (partial) script:
Code:
doRecalc = true # optimize doRecalc = _n_ | false,true | doRecalc
smooth=1 # optimize smooth=_n_ | 0,1 ; filter:doRecalc | smooth
but Optimizer fails
The first problem here was that the optimizer didn't support variables with boolean types (like the variable "doRecalc"). The latest version v0.9.12-beta does so grab that one.

The second problem is that the filter rejects all the values when doRecalc==false, therefore the conflict resolvation cannot finish (it expects to find some combination of parameters which are valid).

How to fix this? You have to return at least one valid value for every parameter. Using variable RblockSize as an example, the filter could be like this:
Code:
filter:doRecalc x 16 ? x ==
The logic here is that when doRecalc is true the rest of the equation becomes (x == x) which is always true so it accepts all the values. When doRecalc is false the equation becomes (x == 16) accepting one value. Since the MRecalculate is disabled the value we choose doesn't matter but we have to choose something anyway.

If the parameter already has a filter, you can add min or max definition (easier to separate the logic than try to make one more complex filter).

Min:
Code:
min:doRecalc 4 64 ?
Max:
Code:
max:doRecalc 64 4 ?
The min will set 64 as the minimum value when doRecalc is false, which leaves only the value 64 as valid. The max is similar but sets the maximum as 4.

So it's a bit of work to add all these min/max/filter definitions, I will have to think if there's an easier way to support this kind of disabling of parametes.

Another way is to make a separate script for the MRecalculate-version. Optimize both scripts and see which one gave better results. I tried this and to my surprise the script without MRecalculate was better. I think it might be because there are much more parameters to optimize in the MRecalculate-script and therefore the search doesn't get anywhere close to optimal results in the same iteration count.
zorr is offline   Reply With Quote
Old 18th November 2018, 19:43   #120  |  Link
Boulder
Pig on the wing
 
Boulder's Avatar
 
Join Date: Mar 2002
Location: Finland
Posts: 5,717
I got this one with the latest version. It happened quite close to the end (once again those resizing tests of mine) and seems to happen with every run. I fired up five concurrent optimizations and three have now failed with the error around the ~39000th iteration.

Code:
java.lang.IllegalArgumentException: bound must be positive
        at java.util.Random.nextInt(Unknown Source)
        at avisynthoptimizer.AviSynthOptimizer.selectRandomWeightedByChangeCount(AviSynthOptimizer.java:2493)
        at avisynthoptimizer.AviSynthOptimizer.mutateResult(AviSynthOptimizer.java:5049)
        at avisynthoptimizer.nsga_ii.RangeMutation.execute(RangeMutation.java:93)
        at avisynthoptimizer.nsga_ii.RangeMutation.execute(RangeMutation.java:25)
        at avisynthoptimizer.spea2.DynamicSPEA2.reproduction(DynamicSPEA2.java:103)
        at org.uma.jmetal.algorithm.impl.AbstractEvolutionaryAlgorithm.run(AbstractEvolutionaryAlgorithm.java:60)
        at java.lang.Thread.run(Unknown Source)
__________________
And if the band you're in starts playing different tunes
I'll see you on the dark side of the Moon...
Boulder is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:19.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.