Thanks Jerome. So it's not feasible to realistically reduce the stride.
I hope this similar topic will also interest you. What about sliding this denoising autoencoder?
size = 157;
n1 = 32;
k = 5;
conv2[n_] :=
NetChain[{ConvolutionLayer[n, k, "Stride" -> 2],
BatchNormalizationLayer[], ElementwiseLayer["ReLU"],
DropoutLayer[], ConvolutionLayer[n, k, "Stride" -> 2],
BatchNormalizationLayer[], ElementwiseLayer["ReLU"]}];
deconv2[n_] :=
NetChain[{DeconvolutionLayer[n, k, "Stride" -> 2],
BatchNormalizationLayer[], ElementwiseLayer["ReLU"],
DropoutLayer[], DeconvolutionLayer[n/2, k, "Stride" -> 2],
BatchNormalizationLayer[], ElementwiseLayer["SoftSign"]}];
sum[] := NetChain[{TotalLayer["Inputs" -> 2]}];
constantPowerLayer[] := NetChain[{
ElementwiseLayer[Log@Clip[#, {$MachineEpsilon, 1}] &],
ConvolutionLayer[1, 1, "Biases" -> None, "Weights" -> {{{{1}}}}],
ElementwiseLayer[Exp]}]
ddae = NetGraph[
<|
"bugworkaround" -> ElementwiseLayer[# &],
"c12" -> conv2[n1],
"c34" -> conv2[2*n1],
"d12" -> deconv2[2*n1],
"d34" ->
NetChain[{DeconvolutionLayer[n1, k, "Stride" -> 2],
BatchNormalizationLayer[], ElementwiseLayer["ReLU"],
DeconvolutionLayer[1, k, "Stride" -> 2],
BatchNormalizationLayer[], ElementwiseLayer["SoftSign"]}],
"sum1" -> sum[],
"sum2" -> NetChain[{sum[], constantPowerLayer[]}],
"loss" -> MeanSquaredLossLayer[]
|>,
{
"bugworkaround" ->
"c12" ->
"c34" ->
"d12" -> "sum1" -> "d34" -> "sum2" -> NetPort["loss", "Input"],
"bugworkaround" -> "sum2",
NetPort["Noisy"] -> "bugworkaround",
"c12" -> "sum1",
NetPort["Target"] -> NetPort["loss", "Target"]
},
"Noisy" ->
NetEncoder[{"Image", {size, size}, ColorSpace -> "Grayscale"}],
"Target" ->
NetEncoder[{"Image", {size, size}, ColorSpace -> "Grayscale"}]
]
trained = NetTake[NetInitialize@ddae, {"bugworkaround", "sum2"}]
Now I "automatize" the input dimensions:
n3 = NetReplacePart[trained, "Noisy" -> Automatic];
This new network works fine if given same dimensions, but fails with larger input dimensions. Any idea how to fix this problem?
In[142]:= n3[RandomReal[1, {1, 157, 157}]] // Dimensions
Out[142]= {1, 157, 157}
In[143]:= n3[RandomReal[1, {1, 1570, 1570}]] // Dimensions
During evaluation of In[143]:= NetGraph::tyfail1: Inferred inconsistent value for output size of layer 4 of layer "d34".
Out[143]= {}