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$
2
  • $\begingroup$ I am on 11.2, and I get "SoftmaxLayer::argr: SoftmaxLayer called with 1 argument; 0 arguments are expected." $\endgroup$
    – MarcoB
    Commented Apr 27, 2018 at 19:26
  • $\begingroup$ @MarcoB I changed it to just SoftmaxLayer[] $\endgroup$
    – M.R.
    Commented Apr 27, 2018 at 19:28

1 Answer 1

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$
1
  • $\begingroup$ An alternative approach is to use NetAppend[NetDrop[res, -2],{"classify" -> LinearLayer[2], "probs" -> SoftmaxLayer[]}, "Output" -> NetDecoder[{"Class", {"A", "B"}}]]. $\endgroup$
    – Sebastian
    Commented May 15, 2018 at 19:09

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.