My network can output an array of 6x512x512 size at the end, now I want to multiply an array of length 3 for each of these 6 channels to get the color of the different channels, I am using the TensorProduct method and I am giving my code:
f[white_, yellow_, cyan_, blue_, green_, red_] :=
TensorProduct[white, {1, 1, 1}] +
TensorProduct[yellow, {1, 1, 0}] +
TensorProduct[cyan, {0, 1, 1}] + TensorProduct[blue, {0, 0, 1}] +
TensorProduct[green, {0, 1, 0}] +
TensorProduct[red, {1, 0, 0}]
The test data is
mat = Normal@
SparseArray[{{1, 1, 1} -> 1, {2, 2, 2} -> 1, {3, 3, 3} ->
1, {4, 4, 4} -> 1, {5, 5, 5} -> 1, {6, 6, 6} -> 1}, {7, 6, 6}];
the output looks like this (with Image
function)
This works correctly for my needs, now I write this function to the FunctionLayer
, but the problem occurs, the error is reported as.
FunctionLayer::compilerr: Cannot interpret #1 TensorProduct #2 & as a network.
I looked up some references and some people said that Map or Apply can't be executed correctly in FunctionLayer
, but when I tried
FunctionLayer[TensorProduct[#] &]
the code runs fine, but the problem occurs when I use TensorProduct
with parameters such as
FunctionLayer[TensorProduct[#, {1, 1, 1}] &]
then the same error is reported and I don't understand why this problem occurs.
Also I have implemented my function in NetDecoder[{"Function", myfun]]}]
and it gets the right results, but I still don't understand why using theFunctionLayer
code gives an error. I think it's unlikely to be a problem with my custom function. Can someone please give a reasonable explanation or a suggestion for a modification?
Using MMA 13.3 ver. There are ways I can get around using the
FunctionLayer
to get the network I want, but I'm still trying to figure out why I'm getting an error if I write it this way.