chaquo / chaquopy

Chaquopy: the Python SDK for Android
https://chaquo.com/chaquopy/
MIT License
753 stars 129 forks source link

UnicodeDecodeError if .pth file presents #307

Closed neur1n closed 4 years ago

neur1n commented 4 years ago

So I'm trying to deploy a pytorch demo on an Android device, but whenever there is a pth file (you can treat it as a neural network model) in src/main/python folder, an UnicodeDecodeError exception will be raised even though the Python source code is not loading the file. This file is in binary format, which is not the same as test.pth in this repo.

The normal way to load the file (while running in PC) is

model = torch.load('foo.pth')

But if I load it with

model = torch.load(open('foo.pth', encoding='utf-8'))

The same UnicodeDecodeError raised. So I assume the exception occurs during Chaquopy sourcing the files?

mhsmith commented 4 years ago

As you've found, the .pth extension is also used for path configuration files. So you'll have to either rename it to have a different extension, or preferably put it in a package subdirectory rather than in the source code root.

For actually finding the file at runtime, see #144.

neur1n commented 4 years ago

Oh I've never know it is a path configuration file. I thought that test.pth was a dummy file.

Thank you very much.