1

Hi I am trying to extract the output of the penulitmate layer from a pre trained model(RsNet-152) in MxNet. As I need the script to work with a java application, I going with scala as the choice of language.

I followed the steps mentioned here https://mxnet.incubator.apache.org/tutorials/python/predict_image.html

and modified by script accordingly. Here is the loadModel function.

  def loadResnetModel(modelPath: String): Module = {
val (net, argParams, auxParams) = Model.loadCheckpoint(modelPath, modelFileNumber)
val allLayer = net.getInternals()
val secondLastLayer = allLayer.get("flatten0_output")
val mod = new Module(symbolVar = secondLastLayer, contexts = Context.cpu(), labelNames =null)
val dataShape = ListMap("data" -> Shape(1, 3, 224, 224))
mod.bind(dataShapes=dataShape, forTraining = false)
mod.setParams(argParams, auxParams, allowMissing=true)
mod

when trying to run the script, I am getting the following error.

 Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: Find name fc1_bias that is not in the arguments
 [java]     at scala.Predef$.require(Predef.scala:224)
 [java]     at org.apache.mxnet.Executor$$anonfun$copyParamsFrom$1.apply(Executor.scala:274)
 [java]     at org.apache.mxnet.Executor$$anonfun$copyParamsFrom$1.apply(Executor.scala:270)
 [java]     at scala.collection.immutable.HashMap$HashMap1.foreach(HashMap.scala:221)
 [java]     at scala.collection.immutable.HashMap$HashTrieMap.foreach(HashMap.scala:428)
 [java]     at scala.collection.immutable.HashMap$HashTrieMap.foreach(HashMap.scala:428)
 [java]     at scala.collection.immutable.HashMap$HashTrieMap.foreach(HashMap.scala:428)
 [java]     at org.apache.mxnet.Executor.copyParamsFrom(Executor.scala:270)
 [java]     at org.apache.mxnet.module.DataParallelExecutorGroup$$anonfun$setParams$1.apply(DataParallelExecutorGroup.scala:452)
 [java]     at org.apache.mxnet.module.DataParallelExecutorGroup$$anonfun$setParams$1.apply(DataParallelExecutorGroup.scala:452)
 [java]     at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
 [java]     at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
 [java]     at org.apache.mxnet.module.DataParallelExecutorGroup.setParams(DataParallelExecutorGroup.scala:452)
 [java]     at org.apache.mxnet.module.Module.setParams(Module.scala:201)

P.S : I am new to mxnet and scala. Is there any obvious mistake I am not seeing?

  • What do you see if you output `argParams`? Looks like somehow a bias parameter is missing in argParams. I have a feeling somehow the prefix is different. – Sina Afrooze Dec 14 '18 at 02:31

1 Answers1

1

You need to change the last line in your function: Instead of mod.setParams(argParams, auxParams, allowMissing=true) you need to call mod.setParams(argParams, auxParams)

NRauschmayr
  • 131
  • 1