I was surprised to learn that there is no custom "Function" named decoder for NetDecoder
, as there is for NetEncoder
. Has anyone perchance found a way to make a custom decoder with NetDecoder
?
$\begingroup$
$\endgroup$
3
-
1$\begingroup$ Yes, this definitely seems like a bit of an oversight! I've gotten around it in the past by reimplementing my netdecoder as a subnetwork, but that's no fun and doesn't extend well... $\endgroup$– Carl LangeCommented Oct 23, 2018 at 7:58
-
1$\begingroup$ I think it's very likely that the developer forgot to add this. $\endgroup$– AsterCommented Oct 23, 2018 at 16:16
-
2$\begingroup$ Official support is coming in 12, I just asked on the livestream. $\endgroup$– Carl LangeCommented Oct 23, 2018 at 21:03
Add a comment
|
1 Answer
$\begingroup$
$\endgroup$
1
Save this as *.m
Input: RealTensorT
Parameters:
$Function: FunctionT
ToDecoderFunction: Function[#Function]
Kind: "expression"
Then load this by:
<< NeuralNetworks`
file = "the path.m";
def = NeuralNetwork`Private`ReadDefinitionFile[file, "System`"];
NeuralNetworks`DefineDecoder["Function", def];
Let's do some test:
decoder=NetDecoder[{"Function",Image[#,Interleaving->False]&}]
net=NetChain[{ElementwiseLayer[#&]},"Output"->decoder]
net[RandomReal[1,{3,128,128}]]
But you still have to wait for official support, any custom behavior will cause the network cannot be imported back.