Skip to content

Commit 2d9ede8

Browse files
committed
custom mean and std fix for ios and pytorch version bugfixes
1 parent cc0ae9b commit 2d9ede8

File tree

9 files changed

+47
-45
lines changed

9 files changed

+47
-45
lines changed

example/ios/Podfile

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Uncomment this line to define a global platform for your project
22
platform :ios, '12.0'
33

4+
use_frameworks!
5+
46
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
57
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
68

example/ios/Podfile.lock

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ PODS:
22
- Flutter (1.0.0)
33
- image_picker (0.0.1):
44
- Flutter
5-
- LibTorch (1.6.1):
6-
- LibTorch/Core (= 1.6.1)
7-
- LibTorch/Core (1.6.1):
5+
- LibTorch (1.8.0):
6+
- LibTorch/Core (= 1.8.0)
7+
- LibTorch/Core (1.8.0):
88
- LibTorch/Torch
9-
- LibTorch/Torch (1.6.1)
9+
- LibTorch/Torch (1.8.0)
1010
- path_provider (0.0.1):
1111
- Flutter
1212
- pytorch_mobile (0.0.1):
1313
- Flutter
14-
- LibTorch (~> 1.6.0)
14+
- LibTorch (~> 1.8.0)
1515

1616
DEPENDENCIES:
1717
- Flutter (from `Flutter`)
@@ -34,12 +34,12 @@ EXTERNAL SOURCES:
3434
:path: ".symlinks/plugins/pytorch_mobile/ios"
3535

3636
SPEC CHECKSUMS:
37-
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec
38-
image_picker: e3eacd46b94694dde7cf2705955cece853aa1a8f
39-
LibTorch: 32a83630ab5b4505f205c7e332975a2d3d6e0c55
40-
path_provider: fb74bd0465e96b594bb3b5088ee4a4e7bb1f2a9d
41-
pytorch_mobile: 22fd3005ff24695fbea6d0aa79f0a2a8edfb5152
37+
Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c
38+
image_picker: 50e7c7ff960e5f58faa4d1f4af84a771c671bc4a
39+
LibTorch: d7724112589515bedd5eadf14a9db5b1d62d8a34
40+
path_provider: abfe2b5c733d04e238b0d8691db0cfd63a27a93c
41+
pytorch_mobile: cdb1566b9883c59662d443e904db6674e829dd84
4242

43-
PODFILE CHECKSUM: cf0c950f7e9a456b4e325f5b8fc0f98906a3705a
43+
PODFILE CHECKSUM: d9646c0250b6c86682c69a86e40f54c636c64ae4
4444

45-
COCOAPODS: 1.10.0
45+
COCOAPODS: 1.10.1

example/ios/Runner.xcodeproj/project.pbxproj

+22-22
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
134ED5FD059C2EC6F55089BA /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1CBE08087A7794AD68A68F34 /* Pods_Runner.framework */; };
1011
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
1112
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
12-
8313DB2B386C05D6A736FA9A /* libPods-Runner.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 830CB15F4BC937B0A561B23D /* libPods-Runner.a */; };
1313
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
1414
97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
1515
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
@@ -34,11 +34,11 @@
3434
0538B1F8A0C843E8B18BD906 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
3535
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
3636
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
37+
1CBE08087A7794AD68A68F34 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3738
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
3839
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
3940
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
4041
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
41-
830CB15F4BC937B0A561B23D /* libPods-Runner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Runner.a"; sourceTree = BUILT_PRODUCTS_DIR; };
4242
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
4343
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
4444
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -56,7 +56,7 @@
5656
isa = PBXFrameworksBuildPhase;
5757
buildActionMask = 2147483647;
5858
files = (
59-
8313DB2B386C05D6A736FA9A /* libPods-Runner.a in Frameworks */,
59+
134ED5FD059C2EC6F55089BA /* Pods_Runner.framework in Frameworks */,
6060
);
6161
runOnlyForDeploymentPostprocessing = 0;
6262
};
@@ -77,7 +77,7 @@
7777
559F459594CD5591545EDA80 /* Frameworks */ = {
7878
isa = PBXGroup;
7979
children = (
80-
830CB15F4BC937B0A561B23D /* libPods-Runner.a */,
80+
1CBE08087A7794AD68A68F34 /* Pods_Runner.framework */,
8181
);
8282
name = Frameworks;
8383
sourceTree = "<group>";
@@ -150,7 +150,7 @@
150150
97C146EC1CF9000F007C117D /* Resources */,
151151
9705A1C41CF9048500538489 /* Embed Frameworks */,
152152
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
153-
1662704A5362991A2D9BF051 /* [CP] Embed Pods Frameworks */,
153+
D8FC68926E06332DF0121637 /* [CP] Embed Pods Frameworks */,
154154
);
155155
buildRules = (
156156
);
@@ -208,23 +208,6 @@
208208
/* End PBXResourcesBuildPhase section */
209209

210210
/* Begin PBXShellScriptBuildPhase section */
211-
1662704A5362991A2D9BF051 /* [CP] Embed Pods Frameworks */ = {
212-
isa = PBXShellScriptBuildPhase;
213-
buildActionMask = 2147483647;
214-
files = (
215-
);
216-
inputFileListPaths = (
217-
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
218-
);
219-
name = "[CP] Embed Pods Frameworks";
220-
outputFileListPaths = (
221-
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
222-
);
223-
runOnlyForDeploymentPostprocessing = 0;
224-
shellPath = /bin/sh;
225-
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
226-
showEnvVarsInLog = 0;
227-
};
228211
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
229212
isa = PBXShellScriptBuildPhase;
230213
buildActionMask = 2147483647;
@@ -275,6 +258,23 @@
275258
shellPath = /bin/sh;
276259
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
277260
};
261+
D8FC68926E06332DF0121637 /* [CP] Embed Pods Frameworks */ = {
262+
isa = PBXShellScriptBuildPhase;
263+
buildActionMask = 2147483647;
264+
files = (
265+
);
266+
inputFileListPaths = (
267+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
268+
);
269+
name = "[CP] Embed Pods Frameworks";
270+
outputFileListPaths = (
271+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
272+
);
273+
runOnlyForDeploymentPostprocessing = 0;
274+
shellPath = /bin/sh;
275+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
276+
showEnvVarsInLog = 0;
277+
};
278278
/* End PBXShellScriptBuildPhase section */
279279

280280
/* Begin PBXSourcesBuildPhase section */

example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ios/Classes/Helpers/UIImageExtension.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ NS_ASSUME_NONNULL_BEGIN
44

55
@interface UIImageExtension : NSObject
66
+ (nullable UIImage*)resize:(UIImage*)image toWidth:(int)width toHeight:(int)height;
7-
+ (nullable float*)normalize:(UIImage*)image;
7+
+ (nullable float*)normalize:(UIImage*)image withMean:(NSArray<NSNumber*>*)mean withSTD:(NSArray<NSNumber*>*)std;
88
@end
99

1010
NS_ASSUME_NONNULL_END

ios/Classes/Helpers/UIImageExtension.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ + (UIImage*)resize:(UIImage*)image toWidth:(int) width toHeight:(int)height {
1212
return newImage;
1313
}
1414

15-
+ (nullable float*)normalize:(UIImage*)image mean:(NSArray<NSNumber*>*) std:(NSArray<NSNumber*>*) {
15+
+ (nullable float*)normalize:(UIImage*)image withMean:(NSArray<NSNumber*>*)mean withSTD:(NSArray<NSNumber*>*)std {
1616
CGImageRef cgImage = [image CGImage];
1717
NSUInteger w = CGImageGetWidth(cgImage);
1818
NSUInteger h = CGImageGetHeight(cgImage);
@@ -37,9 +37,9 @@ + (nullable float*)normalize:(UIImage*)image mean:(NSArray<NSNumber*>*) std:(NSA
3737

3838
float* normalizedBuffer = malloc(3*h*w * sizeof(float));
3939
for(int i = 0; i < (w*h); i++) {
40-
normalizedBuffer[i] = (rawBytes[i * 4 + 0] / 255.0 - mean[0]) / std[0];
41-
normalizedBuffer[w * h + i] = (rawBytes[i * 4 + 1] / 255.0 - mean[1]) / std[1];
42-
normalizedBuffer[w * h * 2 + i] = (rawBytes[i * 4 + 2] / 255.0 - mean[2]) / std[2];
40+
normalizedBuffer[i] = (rawBytes[i * 4 + 0] / 255.0 - mean[0].floatValue) / std[0].floatValue;
41+
normalizedBuffer[w * h + i] = (rawBytes[i * 4 + 1] / 255.0 - mean[1].floatValue) / std[1].floatValue;
42+
normalizedBuffer[w * h * 2 + i] = (rawBytes[i * 4 + 2] / 255.0 - mean[2].floatValue) / std[2].floatValue;
4343
}
4444

4545
return normalizedBuffer;

ios/Classes/PyTorchMobilePlugin.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#import <Flutter/Flutter.h>
22

3-
@interface PytorchMobilePlugin : NSObject<FlutterPlugin>
3+
@interface PyTorchMobilePlugin : NSObject<FlutterPlugin>
44
@end

ios/Classes/PytorchMobilePlugin.mm renamed to ios/Classes/PyTorchMobilePlugin.mm

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
#import "UIImageExtension.h"
44
#import <LibTorch/LibTorch.h>
55

6-
@implementation PytorchMobilePlugin
6+
@implementation PyTorchMobilePlugin
77

88
NSMutableArray *modules = [[NSMutableArray alloc] init];
99

1010
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
1111
FlutterMethodChannel* channel = [FlutterMethodChannel
1212
methodChannelWithName:@"pytorch_mobile"
1313
binaryMessenger:[registrar messenger]];
14-
PytorchMobilePlugin* instance = [[PytorchMobilePlugin alloc] init];
14+
PyTorchMobilePlugin* instance = [[PyTorchMobilePlugin alloc] init];
1515
[registrar addMethodCallDelegate:instance channel:channel];
1616
}
1717

@@ -90,7 +90,7 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
9090
UIImage *image = [UIImage imageWithData: imageData.data];
9191
image = [UIImageExtension resize:image toWidth:width toHeight:height];
9292

93-
input = [UIImageExtension normalize:image mean:mean std:std];
93+
input = [UIImageExtension normalize:image withMean:mean withSTD:std];
9494
} catch (const std::exception& e) {
9595
NSLog(@"PyTorchMobile: error reading image!\n%s", e.what());
9696
}

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ flutter:
2424
package: io.fynn.pytorch_mobile
2525
pluginClass: PyTorchMobilePlugin
2626
ios:
27-
pluginClass: PytorchMobilePlugin
27+
pluginClass: PyTorchMobilePlugin

0 commit comments

Comments
 (0)