Some really interesting findings by piecing together what you mentioned in this thread, along with some tidbit that topaz engineers have let slip in the past about some of the tvai filter parameters.
- It seems the “estimate” button triggers an ffmpeg run using the “tvai_pe” filter.
- “tvai_pe” in turn uses the prap-3 model to perform hyper-parameter optimization estimation, or in layman’s term, figure out the right slider values to set in the GUI when clicking estimate.
- The tvai_pe filter can be run for the entire clip, but topaz people have mentioned in that past that 20 frames were used for estimation, so it’s clearly some subset of all frames being used. It’s also unclear what they meant with “20 frames”, if that was for the whole of the clip or for every N intervals or recurring sampling. (still to be clarified)
- When producing a sample clip (1) and then running the tvai_pe filter on the first 20 frames, the metrics in (2) are produced.
- Looking at the summary statistics of those values, we get (3).
- Opening the clip in the TVAI UI, selecting Protheus v3 > manual and clicking estimate at the beginning of the clip produce the following slider values (4)
- Referring back to the summary statistics of the tvai_pe output, we see that the 75th percentile almost exactly match the slider values. As such I was able to name the columns and we now understand what slider value each of the six “parameter” columns correspond to in the output arrays of tvai_pe.
Implication
Now, this opens up a lot of interesting possibilities.
- It means we can run the tvai_pe model through the entire clip and get a holistic understanding on the predicted nature of our artifacts.
- With our knowledge of where scenes start and end, or using our own custom scene detectors, we can configure different settings for different scenes such as taking a sample at that start of each scene and locking the values for that segment, like gene wanted to achieve.
- We can also create our own functions where we can apply any function scaling to any of the values.
- We can decide to ignore certain values by freezing them, just like you wanted FS.
- To apply different settings under our control we’d likely need to chunk our clip, say one chunk per second, or per 10 seconds or the like. The precision is fully under our control.
The optimal way would be to write an ffmpeg filter specifically designed to take an instruction file. It would then be added to the filter graph just before the tvai filters, or between “tvai_pe” and the enhancement filters.
This is really cool. I’ll have to play with these possibilities a bit. Awesome that Topaz has created such a modular architecture, since that’s precisely what we need to create our own pipelines for our own respective needs. Just sad they’ve not documented it though.
References:
(1) Sample clip generation
ffmpeg -f lavfi -i testsrc=duration=12:size=320x180:rate=15 -pix_fmt yuv420p -c:v libx264 sample.mp4
(2) Defect correction estimation using the ffmpeg tvai_pe filter and prap-3 model
ffmpeg -v error -h filter=tvai_pe
Filter tvai_pe
Apply Topaz Video AI parameter estimation models.
Inputs:
#0: default (video)
Outputs:
#0: default (video)
tvai_pe AVOptions:
model <string> ..FV....... Model short name (default "prap-3")
device <int> ..FV....... Device index (Auto: -2, CPU: -1, GPU0: 0, ...) (from -2 to 8) (default -2)
download <int> ..FV....... Enable model downloading (from 0 to 1) (default 1)
This filter has support for timeline through the 'enable' option.
ffmpeg -v error -i sample.mp4 -vf tvai_pe -vframes 20 -f null -
Parameter values:[-0.163206 ,0.0181217 ,0.229532 ,0.427336 ,0.0986777 ,0.266223 , ]
Parameter values:[-0.166424 ,0.0185162 ,0.231425 ,0.419165 ,0.0973274 ,0.278938 , ]
Parameter values:[-0.166728 ,0.0185982 ,0.233558 ,0.409359 ,0.0961565 ,0.274892 , ]
Parameter values:[-0.168796 ,0.019691 ,0.240075 ,0.406629 ,0.0975815 ,0.289282 , ]
Parameter values:[-0.169663 ,0.0201042 ,0.238102 ,0.397581 ,0.0972078 ,0.288823 , ]
Parameter values:[-0.17035 ,0.0201033 ,0.241191 ,0.395169 ,0.0981346 ,0.291275 , ]
Parameter values:[-0.167102 ,0.0200989 ,0.239995 ,0.394212 ,0.099988 ,0.290737 , ]
Parameter values:[-0.165109 ,0.0198792 ,0.236747 ,0.395309 ,0.0999681 ,0.287588 , ]
Parameter values:[-0.164466 ,0.0195244 ,0.235611 ,0.393794 ,0.0993702 ,0.280433 , ]
Parameter values:[-0.163594 ,0.0192311 ,0.236228 ,0.396524 ,0.0995546 ,0.273717 , ]
Parameter values:[-0.168258 ,0.0195393 ,0.234674 ,0.391004 ,0.0963783 ,0.271823 , ]
Parameter values:[-0.173479 ,0.0186817 ,0.236368 ,0.401487 ,0.0944276 ,0.276925 , ]
Parameter values:[-0.169703 ,0.0187057 ,0.235371 ,0.396484 ,0.0951625 ,0.271464 , ]
Parameter values:[-0.169483 ,0.0186276 ,0.237225 ,0.404117 ,0.0957704 ,0.267977 , ]
Parameter values:[-0.154646 ,0.0191898 ,0.236846 ,0.390147 ,0.0961715 ,0.2302 , ]
Parameter values:[-0.162518 ,0.0175994 ,0.235073 ,0.39477 ,0.094886 ,0.242646 , ]
Parameter values:[-0.159807 ,0.017557 ,0.231505 ,0.38917 ,0.0952248 ,0.238809 , ]
Parameter values:[-0.160943 ,0.0164608 ,0.231884 ,0.399115 ,0.0962811 ,0.242576 , ]
Parameter values:[-0.157057 ,0.0161958 ,0.232442 ,0.397282 ,0.0978506 ,0.240852 , ]
Parameter values:[-0.157441 ,0.0157485 ,0.234216 ,0.399434 ,0.0992506 ,0.238351 , ]
(3) Summary statistics of defect estimates
df.describe()
0 1 2 3 4 5
count 20.000000 20.000000 20.000000 20.000000 20.000000 20.000000
mean -0.164939 0.018609 0.235403 0.399904 0.097268 0.267177
std 0.005033 0.001316 0.003117 0.009580 0.001781 0.020475
min -0.173479 0.015748 0.229532 0.389170 0.094428 0.230200
25% -0.168968 0.017991 0.233279 0.394630 0.096060 0.242628
50% -0.165766 0.018694 0.235491 0.396903 0.097268 0.272770
75% -0.162124 0.019577 0.236941 0.402145 0.098821 0.282222
max -0.154646 0.020104 0.241191 0.427336 0.099988 0.291275
(4) TVAI Estimate run in GUI
(5) tvai_pe dimension identification (column labeling)
df.columns=['deblur', 'reduce_noise', 'improve_detail', 'dehalo', 'sharpen', 'revert_compression']
df.describe()
deblur reduce_noise improve_detail dehalo sharpen revert_compression
count 20.000000 20.000000 20.000000 20.000000 20.000000 20.000000
mean -0.164939 0.018609 0.235403 0.399904 0.097268 0.267177
std 0.005033 0.001316 0.003117 0.009580 0.001781 0.020475
min -0.173479 0.015748 0.229532 0.389170 0.094428 0.230200
25% -0.168968 0.017991 0.233279 0.394630 0.096060 0.242628
50% -0.165766 0.018694 0.235491 0.396903 0.097268 0.272770
75% -0.162124 0.019577 0.236941 0.402145 0.098821 0.282222
max -0.154646 0.020104 0.241191 0.427336 0.099988 0.291275
Note: Compare mean or even the 75th percentile values with the GUI sliders’ in (4). Just multiply with 100. Values in the GUI are percentages while the model produces a fraction in the -1 to 1 range as common in ML.