3
$\begingroup$

I'm trying to replace the "fc1000" layer in a NetModel, what am I missing here:

net = NetModel["ResNet-152 Trained on ImageNet Competition Data"]
NetReplacePart[net, {
     "fc1000" -> LinearLayer[2],
     "prob" -> SoftmaxLayer[],
     "Output" -> NetDecoder[{"Class", {"A", "B"}}]
 }]

enter image description here

I would love it if someone could write a nice tutorial on real-world applications of inserting/tweaking/moving layers for partial retraining.

$\endgroup$
  • $\begingroup$ I am on 11.2, and I get "SoftmaxLayer::argr: SoftmaxLayer called with 1 argument; 0 arguments are expected." $\endgroup$ – MarcoB Apr 27 '18 at 19:26
  • $\begingroup$ @MarcoB I changed it to just SoftmaxLayer[] $\endgroup$ – M.R. Apr 27 '18 at 19:28
2
$\begingroup$

OK, so NetReplacePart won't work in this case, you need a NetTake:

res = NetModel["ResNet-152 Trained on ImageNet Competition Data"]
net = NetChain[{NetTake[res, {1, "flatten_0"}], LinearLayer[2], 
   SoftmaxLayer[]}, "Output" -> NetDecoder[{"Class", {"A", "B"}}]]
$\endgroup$
  • $\begingroup$ An alternative approach is to use NetAppend[NetDrop[res, -2],{"classify" -> LinearLayer[2], "probs" -> SoftmaxLayer[]}, "Output" -> NetDecoder[{"Class", {"A", "B"}}]]. $\endgroup$ – Sebastian May 15 '18 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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