Skip to content

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

License

Notifications You must be signed in to change notification settings

cyrillkuettel/flutter_pytorch_mobile

This branch is 4 commits ahead of fbelderink/flutter_pytorch_mobile:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

64d7ef5 · Feb 18, 2023

History

48 Commits
Apr 11, 2020
Apr 12, 2020
Apr 11, 2020
Feb 18, 2023
Feb 18, 2023
May 29, 2021
May 29, 2021
Apr 12, 2020
Apr 11, 2020
Apr 11, 2020
Jul 12, 2022
Apr 12, 2020
Jul 12, 2022
Apr 12, 2020
Feb 18, 2023
Jul 12, 2022
Apr 12, 2020

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 30.7%
  • Dart 27.6%
  • Objective-C++ 21.8%
  • Objective-C 10.7%
  • Ruby 7.5%
  • Python 1.7%