android-demo-app
android-demo-app copied to clipboard
com.facebook.jni.CppException: PytorchStreamReader failed locating file bytecode.pkl: file not found ()
Using yolov5 model to convert torchscript and Android object detection to report errors:
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.pytorch.demo.objectdetection/org.pytorch.demo.objectdetection.MainActivity}: com.facebook.jni.CppException: PytorchStreamReader failed locating file bytecode.pkl: file not found () Exception raised from valid at ../caffe2/serialize/inline_container.cc:157 (most recent call first): (no backtrace available)
Have you resolved this problem ?
@qichuangguo : Were you able to find a solution to this problem ?.. Looks like it is working on windows , mac seems to be an issue. did you run it on mac ?
Hi, buddies) This information solved the problem for me. Hope this will be helpful for you as well. https://pytorch.org/tutorials/recipes/mobile_interpreter.html.
spoiler alert. You should use script._save_for_lite_interpreter() instead script.save()
I have the same issue on windows
Hello, i change the name of the file "yolov5s.torchscript.ptl" to "uu.ptl" and also in the file "pytorch/demo/objectdetection/MainActivity.java" and now, it's work (don't ask me why!!!)
Hello, i change the name of the file "yolov5s.torchscript.ptl" to "uu.ptl" and also in the file "pytorch/demo/objectdetection/MainActivity.java" and now, it's work (don't ask me why!!!)
removing _ from name worked for me. For, eg: best.torchscript_s.ptl to best.torchscripts.ptl
Hi, buddies) This information solved the problem for me. Hope this will be helpful for you as well. https://pytorch.org/tutorials/recipes/mobile_interpreter.html.
spoiler alert. You should use script._save_for_lite_interpreter() instead script.save() @gleb-papchihin, hello can you please elaborate furthermore, i have a custom .pt file that i want to convert and i cannot seem to do it, thank you in andvance!
Hi, buddies) This information solved the problem for me. Hope this will be helpful for you as well. https://pytorch.org/tutorials/recipes/mobile_interpreter.html.
spoiler alert. You should use script._save_for_lite_interpreter() instead script.save()
This works for me on pytorch 1.10.2 ! Seem The pytorch mobile is only compatible with _save_for_lite_interpreter() model.
- use the same version of torch(yolov5 & android)
- use statment _save_for_lite_interpreter() to save the model
@jithin8mathew Hello. Can you please send a link of export.py file you used to convert .pt model to .torchscripts.ptl Thanks a lot in advance!
Hi @HripsimeS, I have a couple of export.py scripts in my project directory right now and can't figure out which one I used for conversion (it is been a while since I haven't worked on it). For some reason, I had an issue when converting a model trained on Windows OS, but training the same model with Linux OS solved this issue, and I still don't know why it happened.
I trained my model (in Google Colab) with the following versions of packages:
Pytorch 1.9.0 cuda (GPU) at batch size 16 (torch==1.9.0, torchvision==0.10.0, ) Model: YOLOv5s (I downloaded the repo on August 2021, if you want to check the version of YOLOv5)
Here are some changes I made to export.py
def export_torchscript(model, im, file, optimize, prefix=colorstr('TorchScript:')):
# YOLOv5 TorchScript model export
try:
LOGGER.info(f'\n{prefix} starting export with torch {torch.__version__}...')
f = file.with_suffix('.torchscript.pt')
ts = torch.jit.trace(model, im, strict=False)
d = {"shape": im.shape, "stride": int(max(model.stride)), "names": model.names}
extra_files = {'config.txt': json.dumps(d)} # torch._C.ExtraFilesMap()
(optimize_for_mobile(ts) if optimize else ts).save(f, _extra_files=extra_files)
LOGGER.info(f'{prefix} export success, saved as {f} ({file_size(f):.1f} MB)')
except Exception as e:
LOGGER.info(f'{prefix} export failure: {e}')
Let me know if this helps. Good luck!!!
您好,我将文件“yolov5s.torchscript.ptl”的名称更改为“uu.ptl”,并在文件“pytorch/demo/objectdetection/MainActivity.java”中更改,现在,它是工作(不要问我为什么!!!)
It can't work for me!!!!!!
I have the same problem,and I try to use script._save_for_lite_interpreter() instead script.save().Now,it works successfully!