Skip to content

Commit

Permalink
4.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelaziz-mahdy committed Apr 2, 2024
1 parent 8c7bb69 commit 8d89a58
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

## 4.2.5
* added ability to load model from path and assets, instead of only assets

## 4.2.4
* fixed ios possible memory leak (by [cyrillkuettel](https://github.com/cyrillkuettel))
## 4.2.3
Expand Down
2 changes: 2 additions & 0 deletions lib/enums/model_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ enum CameraPreProcessingMethod {
/// Only tested on Android.
byteList,
}

enum ModelLocation { asset, path }
25 changes: 16 additions & 9 deletions lib/pytorch_lite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export 'enums/dtype.dart';
export 'package:pytorch_lite/pigeon.dart';
export 'extensions/to_map_json.dart';
export 'enums/model_type.dart';

const List<double> torchVisionNormMeanRGB = [0.485, 0.456, 0.406];
const List<double> torchVisionNormSTDRGB = [0.229, 0.224, 0.225];
const List<double> noMeanRGB = [0, 0, 0];
const List<double> noSTDRGB = [1, 1, 1];


class PytorchLite {
/*
///Sets pytorch model path and returns Model
Expand All @@ -35,10 +35,14 @@ class PytorchLite {
///Sets pytorch model path and returns Model
static Future<ClassificationModel> loadClassificationModel(
String path, int imageWidth, int imageHeight, int numberOfClasses,
{String? labelPath, bool ensureMatchingNumberOfClasses = true}) async {
String absPathModelPath = await _getAbsolutePath(path);
int index = await ModelApi()
.loadModel(absPathModelPath, null, imageWidth, imageHeight, null);
{String? labelPath,
bool ensureMatchingNumberOfClasses = true,
ModelLocation modelLocation = ModelLocation.asset}) async {
if (modelLocation == ModelLocation.asset) {
path = await _getAbsolutePath(path);
}
int index =
await ModelApi().loadModel(path, null, imageWidth, imageHeight, null);
List<String> labels = [];
if (labelPath != null) {
if (labelPath.endsWith(".txt")) {
Expand All @@ -62,11 +66,14 @@ class PytorchLite {
String path, int numberOfClasses, int imageWidth, int imageHeight,
{String? labelPath,
ObjectDetectionModelType objectDetectionModelType =
ObjectDetectionModelType.yolov5}) async {
String absPathModelPath = await _getAbsolutePath(path);
ObjectDetectionModelType.yolov5,
ModelLocation modelLocation = ModelLocation.asset}) async {
if (modelLocation == ModelLocation.asset) {
path = await _getAbsolutePath(path);
}

int index = await ModelApi().loadModel(absPathModelPath, numberOfClasses,
imageWidth, imageHeight, objectDetectionModelType.index);
int index = await ModelApi().loadModel(path, numberOfClasses, imageWidth,
imageHeight, objectDetectionModelType.index);
List<String> labels = [];
if (labelPath != null) {
if (labelPath.endsWith(".txt")) {
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: pytorch_lite
description: Flutter package to help run pytorch lite models classification and yolov5 and yolov8
version: 4.2.4
homepage: https://github.com/zezo357/pytorch_lite
version: 4.2.5
homepage: https://github.com/abdelaziz-mahdy/pytorch_lite

environment:
sdk: ">=2.17.0 <4.0.0"
Expand Down

0 comments on commit 8d89a58

Please sign in to comment.