3
$\begingroup$

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?

$\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 Lange
    Commented Oct 23, 2018 at 7:58
  • 1
    $\begingroup$ I think it's very likely that the developer forgot to add this. $\endgroup$
    – Aster
    Commented Oct 23, 2018 at 16:16
  • 2
    $\begingroup$ Official support is coming in 12, I just asked on the livestream. $\endgroup$
    – Carl Lange
    Commented Oct 23, 2018 at 21:03

1 Answer 1

5
$\begingroup$

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}]]

enter image description here

But you still have to wait for official support, any custom behavior will cause the network cannot be imported back.

$\endgroup$
1
  • $\begingroup$ Wow, nicely found. $\endgroup$
    – Carl Lange
    Commented Oct 23, 2018 at 21:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.