I am trying to load a .h5 model in scala on Intellij Idea.
val modelPath = "/home/userr/IdeaProjects/untitled1/model.h5"
val model: ComputationGraph = KerasModelImport.importKerasModelAndWeights(modelPath,false)
I am using SBT here and my machine is Linux.
The build.sbt file is as follows:
import scala.collection.immutable.Seq
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.13"
libraryDependencies ++= Seq(
"org.deeplearning4j" % "deeplearning4j-core" % "1.0.0-M2.1",
"org.deeplearning4j" % "deeplearning4j-modelimport" % "1.0.0-M2.1",
"org.nd4j" % "nd4j-backends" % "1.0.0-M2.1" % "pom",
"org.bytedeco" % "hdf5" % "1.12.1-1.5.7",
"org.bytedeco" % "hdf5-platform" % "1.12.1-1.5.7",
"org.deeplearning4j" % "deeplearning4j-nn" % "1.0.0-M2.1",
"org.nd4j" % "nd4j-native-platform" % "1.0.0-M2.1",
//"org.nd4j" % "nd4j-native" % "1.0.0-M2.1"
)
Compile / mainClass := Some("ten")
assembly / mainClass := Some("ten")
// removed code for discarding unwanted jars; refer u
assemblyMergeStrategy in assembly := {
case PathList("META-INF", xs @ _*) => MergeStrategy.discard
case x => MergeStrategy.first
}
lazy val root = (project in file("."))
.settings(
name := "untitled1"
)
//,
The program works perfectly with sbt run
command. However, after creating an uber jar, if I try to execute the uber jar, the following error is raised:
Debug: Loading class org.bytedeco.javacpp.presets.javacpp
Debug: Loading class org.bytedeco.javacpp.FloatPointer
Debug: Registering org.bytedeco.javacpp.FloatPointer[address=0x7f50d0541540,position=0,limit=128,capacity=128,deallocator=org.bytedeco.javacpp.Pointer$NativeDeallocator[ownerAddress=0x7f50d0541540,deallocatorAddress=0x7f50493b7e20]]
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.deeplearning4j.nn.modelimport.keras.Hdf5Archive.readDataSet(Hdf5Archive.java:295)
at org.deeplearning4j.nn.modelimport.keras.Hdf5Archive.readDataSet(Hdf5Archive.java:109)
at org.deeplearning4j.nn.modelimport.keras.utils.KerasModelUtils.importWeights(KerasModelUtils.java:335)
at org.deeplearning4j.nn.modelimport.keras.KerasModel.<init>(KerasModel.java:188)
at org.deeplearning4j.nn.modelimport.keras.KerasModel.<init>(KerasModel.java:97)
at org.deeplearning4j.nn.modelimport.keras.utils.KerasModelBuilder.buildModel(KerasModelBuilder.java:311)
at org.deeplearning4j.nn.modelimport.keras.KerasModelImport.importKerasModelAndWeights(KerasModelImport.java:150)
at ten$.main(ten.scala:13)
at ten.main(ten.scala)
Caused by: java.lang.RuntimeException: org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException: Please ensure that you have an nd4j backend on your classpath. Please see: https://deeplearning4j.konduit.ai/nd4j/backend
at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:5066)
at org.nd4j.linalg.factory.Nd4j.<clinit>(Nd4j.java:284)
... 9 more
Caused by: org.nd4j.linalg.factory.Nd4jBackend$NoAvailableBackendException: Please ensure that you have an nd4j backend on your classpath. Please see: https://deeplearning4j.konduit.ai/nd4j/backend
at org.nd4j.linalg.factory.Nd4jBackend.load(Nd4jBackend.java:211)
at org.nd4j.linalg.factory.Nd4j.initContext(Nd4j.java:5062)
... 10 more
The error occurs only when the uber jar is executed.
Can somebody guide me to resolve this?