flutter_pytorch_mobile
flutter_pytorch_mobile copied to clipboard
How to update torch for this plugin ?
@fynnmaarten I am trying to load a model that i compiled using PyTorch 2.0.0 and it is giving me an error. How to update the torch version for this plugin ?
Updating Pytorch Version of the plugin
I did this a couple of months ago, so here you go:
(Disclaimer: this can be quite a hustle, it's probably easier to compile with pytorch 1.10 if that's an option that works for you.)
- Fork this repository to have a local copy.
- Open your project's
pubspec.ymland update the version to the forked one.
flutter_pytorch_mobile:
git: [email protected]:name/path-to-your-forked-repo.git
iOS
Open flutter_pytorch_mobile/ios/flutter_pytorch_mobile.podspec in your forked plugin.
Change the version you want to change, on iOS it's called LibTorch
@ ios/flutter_pytorch_mobile.podspec:27 @ A new Flutter plugin project.
s.static_framework = true
s.public_header_files = 'Classes/**/*.h'
- s.dependency 'LibTorch', '~>1.10.0'
+ s.dependency 'LibTorch', '~>1.13.0'
# Flutter.framework does not contain a i386 slice.
s.pod_target_xcconfig = { 'DEFINES_MODULE' =>
Here we've changed the dependency s.dependency 'LibTorch to 1.13 as an example.
❗ You'll to check which version you need that works with PyTorch 2.0.0
After that, run
pod update LibTorch
for the changes to take effect (If you don't have pod, you need to install Cocabods)
Maybe you also need:
flutter build ios
Android
On android, pytorch mobile is specified as a gradle dependency in your forked plugin.
Open flutter_pytorch_mobile/android/build.gradle
dependencies {
implementation 'org.pytorch:pytorch_android:1.13.1'
implementation 'org.pytorch:pytorch_android_torchvision:1.13.1
}
After that, sync gradle and make sure everything works in the Android build. It usually helps opening Android Studio and resolving all issues. Finally, don't forget to commit and push your changes.