sh1r0 / caffe-android-demo

An android caffe demo app exploiting caffe pre-trained ImageNet model for image classification
https://github.com/sh1r0/caffe-android-lib
MIT License
255 stars 164 forks source link

File not found #41

Closed billygl closed 7 years ago

billygl commented 8 years ago

I used

        File file = new File(modelProto);
        if(file.exists())Log.e("DEVX", "ok.");
        else Log.e("DEVX", "NOT");

And I watched ok in Android Log Monitor. It means Android can find the file. It exists. But I got

F1107 18:01:28.624402 16834 io.cpp:36] Check failed: fd != -1 (-1 vs. -1) File not found: /storage/emulated/0/Download/caffe_mobile/bvlc_reference_caffenet/deploy.prototxt

when the execution arrived to caffeMobile.loadModel(modelProto, modelBinary);

It means that Android find the file but io.cpp can't find the file.

I doubled checked the path and I added <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> And I updated the code using the external storage SD card

pull /storage/278E-8716/caffe_mobile/bvlc_reference_caffenet/deploy.prototxt

but I can't solve this issue.

I have

android { compileSdkVersion 23 buildToolsVersion "22.0.1" defaultConfig { applicationId "com.sh1r0.caffe_android_demo" minSdkVersion 15 targetSdkVersion 23 versionName "1.0" }

And I don't know what is the problem. Please, help

sh1r0 commented 8 years ago

@billygl First, /storage/emulated/0/Download/caffe_mobile/bvlc_reference_caffenet/deploy.prototxt does not match /storage/278E-8716/caffe_mobile/bvlc_reference_caffenet/deploy.prototxt. And AFAIW, /emulated/0 is usually the primary external storage rather than the secondary one (i.e., external sd card) [1]. Please check the absolute path of your files.

[1] http://stackoverflow.com/a/29404440

billygl commented 8 years ago

Yes, I checked both locations. For that reason,

  1. First, I tried with one path It didn't work so
  2. I tried the other path. I thought it was caused by permissions.

Sorry for the confusion. I updated the post

sh1r0 commented 8 years ago

@billygl Is your phone on android 6 (marshmallow)?

billygl commented 7 years ago

Yes Android 6.0.1. Galaxy S7 Edge.

Uchanka commented 7 years ago

Maybe you should try and modify its Java source code? The file paths are designated in its source code, both .prototxt and weight file. Push these files to somewhere you have access to. Try enabling developer mode if you have to. Also be advised be careful with that S7 May cause massive explosion

billygl commented 7 years ago

Yes. I pushed these files to 2 locations and I changed the source code for theses locations in different tests but I highlight that

    File file = new File(modelProto);
    if(file.exists())Log.e("test", "ok.");

It works, but caffeMobile.loadModel(modelProto, modelBinary); doesn't work

sh1r0 commented 7 years ago

@billygl I found the problem, it's about runtime permission control introduced in android 6. Here's the workaround: manually grant the app with storage permission. screenshot_1480756864

billygl commented 7 years ago

Excellent! Thanks