Ah. A terminally curious insomniac. Such questions will, most certainly, play hob with your circadian rhythms — too much, and you’ll turn into a technical writer. From there, you will lose all contact with your kith and kin; but if you must know:
TL;DR
- Argument one: picks a neural network and associated weights.
- Argument two: sets a patch size.
Read after breakfast:
Try (in a linux bash shell; with Windows, your mileage will vary):
gmic input_cached gmic_denoise_cnn.gmz k[1] unserialize. ot. /tmp/gmic_nnet.gmic
which (hopefully), in your world, dumps out in a manner similar to this:
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input cached file 'gmic_denoise_cnn.gmz'.
[gmic]-5./ Keep image [1] (1 image left).
[gmic]-1./ Unserialize image [0].
[gmic]-1./ Output image [12] as text-data file '/tmp/gmic_nnet.gmic'.
[gmic]-13./ End G'MIC interpreter.
And then:
$ cat /tmp/gmic_nnet.gmic
nn_init nn_layer_input X,32,32,1,3 nn_layer_clone X0,X1,X nn_layer_conv2d BLUR,X1,3,5,1,1,0 nn_layer_append X2,X0,BLUR nn_layer_conv2d C1_0,X2,32,3,1,1,1 nn_layer_nl C1,C1_0,leakyrelu nn_layer_conv2d C2_0,C1,32,3,1,1,1 nn_layer_nl C2,C2_0,leakyrelu nn_layer_conv2d C3_0,C2,32,3,1,1,1 nn_layer_nl C3,C3_0,leakyrelu nn_layer_conv2d C4_0,C3,32,3,1,1,1 nn_layer_nl C4,C4_0,leakyrelu nn_layer_conv2d C5_0,C4,32,3,1,1,1 nn_layer_nl C5,C5_0,leakyrelu nn_layer_conv2d C6_0,C5,32,3,1,1,1 nn_layer_nl C6,C6_0,leakyrelu nn_layer_conv2d C7_0,C6,32,3,1,1,1 nn_layer_nl C7,C7_0,leakyrelu nn_layer_conv2d C8_0,C7,32,3,1,1,1 nn_layer_nl C8,C8_0,leakyrelu nn_layer_conv2d C9_0,C8,32,3,1,1,1 nn_layer_nl C9,C9_0,leakyrelu nn_layer_conv2d C10_0,C9,32,3,1,1,1 nn_layer_nl C10,C10_0,leakyrelu nn_layer_conv2d C11,C10,3 nn_layer_add OUT0,C11,BLUR nn_layer_crop OUT,OUT0,2,2,0,29,29,0 nn_loss_mse L,OUT,Y nn_trainer T,L,1e-4,adam,constant
NB: the file gmic_denoise_cnn.gmz
almost certainly lives in your gmic cache directory; it is implicitly downloaded once you start working with the various nn_*
commands ( But, sometimes, not ). That compressed file is a container for the various neural networks that @David_Tschumperle has published so far. Here, we pick one arbitrarily, type 1, aka heavy
, from the set: (0) smooth
, (1) heavy
, (2) heavy (faster)
, (3) poisson+gaussian
, (4) poisson+gaussian2,
unserialize it, giving us 12 data sets (packaged as images) and a gmic script, also packaged as an image. We text-output that last image into a temporary file for later study.
I have not (so far) spelunked any of these scripts or allied data sets. In the fullness of time (which, in Tutorial Land, can approach decades), I should make a Beginner’s Cookbook. Not now; read Neural Networks in G’MIC: An introduction to the API of nn_lib
instead. In any case, that’s your first argument to denoise_cnn
: it picks one of the five neural network scripts that have been composed so far at the Global G’MIC World Headquarters, along with its allied data sets, and the same are turned loose onto your noisy photographs.
The second argument, patch_size
, is more tractable. It runs img2patches <patch_size>,6,3 on your image. That cuts the image into patch_size × patch_size
squares with mirrored overlap regions (6 pixels wide) on the borders so that the workload can be spread among the various cores you have available. When we run off of edges, mirror policy is in play.
So, ignorant that I is of neural network types, I just take them to be various magical black boxes and write myself a little finger exercise to spelunk , let’s call it noisesampler.gmic
:
dncnnsample: skip ${1=0}
-check isint($1)
patchsz=$1
denoisetypes=smooth,heavy,heavy\ (faster),poisson+gaussian,poisson+gaussian2
numtypes=narg($denoisetypes)
-name. testimg
-arg2var _ns,$denoisetypes
-repeat $numtypes
+denoise[testimg] $_ns{$>},$patchsz
-normalize. 0,255
-text_outline. "Type:\ "${_ns{$>+1}},8,8,15,1
-text_outline. "Patch\ Size:\ "$patchsz,8,23,15,1
-done
text_outline[0] "Original",8,8,15,1
And a run of that might give you something like this:
$ gmic noisesampler.gmic input alice.jpg r2dx. 25%,5 n. 0,255 noise. 10 dncnnsample. 16
And with a big patch size of 128:
$ gmic noisesampler.gmic input alice.jpg r2dx. 25%,5 n. 0,255 noise. 10 dncnnsample. 128
Larger patches run faster, but seem to be lower in quality. But (!) — your mileage may vary. It is always worth one’s while to explore parameter spaces with finger exercises. Especially before big batch runs.
This should be enough to burn off the rest of your day. Have fun!