I have come across this neat explanation on how to adjust a pre-trained Inception neural net to an arbitrary number of classes by truncating the top layers.
However, my input data does not come in $299 \times 299$ RGB images, but rather in $100 \times 100$ RGB images. I want to essentially get rid of the input layer, and replace it by a custom one ($3 \times 100 \times 100$ instead of $3 \times 299 \times 299$).
Here would be the loaded MXNet model:
net = NeuralNetworks`ImportMXNetModel[
NotebookDirectory[] <> "model//Inception-7-symbol.json",
NotebookDirectory[] <> "model//Inception-7-0001.params"];
Which we then adapt to a custom number of classes (75):
net2 = NetGraph[{Take[net, {NetPort["Input"], "flatten"}],
75, SoftmaxLayer[]},
{1 -> 2 -> 3},
"Input" -> NetEncoder[{"Image", {100, 100}, ColorSpace -> "RGB"}],
"Output" -> NetDecoder[{"Class", Range[0, 74]}]]
However, as expected, this throws an error, because, from what I understand, I am simply adding a new Input
layer, and not modifying the one from net
.
How could I adapt the existing model (net
) to handle inputs (i.e., images) with a lower number of dimensions (resolution)?
I know this can be done in Python's keras
module by re-wiring the inputs to a custom Input layer, but I am not sure on how to proceed in Mathematica.
Any help and advice appreciated!