gWOLF3 / rscnn

A cnn framework on Android platform, implemented with RenderScript and java, support MobileNet-SSD and faster-rcnn. No JNI/C++ or thirdparty dependencies.
MIT License
0 stars 1 forks source link

errors bootstrapping with core_ml.prototext #9

Open gWOLF3 opened 4 years ago

gWOLF3 commented 4 years ago

what happened?

received error while trying to use the "catNotDog" classifier model provided.

error:

 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rscnn.example/com.rscnn.example.activity.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.util.LinkedHashMap.get(java.lang.Object)' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3047)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3182)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1916)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6898)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.util.LinkedHashMap.get(java.lang.Object)' on a null object reference
        at com.rscnn.network.LayerParser.parseGraphs(LayerParser.java:515)
        at com.rscnn.network.LayerParser.parse(LayerParser.java:689)
        at com.rscnn.network.LayerParser.parseFromRawDataOnAsset(LayerParser.java:710)
        at com.rscnn.network.ConvNet.loadGraphFromRawData(ConvNet.java:85)
        at com.rscnn.network.ConvNet.<init>(ConvNet.java:78)
        at com.rscnn.model.MobileNetSSD.<init>(MobileNetSSD.java:33)
        at com.rscnn.example.activity.MainActivity.onCreate(MainActivity.java:45)
        at android.app.Activity.performCreate(Activity.java:7149)
        at android.app.Activity.performCreate(Activity.java:7140)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1288)

take special note here:

 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.util.LinkedHashMap.get(java.lang.Object)' on a null object reference
        at com.rscnn.network.LayerParser.parseGraphs(LayerParser.java:515)
        at com.rscnn.network.LayerParser.parse(LayerParser.java:689)

why:

the core_ml generated prototext file is slightly different semantically than the expected.

in core_ml prototext:

input: "data"
input_dim: 1
input_dim: 3
input_dim: 224
input_dim: 224

in expected prototext:

input_shape {
  dim: 1
  dim: 3
  dim: 300
  dim: 300
}

I also attached the files for further inspection. This breaks at the layer parser, but there may be further incompatibility errors beyond this.

gWOLF3 commented 4 years ago

attempt at "hacking it together".

in order to get passed this issue, i manually started playing with resolving the minor differences in format.

after a quick file manipulation on the prototext, I can get to a different error, which appears to be caused by the batch norm layer. we see a null length array causing an error. looking into the code, im not sure where 'mean' is meant to be defined before...

@ batchnorm.java:


        float scaleFactor = scale == 0 ? 0 : 1.f / scale;
        for (int i = 0; i < mean.length; i++) {
            mean[i] *= scaleFactor;
            variance[i] *= scaleFactor;
        }

(e):

  Caused by: java.lang.NullPointerException: Attempt to get length of null array
        at com.rscnn.layers.BatchNorm.setup(BatchNorm.java:56)
        at com.rscnn.network.LayerGraph.init(LayerGraph.java:298)