GitHub repositoryfbelderink/flutter_pytorch_mobile

flutter_pytorch_mobile

A flutter plugin for pytorch model inference. Supports image models as well as custom models.

flutter_pytorch_mobile project cover
Stars
103
Forks
52
Last push (UTC)
Feb 20, 2023
Project status
Active

Original README

English project snapshot. Visit GitHub for the latest content.

pytorch_mobile

A flutter plugin for pytorch model inference, supported both for Android and iOS.

Usage

Installation

To use this plugin, add pytorch_mobile as a dependency in your pubspec.yaml file.

Create a assets folder with your pytorch model and labels if needed. Modify pubspec.yaml accoringly.

assets:
 - assets/models/model.pt
 - assets/labels.csv

Run flutter pub get

Import the library
import 'package:pytorch_mobile/pytorch_mobile.dart';
Load model

Either custom model:

Model customModel = await PyTorchMobile
        .loadModel('assets/models/custom_model.pt');

Or image model:

Model imageModel = await PyTorchMobile
        .loadModel('assets/models/resnet18.pt');
Get custom prediction
List prediction = await customModel
        .getPrediction([1, 2, 3, 4], [1, 2, 2], DType.float32);
Get prediction for an image
String prediction = await _imageModel
        .getImagePrediction(image, 224, 224, "assets/labels/labels.csv");
Image prediction for an image with custom mean and std
final mean = [0.5, 0.5, 0.5];
final std = [0.5, 0.5, 0.5];
String prediction = await _imageModel
        .getImagePrediction(image, 224, 224, "assets/labels/labels.csv", mean: mean, std: std);

Contact

fynnmaarten.business@gmail.com

Fynn Maarten Belderink GitHub avatar
GitHub author

Fynn Maarten Belderink ↗

Trying to inspire people!

RWTH Aachen UniversityGermany
LanguagesJavaDartObjective-C++Objective-CRubyPython

Categories

Dependencies used

Dependency list 4 items

  • flutter{"sdk":"flutter"}
  • path_provider^2.0.2
  • path^1.8.0
  • flutter_testDevelopment{"sdk":"flutter"}

How do I choose a repository?

Start with your use case, compare repository activity, and check the original project before adopting it.

  1. Search by repository name, owner or description, then narrow the results by topic.
  2. Compare stars, forks and recent pushes. Stars show community interest, not a guarantee of quality.
  3. Read the README, license and issues on GitHub before using a project.

Sources and maintenance

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗