guchengxi1994 / pytorch-mobile-trial

pytorch mobile trial with a self-trained gan(U-GAT-IT)
3 stars 0 forks source link

Hi, did you get this working? I'd like to make something similar. #2

Open spinoza1791 opened 2 years ago

guchengxi1994 commented 2 years ago

@spinoza1791 I have released a demo app on Huawei app market, https://appgallery.huawei.com/app/C104482337 . Full codes of this app can be find in this repo. You can follow my codes to build your own apps. However, these codes are not supported on iOS yet. You should use Platform package to distinguish different platforms , install pytorch-mobile dependency and write iOS pytorch-mobile codes for iOS. Or just use a web server to convert photos.

enjoy coding.

spinoza1791 commented 2 years ago

Thank you! Great work. I got your example code working. Your pytorch model works well, but my pytorch model does not yet work with your pytorch cmds. What are the properties of your test.pt model? Perhaps I can convert my model to be a similar type?

guchengxi1994 commented 2 years ago

This is a sample code for converting pytorch models to pytorch-mobile models.

import torch
import torchvision  # unnecessary if using your own model
from torch.utils.mobile_optimizer import optimize_for_mobile

model = torchvision.models.mobilenet_v3_small(pretrained=True) # you can replace this with your own model
model.eval()
example = torch.rand(1, 3, 224, 224)  # change input size
traced_script_module = torch.jit.trace(model, example)
optimized_traced_model = optimize_for_mobile(traced_script_module)
optimized_traced_model._save_for_lite_interpreter("app/src/main/assets/model.ptl")

and , here is a tutorial video from pytorch team https://www.youtube.com/watch?v=5Lxuu16_28o which introduces how to convert models

guchengxi1994 commented 2 years ago

also , you should pay attention to the pytorch version