Skip to content

Exception in thread "main" java.lang.IncompatibleClassChangeError: Method 'org.tensorflow.Tensor org.tensorflow.types.TInt32.vectorOf(int[])' must be InterfaceMethodref constant #97

@aday00

Description

@aday00

Thanks for helping me build a working .jar file containing TensorflowJava per #96!

Would a colleague kindly help me with the following runtime error, when I run my tests within a Docker container:

root@4f6083770318:tensorflow-java# java -jar my.jar tf --verbose
DEBUG 1596940815346: Started ndarray TensorflowJavaTest.
DEBUG 1596940815727: matrix3d rank 3
DEBUG 1596940815727: Finished ndarray TensorflowJavaTest.
DEBUG 1596940815728: Started graph TensorflowJavaTest.
DEBUG 1596940819085: fetch_test fetched.data.getInt(0)=3 is 3? true
DEBUG 1596940819087: fetch_test fetched.data.getInt(1)=4 is 4? true
Exception in thread "main" java.lang.IncompatibleClassChangeError: Method 'org.tensorflow.Tensor org.tensorflow.types.TInt32.vectorOf(int[])' must be InterfaceMethodref constant
        at vis.TensorflowJavaTest.feed_test(tf.scala:80)
        at vis.TensorflowJavaTest.run(tf.scala:106)
        at vis.TensorflowJavaTest$.runArgs(tf.scala:58)
        at vis.VIS$.main(vis.scala:171)
        at vis.VIS.main(vis.scala)

My tests are based on runUsingColonSeparatedNames() in SessionTest.java, and I re-wrote some in Scala.

The test body is:

      debug("Started ndarray TensorflowJavaTest.")
      // run simple data buffers test as in https://github.com/tensorflow/java/tree/master/ndarray
      val matrix3d = org.tensorflow.ndarray.NdArrays.ofInts( org.tensorflow.ndarray.Shape.of(2, 3, 2) )
      debug("matrix3d rank " + matrix3d.rank)
      debug("Finished ndarray TensorflowJavaTest.")

      debug("Started graph TensorflowJavaTest.")
      // run simple graph and session tests per https://github.com/tensorflow/java/blob/master/tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/SessionTest.java
      val graph = new org.tensorflow.Graph() // defined in https://github.com/tensorflow/java/blob/master/tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/Graph.java
      val session = new org.tensorflow.Session(graph)
      val tf = org.tensorflow.op.Ops.create(graph)

      fetch_test(session, tf)
      feed_test(session, tf)

      debug("Finished graph TensorflowJavaTest.")

The fetch test is:

    private def fetch_test(session: org.tensorflow.Session, tf: org.tensorflow.op.Ops): Unit = {
      val split = tf.split( tf.constant(0), tf.array(1, 2, 3, 4), 2l)
      tf.math.add(split.output().get(0), split.output().get(1))
      // Fetch using colon separated names.
      val fetched = session.runner().fetch("Split:1").run().get(0).expect(org.tensorflow.types.TInt32.DTYPE)
      val fetch0 = fetched.data().getInt(0)
      debug("fetch_test fetched.data.getInt(0)=%d is 3? %b".format(fetch0, fetch0 == 3)) // expected to be 3
      val fetch1 = fetched.data().getInt(1)
      debug("fetch_test fetched.data.getInt(1)=%d is 4? %b".format(fetch1, fetch1 == 4)) // expected to be 4
    }

The feed test is:

      import scala.collection.JavaConversions._ // convert java iterator to scala iterator with foreach defined.  Allows TensorflowJava's NdArraySequence to be treated as a Java Iterable, to be treated as a Scala Iterable, so mkString() will work 
...
    private def feed_test(session: org.tensorflow.Session, tf: org.tensorflow.op.Ops): Unit = {
      // Feed using colon separated names.
      val fed = org.tensorflow.types.TInt32.vectorOf(4, 3, 2, 1) // <-- line 80, throws IncompatibleClassChangeError at runtime
      val fetched = session.runner()
                           .feed("Split:0", fed)
                           .feed("Split:1", fed)
                           .fetch("Add")
                           .run()
                           .get(0)
                           .expect(org.tensorflow.types.TInt32.DTYPE)
      val data = fetched.data()
      debug("feed_test fetched.data=%s".format(data.scalars.mkString(",")))
    }

Kindly advise what is wrong with the line val fed = org.tensorflow.types.TInt32.vectorOf(4, 3, 2, 1), which throws the IncompatibleClassChangeError at runtime?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions