jeremiedb commented on issue #7968: [R] Transfer Learning using VGG-16
URL: 
https://github.com/apache/incubator-mxnet/issues/7968#issuecomment-332385636
 
 
   There are different ways to approach the fine tuning, which depends on 
whether there are changes to only the weights parameters or also to the model 
architecture (symbol). General idea is to pick whatever you like from the 
pre-trained model and weights and decide which weights should be fixed. Note 
that by default, all weights are retrained.
   
   If what you want is to keep the same VGG  model structure but only modify 
the last one for which the number of hidden units is the number of categories 
(so two 4096 hidden unist FC layers followed by a FC layer which hidden units 
match your number of categories), then you would probably what to start the 
fine-tuning following the last dropout, something like: 
   `drop7 <- internals$get.output(which(outputs == "fc7_output"))`
   
   Then, you can continue the composition of the symbol like for any model 
designed from scratch. 
   Here the only two remaining elements as can be seen from the [Model 
Zoo](http://data.dmlc.ml/models/imagenet/vgg/vgg16-symbol.json) are the last FC 
and the SoftMaxOutput: 
   
   ```
   fc_final <- mx.symbol.FullyConnected(data = drop7, num.hidden = you number 
of levels)
   softmax <- mx.symbol.SoftmaxOutput(data = fc_final)
   ```
   
   You can now train using `mx.model.FeedForward.create` and feeding it with 
`softmax` as a symbol. 
   `mx.model.FeedForward.create` has parameters to specify initial weights of 
the model (arg.params) and whether some parameters must be kept fixed 
(fixed.param). If you want to have all parameters prior to fc6 to remain fixed, 
then you will need to pass the vector of these parameters into the 
`fixed.param` argument to that their weights are ignored during update. 
   To reuse the VGG-16 weights, you will also need to feed the `arg.param` 
argument. This will be the list of weights obtained from the pre-trained model, 
except for the final FC layer where you would apply a random initialization as 
illustrated in the cat-dog example. 
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to