Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on android in torch.load() #96

Open
rhythm9229 opened this issue Apr 19, 2017 · 3 comments
Open

Crash on android in torch.load() #96

rhythm9229 opened this issue Apr 19, 2017 · 3 comments

Comments

@rhythm9229
Copy link

Hi,
I am getting the following crash on loading a torch model in assets folder.
Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 15381 (AsyncTask #1)

I loaded the model like this-
torch.load("model.t7", "apkbinary64")

I also converted the model.t7 to ascii format and tried loading it like this-
torch.load("modelascii.t7", "apkascii")
But i faced the same issue.

Please help resolve this issue.

@paramsen
Copy link
Contributor

Write the file to disk and try to load it like torch.load("/absolute/path/to/model.t7", "binary64"), that works for me.

I've had no luck using the load-from-assets functions, so I've reverted to write the .t7 file to disk and load it dynamically from a path when initializing torch. My first step was to manually put the .t7 file on the device disk and "hard code" the path in my .lua script.

@shijie-nv
Copy link

The crash is caused by the "torch-android/src/THApkFile.c"

The "THFileVTable" data structure has slightly changed in the new version torch7.
add two items, "THDiskFile_readHalf", "THDiskFile_writeHalf"
Please see "torch-android/distro/pkg/torch/lib/TH/THDiskFile.c"

Here we do not need to implement the "THApkFile_readHalf" "THApkFile_writeHalf", just use NULL to fill the table.
Then rebuild the torch-android, everything works well.
Thank @iGit2017 for finding the solution.

--- a/src/THApkFile.c
+++ b/src/THApkFile.c
@@ -625,6 +625,7 @@ THFile *THApkFile_new(const char *name, const char *mode, int isQuiet)
THApkFile_readLong,
THApkFile_readFloat,
THApkFile_readDouble,
+ NULL,
THApkFile_readString,

@@ -634,6 +635,7 @@ THFile *THApkFile_new(const char *name, const char *mode, int isQuiet)
THApkFile_writeLong,
THApkFile_writeFloat,
THApkFile_writeDouble,
+ NULL,
THApkFile_writeString,

@shijie-nv
Copy link

added the missing fclose(). maybe a resource leaks

diff --git a/src/torchandroid.cpp b/src/torchandroid.cpp
index 6ac4589..1cfedfb 100644
--- a/src/torchandroid.cpp
+++ b/src/torchandroid.cpp
@@ -56,6 +56,7 @@ long android_asset_get_size(const char *name) {
return -1;
fseek(fl, 0, SEEK_END);
long len = ftell(fl);
+ fclose(fl);
return len;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants