Skip to content

Static methods in interface require -target:jvm-1.8 #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shuDaoNan9 opened this issue Mar 31, 2021 · 10 comments
Closed

Static methods in interface require -target:jvm-1.8 #265

shuDaoNan9 opened this issue Mar 31, 2021 · 10 comments

Comments

@shuDaoNan9
Copy link

I can't create any tensor, the error message is:
Error:(141, 52) Static methods in interface require -target:jvm-1.8
val fed2 = TInt32.tensorOf( org.tensorflow.ndarray.NdArrays.vectorOf(4, 3, 2, 1) )
Error:(142, 51) Static methods in interface require -target:jvm-1.8
val fed = TInt32.tensorOf(Shape.of(4)).setInt(4, 0).setInt(3, 1).setInt(2, 2).setInt(1, 3)
Error:(149, 37) Static methods in interface require -target:jvm-1.8
val itemId_index=TInt32.vectorOf(6135)
........

my scala code for test is:

    val fed2 = TInt32.tensorOf( org.tensorflow.ndarray.NdArrays.vectorOf(4, 3, 2, 1) )
    val fed = TInt32.tensorOf(Shape.of(4)).setInt(4, 0).setInt(3, 1).setInt(2, 2).setInt(1, 3)
    val a: Array[Int] =Array(1311,1205,1210,0,0,0,0,0,0,0)
    val genres = TInt32.tensorOf(StdArrays.ndCopyOf(a))
    val id_index=TInt32.vectorOf(450)

the version is:

        <dependency>
            <groupId>org.tensorflow</groupId>
            <artifactId>tensorflow-core-api</artifactId>
            <version>0.3.1</version>
        </dependency>

my environment:
Windows10 64bit,
idea 2018.3.5,
jdk1.8

Thank you!

@shuDaoNan9
Copy link
Author

shuDaoNan9 commented Mar 31, 2021

Infact I don't know what ${javacpp.platform.extension} is, and haven't add this:

<dependency>
  <groupId>org.tensorflow</groupId>
  <artifactId>tensorflow-core-api</artifactId>
  <version>0.3.1</version>
  <classifier>windows-x86_64${javacpp.platform.extension}</classifier>
</dependency>

Instead, I delete ${javacpp.platform.extension} like this:

  <dependency>
            <groupId>org.tensorflow</groupId>
            <artifactId>tensorflow-core-api</artifactId>
            <version>0.3.1</version>
            <classifier>windows-x86_64</classifier>
        </dependency>

@Craigacp
Copy link
Collaborator

Craigacp commented Mar 31, 2021

Looks like that's a Scala issue not a TF-Java issue, you need to tell the Scala compiler to use the appropriate JVM backend - https://stackoverflow.com/questions/49213620/static-methods-in-interface-require-targetjvm-1-8.

If you use the core api jar without a specifier then it will use CPUs to execute all the code. This is fine assuming that's what you want. Otherwise you can supply one of "-mkl", "-gpu" and "-mkl-gpu" to have Intel's oneDNN support, CUDA GPU support or both.

@shuDaoNan9
Copy link
Author

shuDaoNan9 commented Apr 1, 2021

have

thanks, but my scala(spark) project works well for 2 years without using TF-Java 0.3.1. And work well with the old version ( TensorFlow1.14). when I use the old version, I can create tensor like 'Tensor.create(Array(0.000231F,0.008493F))' correctly.
The old dependencies version is:

        <dependency>
            <groupId>org.tensorflow</groupId>
            <artifactId>tensorflow</artifactId>
            <version>1.14.0</version>
        </dependency>
        <dependency>
            <groupId>org.tensorflow</groupId>
            <artifactId>libtensorflow</artifactId>
            <version>1.14.0</version>
        </dependency>
        <dependency>
            <groupId>org.tensorflow</groupId>
            <artifactId>libtensorflow_jni_gpu</artifactId>
            <version>1.14.0</version>
        </dependency>
        <dependency>
            <groupId>org.tensorflow</groupId>
            <artifactId>proto</artifactId>
            <version>1.14.0</version>
        </dependency>

I will try a new scala project after that.

I did as you say, but...
图片

@Craigacp
Copy link
Collaborator

Craigacp commented Apr 1, 2021

If your Scala project wasn't calling any default methods on Java interfaces then it wouldn't have triggered the issue. We use them extensively in TF-Java, and they've been part of Java since Java 8 was released in 2014.

It looks like it found the mkl dependency, as it managed to resolve some of its dependencies. Does Maven give you an error message when building?

@shuDaoNan9
Copy link
Author

shuDaoNan9 commented Apr 1, 2021

I update the last reply just now. when I try to build the project, the error message is the same:

Error:(142, 31) Static methods in interface require -target:jvm-1.8
    val fed2 = TInt32.tensorOf( org.tensorflow.ndarray.NdArrays.vectorOf(4, 3, 2, 1) )

And I can build my project correctly without try to create tensor.

I tried a new project, but facing the same error.

@shuDaoNan9
Copy link
Author

shuDaoNan9 commented Apr 1, 2021

First, I trainned my model with TF2.4.0.
Second, I tried to use the PB model in my scala project with old dependencies( TF1.14 ), but failed:

Caused by: java.lang.IllegalArgumentException: ConcatOp : Expected concatenating dimensions in the range [-1, 1), but got 1
	 [[{{node StatefulPartitionedCall/StatefulPartitionedCall/model/concatenate_1/concat}}]]
	at org.tensorflow.Session.run(Native Method)
	at org.tensorflow.Session.access$100(Session.java:48)
	at org.tensorflow.Session$Runner.runHelper(Session.java:322)
	at org.tensorflow.Session$Runner.run(Session.java:272)

Third, I tried to use the PB model in my scala project with old dependencies( TF1.15 ), but failed:

java.lang.IllegalArgumentException: ConcatOp : Expected concatenating dimensions in the range [-1, 1), but got 1
	 [[{{node model/concatenate_4/concat}}]]
	at org.tensorflow.Session.run(Native Method)
	at org.tensorflow.Session.access$100(Session.java:48)
	at org.tensorflow.Session$Runner.runHelper(Session.java:326)
	at org.tensorflow.Session$Runner.run(Session.java:276)
	at xdeepfm$.getScore(xdeepfm.scala:173)

last, I tried to use the PB model in my scala project with new dependencies( TF-Java 0.3.1 ), but failed to create any tensor.

@Craigacp
Copy link
Collaborator

Craigacp commented Apr 1, 2021

I update the last reply just now. when I try to build the project, the error message is the same:

Error:(142, 31) Static methods in interface require -target:jvm-1.8
    val fed2 = TInt32.tensorOf( org.tensorflow.ndarray.NdArrays.vectorOf(4, 3, 2, 1) )

And I can build my project correctly without try to create tensor.

I tried a new project, but facing the same error.

Yes, but the issue is due to your scala build, not a problem in TF-Java. The 1.x version didn't use default methods as heavily, so you didn't hit the issue. The new one does, so you need to make sure that your Scala compiler is happy with using 7 year old language features from Java 8.

@Craigacp
Copy link
Collaborator

Craigacp commented Apr 1, 2021

I wouldn't expect TF 1.x to be able to load a TF 2 model so that's not too surprising.

@shuDaoNan9
Copy link
Author

shuDaoNan9 commented Apr 1, 2021

not

yes, I mean this error message only appears while I try to create tensor by using TF-Java 0.3+

I update the last reply just now. when I try to build the project, the error message is the same:

Error:(142, 31) Static methods in interface require -target:jvm-1.8
    val fed2 = TInt32.tensorOf( org.tensorflow.ndarray.NdArrays.vectorOf(4, 3, 2, 1) )

And I can build my project correctly without try to create tensor.
I tried a new project, but facing the same error.

Yes, but the issue is due to your scala build, not a problem in TF-Java. The 1.x version didn't use default methods as heavily, so you didn't hit the issue. The new one does, so you need to make sure that your Scala compiler is happy with using 7 year old language features from Java 8.

I add '-target:jvm-1.8' to my setting just now:
图片

and the error message changed, I can't load my model and create tensor now:

Warning: Could not load Loader: java.lang.UnsatisfiedLinkError: no jnijavacpp in java.library.path
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jnitensorflow in java.library.path
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1865)
	at java.lang.Runtime.loadLibrary0(Runtime.java:870)
	at java.lang.System.loadLibrary(System.java:1122)
	at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1683)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1300)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1123)
	at org.tensorflow.internal.c_api.global.tensorflow.<clinit>(tensorflow.java:12)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1190)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1139)
	at org.tensorflow.NativeLibrary.load(NativeLibrary.java:48)
	at org.tensorflow.TensorFlow.init(TensorFlow.java:111)
	at org.tensorflow.TensorFlow.<clinit>(TensorFlow.java:126)
	at org.tensorflow.RawTensor.<clinit>(RawTensor.java:231)
	at org.tensorflow.Tensor.of(Tensor.java:88)
	at org.tensorflow.Tensor.of(Tensor.java:154)
	at org.tensorflow.Tensor.of(Tensor.java:126)
	at org.tensorflow.types.TInt32.tensorOf(TInt32.java:69)
...
Caused by: java.lang.UnsatisfiedLinkError: no tensorflow_cc in java.library.path
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1865)
	at java.lang.Runtime.loadLibrary0(Runtime.java:870)
	at java.lang.System.loadLibrary(System.java:1122)
	at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1683)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1227)
	... 16 more

So, I followed this way #259

        <dependency>
            <groupId>org.tensorflow</groupId>
            <artifactId>tensorflow-core-platform</artifactId>
            <version>0.3.1</version>
        </dependency>

Everything's all right now! Thank you very much!

@shuDaoNan9
Copy link
Author

By the way, I tried to add '-target:jvm-1.8' to my pom.xml first, but it do not work.

<build>
	<plugins>
		<plugin>
			<groupId>org.scala-tools</groupId>
			<artifactId>maven-jar-plugin</artifactId>
			<!--<version>2.3.1</version>-->
			<configuration>
				<archive>
					<manifest>
						<mainClass>my.test.classname</mainClass>
					</manifest>
				</archive>
				<addScalacArgs>-target:jvm-1.8</addScalacArgs>
			</configuration>
		</plugin>
	</plugins>
</build>

So I change my IDEA setting instead.

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

No branches or pull requests

2 participants