Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Scala: DataDesc IllegalArgumentException with simple example #12409

Closed
mariussoutier opened this issue Aug 30, 2018 · 16 comments
Closed

Scala: DataDesc IllegalArgumentException with simple example #12409

mariussoutier opened this issue Aug 30, 2018 · 16 comments
Labels

Comments

@mariussoutier
Copy link

mariussoutier commented Aug 30, 2018

Description

Fitting using Scala and Module API throws an IAE.
Apparently the label shape of (50) doesn't correspond to expected the NCHW format.

Environment info (Required)

macOS 10.13.6
IntelliJ 2018.2.2
Scala 2.11.12
Java 1.8.0_121
MXNet 1.2.1

Error Message:

Exception in thread "main" java.lang.IllegalArgumentException: requirement failed: number of dimensions in shape :1 with shape: (50) should match the length of the layout: 4 with layout: NCHW
	at scala.Predef$.require(Predef.scala:224)
	at org.apache.mxnet.DataDesc.<init>(IO.scala:233)
	at org.apache.mxnet.DataDesc$$anonfun$ListMap2Descs$1.apply(IO.scala:256)
	at org.apache.mxnet.DataDesc$$anonfun$ListMap2Descs$1.apply(IO.scala:256)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
	at scala.collection.Iterator$class.foreach(Iterator.scala:891)
	at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
	at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
	at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
	at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
	at scala.collection.AbstractTraversable.map(Traversable.scala:104)
	at org.apache.mxnet.DataDesc$.ListMap2Descs(IO.scala:256)
	at org.apache.mxnet.module.BaseModule.fit(BaseModule.scala:399)

Minimum reproducible example

    val trainDataIter = IO.ImageRecordIter(Map(
      "data_name" -> dataName,
      "path_imgrec" -> this.getClass.getResource("/data/mydata.rec").getFile,
      "data_shape" -> "(3,128,128)",
      "batch_size" -> "50"
    ))

val mod = new Module(mlp)
    mod.fit(
      trainDataIter,
      Some(testDataIter),
      numEpoch = 10,
      fitParams =
        new FitParams()
          .setOptimizer(new SGD(0.1f, 0.9f, 0.0001f))
    )

Tried debugging this, but pretty difficult to find out what's going on with a stringly typed API.

println(trainDataIter.provideData) -> Map(data -> (50,3,128,128))
println(trainDataIter.provideLabel) -> Map(label -> (50))

@anirudhacharya
Copy link
Member

@mxnet-label-bot [Scala]

@lanking520
Copy link
Member

Hi @mariussoutier this problem actually addressed in 1.3 in this PR: #11844. Try with this one!

@mariussoutier
Copy link
Author

@lanking520 Is there a published version of that I can use or do I have to build it myself?

@lanking520
Copy link
Member

Unfortunately, you need to build from source with 1.3 or please wait for us to publish that. It will be out very soon.

@mariussoutier
Copy link
Author

Ok I'll test again then. I feel like the Scala API could use some love :-)

@nswamy
Copy link
Member

nswamy commented Sep 4, 2018

@mariussoutier we are working on a 1.3.0 pre-release, we should be able to have a RC maven package in staging soon.

@mariussoutier
Copy link
Author

Nice, looking forward to it.

@nswamy
Copy link
Member

nswamy commented Sep 12, 2018

@mariussoutier we released the package to Staging here if you would like to test it.
https://repository.apache.org/content/repositories/staging/org/apache/mxnet/

See the instructions on how to use packages in Staging repo here:
https://cwiki.apache.org/confluence/display/MXNET/MXNet-Scala+Release+Process#MXNet-ScalaReleaseProcess-UsingPackagesinStagingRepository

@mariussoutier
Copy link
Author

@nswamy Just tried it out, Module API seems to work now. Thanks!

@mariussoutier
Copy link
Author

Is there any difference between Module and FeedForward anyway?

@nswamy
Copy link
Member

nswamy commented Sep 13, 2018

Feedforward as the name suggests works for FeedForward networks which are single input/single output but Module APIs will work for multi-input/multi-output FeedForward and CNNs, GANs, RNNs(probably requires the extended Bucketing Module which is in examples)

@mariussoutier
Copy link
Author

Ok, makes sense. I've also used FeedForward for my CNN :-)

@mariussoutier
Copy link
Author

One more issue, Module-based GPU training on Ubuntu fails during the second epoch with a SIGTERM. I don't know yet what's happening. FeedForward-based training in 1.2.1 works without a problem.

@nswamy
Copy link
Member

nswamy commented Sep 13, 2018

could you please open a new issue with some reproducible code?

@mariussoutier
Copy link
Author

Sure, will do.

@ddavydenko
Copy link
Contributor

Seems like this extra question was filed and replied to in #12553. Could we close this issue as it has been addressed in comments above?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants