eaplatanios / tensorflow_scala

TensorFlow API for the Scala Programming Language
http://platanios.org/tensorflow_scala/
Apache License 2.0
939 stars 95 forks source link

org.platanios.tensorflow.jni.NotFoundException #190

Open shilkazx opened 3 years ago

shilkazx commented 3 years ago

Platform: Archlinux x86_64, with Arch's official tensorflow-opt 2.3.1-7 package installed. Scala version: 2.12.12

After import org.platanios.tensorflow.api._, I just try the simple snippet: val t1 = Tensor(1.2, 4.5) then scala throw the following error:

org.platanios.tensorflow.jni.NotFoundException: /tmp/tensorflow_scala_native_libraries18100586144836986571/libtensorflow_ops.so: undefined symbol: _ZN10tensorflow8OpKernel11TraceStringEPNS_15OpKernelContextEb at org.platanios.tensorflow.jni.TensorFlow$.loadOpLibrary(Native Method) at org.platanios.tensorflow.jni.TensorFlow$.$anonfun$load$6(TensorFlow.scala:101) at scala.collection.immutable.List.foreach(List.scala:431) at org.platanios.tensorflow.jni.TensorFlow$.load(TensorFlow.scala:101) at org.platanios.tensorflow.jni.TensorFlow$.(TensorFlow.scala:169) at org.platanios.tensorflow.jni.TensorFlow$.(TensorFlow.scala) at org.platanios.tensorflow.jni.Tensor$.(Tensor.scala:24) at org.platanios.tensorflow.jni.Tensor$.(Tensor.scala) at org.platanios.tensorflow.api.tensors.Tensor$.fill(Tensor.scala:842) at org.platanios.tensorflow.api.tensors.Implicits.tensorFromSupportedType(Implicits.scala:32) at org.platanios.tensorflow.api.tensors.Implicits.tensorFromSupportedType$(Implicits.scala:31) at org.platanios.tensorflow.api.package$.tensorFromSupportedType(package.scala:21) at org.platanios.tensorflow.api.implicits.Implicits.doubleToTensor(Implicits.scala:62) at org.platanios.tensorflow.api.implicits.Implicits.doubleToTensor$(Implicits.scala:61) at org.platanios.tensorflow.api.package$.doubleToTensor(package.scala:21) at $line3.$read$$iw$$iw$$iw$$iw$.(:14) at $line3.$read$$iw$$iw$$iw$$iw$.() at $line3.$eval$.$print$lzycompute(:7) at $line3.$eval$.$print(:6) at $line3.$eval.$print() at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.call(IMain.scala:747) at scala.tools.nsc.interpreter.IMain$Request.loadAndRun(IMain.scala:1020) at scala.tools.nsc.interpreter.IMain.$anonfun$interpret$1(IMain.scala:577) at scala.reflect.internal.util.ScalaClassLoader.asContext(ScalaClassLoader.scala:41) at scala.reflect.internal.util.ScalaClassLoader.asContext$(ScalaClassLoader.scala:37) at scala.reflect.internal.util.AbstractFileClassLoader.asContext(AbstractFileClassLoader.scala:41) at scala.tools.nsc.interpreter.IMain.loadAndRunReq$1(IMain.scala:576) at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:603) at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:573) at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:865) at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:733) at scala.tools.nsc.interpreter.ILoop.processLine(ILoop.scala:435) at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:456) at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:1048) at xsbt.ConsoleBridge.run(ConsoleBridge.scala:75) at sbt.internal.inc.AnalyzingCompiler.console(AnalyzingCompiler.scala:209) at sbt.Console.console0$1(Console.scala:64) at sbt.Console.$anonfun$apply$5(Console.scala:73) at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) at sbt.util.InterfaceUtil$$anon$1.get(InterfaceUtil.scala:17) at sbt.TrapExit$App.run(TrapExit.scala:258) at java.base/java.lang.Thread.run(Thread.java:834)

Btw. I also run a python version tensorflow sample on the same environment, everything is fine. I've already done some google work, but found nothing helpful. Please help me. Thanks a million.

akopich commented 3 years ago

I experience exactly the same issue. I run Archlinux and tried tensorflow-opt package too. I've also built tensorflow from source to the same effect.

novakov-alexey-zz commented 3 years ago

@akopich, @shilkazx if you can test with Ammonite, you can try below simple script.

test.sc :

// scala 2.13.4

interp.load.ivy(
  ("org.platanios" %% "tensorflow" % "0.5.10").withClassifier("linux")
)

import $ivy.`org.platanios::tensorflow:0.5.10`

import org.platanios.tensorflow.api._

val t1 = Tensor(1.2, 4.5)
println(t1.summarize())

It should print:

Tensor[Double, [2]]
[1.2, 4.5]

It should also work with SBT like this:

lazy val root = (project in file("."))
  .settings(
    name := "tensorflow-ann",
    libraryDependencies ++= Seq(
      "org.platanios" %% "tensorflow" % "0.5.10" classifier "linux"     
    )
  )
akopich commented 3 years ago

@novakov-alexey thank you. I had the classifier "linux" part missing.

akopich commented 3 years ago

@novakov-alexey but wait, doesn't it just pull the generic binaries from the repo? I removed the tensorflow-related packages and the code still works.

novakov-alexey-zz commented 3 years ago

@akopich welcome. Platform specific jar from Maven central contains dyn libs that are eventually used by JVM+JNI. I think @eaplatanios can clarify this moment better than I.