pytorch / android-demo-app

PyTorch android examples of usage in applications
1.47k stars 606 forks source link

NoneType return loadModuleFromAsset(getAssets(), "d2go.pt"); #164

Open pankajkumar9797 opened 3 years ago

pankajkumar9797 commented 3 years ago
 Caused by: com.facebook.jni.CppException: 
Unknown type name 'NoneType':
Serialized   File "code/__torch__/torch/nn/intrinsic/quantized/modules/conv_relu.py", line 24
    return _0
  def __setstate__(self: __torch__.torch.nn.intrinsic.quantized.modules.conv_relu.ConvReLU2d,
    state: Tuple[int, int, Tuple[int, int], Tuple[int, int], Tuple[int, int], Tuple[int, int], bool, Tuple[int, int], int, str, Tensor, Optional[Tensor], float, int, bool]) -> NoneType:
                                                                                                                                                                                ~~~~~~~~ <--- HERE
    self.in_channels = (state)[0]
    self.out_channels = (state)[1]
Parth38 commented 3 years ago

I am facing the same issue

Parth38 commented 3 years ago

cc @jeffxtang

jeffxtang commented 3 years ago

Did you create d2go.pt using the script in the repo, or use the model file directly in the repo?

Parth38 commented 3 years ago

I am creating d2go.pt in Google colab

Parth38 commented 3 years ago

I am training custom model and for conversion I am referring create_d2go.py

jeffxtang commented 3 years ago

Did you use PyTorch 1.9 and torchvision 0.10.0 to create your model? Then the build.gradle needs to be updated with 1.9.0 like this and use the lite version api like this.

Or you can install PyTorch 1.8 and torchvision 0.9 to work with the current Android code.

MayarLotfy commented 3 years ago

I am facing the same issue.

I followed @jeffxtang advice, but I get this error on android:

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 ()

from the line :

mModule = LiteModuleLoader.load(MainActivity.assetFilePath(getApplicationContext(), "d2go.pt"));

I guess d2go is only supported for Pytorch 1.8 : (If I am not mistaken) [https://pytorch.org/mobile/android/] pytorch d2go version

Now I am trying to run the notebook again from colab with Pytorch installed 1.8. But that doesn't seem to work :\ Import errors from torch text.. ImportError: /usr/local/lib/python3.7/dist-packages/torchtext/_torchtext.so: undefined symbol: _ZN2at6detail10noopDeleteEPv

Any leads ?

The goal is to try the balloon toy set on D2go so I could later twist it to my Custom dataset.

jeffxtang commented 3 years ago

D2Go for PyTorch 1.9 works, but an updated script is required to create the model - please checkout the PyTorch 1.9 updated D2Go iOS demo app, steps 1-3 of here for now. Will update this D2Go Android demo app to 1.9 soon.

Parth38 commented 3 years ago

@MayarLotfy I am trying this in colab and it has started to train !pip install --pre torch==1.8.0 torchvision==0.9.0 torchtext==0.9.1 -f https://download.pytorch.org/whl/nightly/cu101/torch_nightly.html -U Will update whether the generated .pt file is working

Parth38 commented 3 years ago

The app is crashing when I press detect. I think we have to wait for the updated app

Parth38 commented 3 years ago

@jeffxtang I am getting this error Process: org.pytorch.demo.objectdetection, PID: 9752 com.facebook.jni.CppException: Method 'forward' is not defined. Exception raised from get_method at ../../../../src/main/cpp/libtorch_include/x86/torch/csrc/jit/api/object.h:96 (most recent call first): (no backtrace available) at org.pytorch.NativePeer.forward(Native Method) at org.pytorch.Module.forward(Module.java:49) at org.pytorch.demo.objectdetection.MainActivity.run(MainActivity.java:241) at java.lang.Thread.run(Thread.java:923) I/Process: Sending signal. PID: 9752 SIG: 9