0

I am getting a nullpointerexception when calling NativeImageLoader.asMatrix(). I am trying to figure out what the trace is telling me. I am working with DeepLearning 1.0.0-beta7.

Any hints? Thanks!

2020-11-03 14:49:17,273 ERROR [stderr] (pool-19-thread-25) java.lang.NullPointerException

2020-11-03 14:49:17,273 ERROR [stderr] (pool-19-thread-25) at org.bytedeco.javacpp.indexer.LongRawIndexer.getRaw(LongRawIndexer.java:73)

2020-11-03 14:49:17,273 ERROR [stderr] (pool-19-thread-25) at org.bytedeco.javacpp.indexer.LongRawIndexer.get(LongRawIndexer.java:76)

2020-11-03 14:49:17,273 ERROR [stderr] (pool-19-thread-25) at org.nd4j.linalg.api.buffer.BaseDataBuffer.getLong(BaseDataBuffer.java:872)

2020-11-03 14:49:17,273 ERROR [stderr] (pool-19-thread-25) at org.nd4j.linalg.jcublas.buffer.BaseCudaDataBuffer.getLongUnsynced(BaseCudaDataBuffer.java:1304)

2020-11-03 14:49:17,273 ERROR [stderr] (pool-19-thread-25) at org.nd4j.linalg.api.buffer.BaseDataBuffer.asLong(BaseDataBuffer.java:813)

2020-11-03 14:49:17,273 ERROR [stderr] (pool-19-thread-25) at org.nd4j.linalg.jcublas.buffer.BaseCudaDataBuffer.asLong(BaseCudaDataBuffer.java:1539)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.nd4j.linalg.api.ndarray.BaseShapeInfoProvider.createShapeInformation(BaseShapeInfoProvider.java:76)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.nd4j.jita.constant.ProtectedCudaShapeInfoProvider.createShapeInformation(ProtectedCudaShapeInfoProvider.java:92)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.nd4j.jita.constant.ProtectedCudaShapeInfoProvider.createShapeInformation(ProtectedCudaShapeInfoProvider.java:73)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.nd4j.linalg.jcublas.CachedShapeInfoProvider.createShapeInformation(CachedShapeInfoProvider.java:42)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.nd4j.linalg.api.ndarray.BaseNDArray.(BaseNDArray.java:181)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.nd4j.linalg.api.ndarray.BaseNDArray.(BaseNDArray.java:310)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.nd4j.linalg.api.ndarray.BaseNDArray.(BaseNDArray.java:363)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.nd4j.linalg.api.ndarray.BaseNDArray.(BaseNDArray.java:786)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.nd4j.linalg.jcublas.JCublasNDArray.(JCublasNDArray.java:287)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.nd4j.linalg.jcublas.JCublasNDArrayFactory.create(JCublasNDArrayFactory.java:172)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.nd4j.linalg.factory.Nd4j.create(Nd4j.java:4247)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.nd4j.linalg.factory.Nd4j.create(Nd4j.java:3964)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.datavec.image.loader.NativeImageLoader.transformImage(NativeImageLoader.java:671)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.datavec.image.loader.NativeImageLoader.asMatrix(NativeImageLoader.java:594)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.datavec.image.loader.Java2DNativeImageLoader.asMatrix(Java2DNativeImageLoader.java:92)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.datavec.image.loader.Java2DNativeImageLoader.asMatrix(Java2DNativeImageLoader.java:70)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.datavec.image.loader.Java2DNativeImageLoader.asMatrix(Java2DNativeImageLoader.java:102)

2020-11-03 14:49:17,274 ERROR [stderr] (pool-19-thread-25) at org.datavec.image.loader.NativeImageLoader.asMatrix(NativeImageLoader.java:407)

Tony Anecito
  • 347
  • 2
  • 13
  • I am using javaCPP 1.5.4. – Tony Anecito Nov 04 '20 at 02:30
  • It looks like there's some initialization problem with your servlet. Make sure all classes from JavaCPP get loaded by the same class loader. – Samuel Audet Nov 04 '20 at 02:51
  • Thanks Samuel. I traced things in the servlet back to ModelSerializer.restoreMultiLayerNetworkNetwork throwing several exceptions which explains this trace. – Tony Anecito Nov 04 '20 at 03:59
  • So I am wondering if there is an issue with the servlet when using that class to read the model file. Still looking at it though. – Tony Anecito Nov 04 '20 at 04:04
  • For now looks like in a servlet the following is failing (java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NullPointerException ) for restoreMultiLayerNetwork(File) or passing in a String for the location in ModelSerializer.restoreMultiLayerNetworkNetwork:org.nd4j.linalg.api.buffer.BaseDataBuffer.read(BaseDataBuffer.java:1572) – Tony Anecito Nov 05 '20 at 09:09
  • Traced exception to this line of code so far in nd4j-api-1.0.0beta7 in BaseDataBuffer class ((IntIndexer) indexer).put(i, element); Only happens in a servlet context. – Tony Anecito Nov 08 '20 at 00:10
  • Ok so far looks like this call in the IntRawIndexer class is returning a null when in a servlet environment. /** The instance for the raw memory interface. */ protected static final Raw RAW = Raw.getInstance(); – Tony Anecito Nov 08 '20 at 05:59

1 Answers1

0

Ok so far looks like this call in the IntRawIndexer class is returning a null when in a Wildfly environment. /** The instance for the raw memory interface. */ protected static final Raw RAW = Raw.getInstance(); And looking closer at that it relies on sun.misc.Unsafe and if when checking for that will return a null if there is an exception when loading that class Class.forName("sun.misc.Unsafe") or when checking for methods of that class after the class is loaded. More effort and the root cause is Wildfly not finding the Unsafe class called from that jar. It can find it from servlet apparently from a test I did.

Tony Anecito
  • 347
  • 2
  • 13
  • Yes, that's part of the issue. When we can't access sun.misc.Unsafe, it falls back on java.nio.Buffer. Why it's not doing that in this case is probably because multiple class loaders are getting used incorrectly. As I mentioned above, please make sure all the classes from JavaCPP get loaded with the same class loader. If, for example, `Loader` gets loaded by one class loader, but `Pointer` with another class loader, it's not going to work! – Samuel Audet Nov 09 '20 at 01:08
  • Well the issue for the Unsafe class is the Wildfly java modular system does not allow access to it but the servlet loader and putting the jars in eclipse do work. I tried putting all the jars in a path found by the jre but issues (Cassandra) with that also. Working on having the jars in the war but that is not quite working yet. All those would use the same loader and so far all have issues with the jars. But still working on it. Closest was with the Wildfly module but the listener for IIOP needs at least the servlet jar and probably uses another loader anyway. – Tony Anecito Nov 09 '20 at 02:01
  • 1
    Okay everything is working!! So many thanks to the Deeplearn4j team you all are awesome!! In the end I needed to add a dependency in the module for Wildfly to access the Unsafe class. So now everything is in one loader. Been almost 4 years since I last updated the jars and I wanted only what was needed for what I did. – Tony Anecito Nov 09 '20 at 07:29