Updated formatted
This commit is contained in:
parent
da8b60700b
commit
8682a3ffd9
|
@ -20,7 +20,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
@interface MPPBaseOptions (Helpers)
|
@interface MPPBaseOptions (Helpers)
|
||||||
|
|
||||||
- (void)copyToProto:(mediapipe::tasks::core::proto::BaseOptions *)baseOptionsProto;
|
- (void)copyToProto:(mediapipe::tasks::core::proto::BaseOptions *)baseOptionsProto;
|
||||||
- (void)copyToProto:(mediapipe::tasks::core::proto::BaseOptions *)baseOptionsProto withUseStreamMode:(BOOL)useStreamMode;
|
- (void)copyToProto:(mediapipe::tasks::core::proto::BaseOptions *)baseOptionsProto
|
||||||
|
withUseStreamMode:(BOOL)useStreamMode;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,8 @@ static NSString *const kQuantizedModelName = @"mobilenet_v1_0.25_224_quant";
|
||||||
static NSDictionary *const kBurgerImage = @{@"name" : @"burger", @"type" : @"jpg"};
|
static NSDictionary *const kBurgerImage = @{@"name" : @"burger", @"type" : @"jpg"};
|
||||||
static NSDictionary *const kBurgerRotatedImage = @{@"name" : @"burger_rotated", @"type" : @"jpg"};
|
static NSDictionary *const kBurgerRotatedImage = @{@"name" : @"burger_rotated", @"type" : @"jpg"};
|
||||||
static NSDictionary *const kMultiObjectsImage = @{@"name" : @"multi_objects", @"type" : @"jpg"};
|
static NSDictionary *const kMultiObjectsImage = @{@"name" : @"multi_objects", @"type" : @"jpg"};
|
||||||
static NSDictionary *const kMultiObjectsRotatedImage = @{@"name" : @"multi_objects_rotated", @"type" : @"jpg"};
|
static NSDictionary *const kMultiObjectsRotatedImage =
|
||||||
|
@{@"name" : @"multi_objects_rotated", @"type" : @"jpg"};
|
||||||
static const int kMobileNetCategoriesCount = 1001;
|
static const int kMobileNetCategoriesCount = 1001;
|
||||||
static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
||||||
|
|
||||||
|
@ -112,7 +113,7 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
||||||
|
|
||||||
#pragma mark Assert Classify Results
|
#pragma mark Assert Classify Results
|
||||||
|
|
||||||
-(MPPImage *)imageWithFileInfo:(NSDictionary *)fileInfo {
|
- (MPPImage *)imageWithFileInfo:(NSDictionary *)fileInfo {
|
||||||
MPPImage *image = [MPPImage imageFromBundleWithClass:[MPPImageClassifierTests class]
|
MPPImage *image = [MPPImage imageFromBundleWithClass:[MPPImageClassifierTests class]
|
||||||
fileName:fileInfo[@"name"]
|
fileName:fileInfo[@"name"]
|
||||||
ofType:fileInfo[@"type"]];
|
ofType:fileInfo[@"type"]];
|
||||||
|
@ -121,7 +122,8 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(MPPImage *)imageWithFileInfo:(NSDictionary *)fileInfo orientation:(UIImageOrientation)orientation {
|
- (MPPImage *)imageWithFileInfo:(NSDictionary *)fileInfo
|
||||||
|
orientation:(UIImageOrientation)orientation {
|
||||||
MPPImage *image = [MPPImage imageFromBundleWithClass:[MPPImageClassifierTests class]
|
MPPImage *image = [MPPImage imageFromBundleWithClass:[MPPImageClassifierTests class]
|
||||||
fileName:fileInfo[@"name"]
|
fileName:fileInfo[@"name"]
|
||||||
ofType:fileInfo[@"type"]
|
ofType:fileInfo[@"type"]
|
||||||
|
@ -242,10 +244,12 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
||||||
- (void)testClassifyWithModelPathAndFloatModelSucceeds {
|
- (void)testClassifyWithModelPathAndFloatModelSucceeds {
|
||||||
MPPImageClassifier *imageClassifier = [self imageClassifierFromModelFileWithName:kFloatModelName];
|
MPPImageClassifier *imageClassifier = [self imageClassifierFromModelFileWithName:kFloatModelName];
|
||||||
|
|
||||||
[self assertResultsOfClassifyImageWithFileInfo:kBurgerImage
|
[self
|
||||||
|
assertResultsOfClassifyImageWithFileInfo:kBurgerImage
|
||||||
usingImageClassifier:imageClassifier
|
usingImageClassifier:imageClassifier
|
||||||
expectedCategoriesCount:kMobileNetCategoriesCount
|
expectedCategoriesCount:kMobileNetCategoriesCount
|
||||||
equalsCategories:[MPPImageClassifierTests
|
equalsCategories:
|
||||||
|
[MPPImageClassifierTests
|
||||||
expectedResultCategoriesForClassifyBurgerImageWithFloatModel]];
|
expectedResultCategoriesForClassifyBurgerImageWithFloatModel]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,10 +261,12 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
||||||
|
|
||||||
MPPImageClassifier *imageClassifier = [self imageClassifierWithOptionsSucceeds:options];
|
MPPImageClassifier *imageClassifier = [self imageClassifierWithOptionsSucceeds:options];
|
||||||
|
|
||||||
[self assertResultsOfClassifyImageWithFileInfo:kBurgerImage
|
[self
|
||||||
|
assertResultsOfClassifyImageWithFileInfo:kBurgerImage
|
||||||
usingImageClassifier:imageClassifier
|
usingImageClassifier:imageClassifier
|
||||||
expectedCategoriesCount:maxResults
|
expectedCategoriesCount:maxResults
|
||||||
equalsCategories:[MPPImageClassifierTests
|
equalsCategories:
|
||||||
|
[MPPImageClassifierTests
|
||||||
expectedResultCategoriesForClassifyBurgerImageWithFloatModel]];
|
expectedResultCategoriesForClassifyBurgerImageWithFloatModel]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +418,8 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
MPPImage *image = [self imageWithFileInfo:kBurgerRotatedImage orientation:UIImageOrientationRight];
|
MPPImage *image = [self imageWithFileInfo:kBurgerRotatedImage
|
||||||
|
orientation:UIImageOrientationRight];
|
||||||
|
|
||||||
[self assertResultsOfClassifyImage:image
|
[self assertResultsOfClassifyImage:image
|
||||||
usingImageClassifier:imageClassifier
|
usingImageClassifier:imageClassifier
|
||||||
|
@ -434,7 +441,8 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
||||||
categoryName:@"folding chair"
|
categoryName:@"folding chair"
|
||||||
displayName:nil] ];
|
displayName:nil] ];
|
||||||
|
|
||||||
MPPImage *image = [self imageWithFileInfo:kMultiObjectsRotatedImage orientation:UIImageOrientationRight];
|
MPPImage *image = [self imageWithFileInfo:kMultiObjectsRotatedImage
|
||||||
|
orientation:UIImageOrientationRight];
|
||||||
|
|
||||||
// roi around folding chair
|
// roi around folding chair
|
||||||
MPPImageClassifierResult *imageClassifierResult =
|
MPPImageClassifierResult *imageClassifierResult =
|
||||||
|
@ -606,7 +614,6 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
||||||
|
|
||||||
MPPImageClassifier *imageClassifier = [self imageClassifierWithOptionsSucceeds:options];
|
MPPImageClassifier *imageClassifier = [self imageClassifierWithOptionsSucceeds:options];
|
||||||
|
|
||||||
|
|
||||||
MPPImage *image = [self imageWithFileInfo:kBurgerImage];
|
MPPImage *image = [self imageWithFileInfo:kBurgerImage];
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
|
@ -615,7 +622,8 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
||||||
error:nil];
|
error:nil];
|
||||||
[self assertImageClassifierResult:imageClassifierResult
|
[self assertImageClassifierResult:imageClassifierResult
|
||||||
hasExpectedCategoriesCount:maxResults
|
hasExpectedCategoriesCount:maxResults
|
||||||
expectedCategories:[MPPImageClassifierTests
|
expectedCategories:
|
||||||
|
[MPPImageClassifierTests
|
||||||
expectedResultCategoriesForClassifyBurgerImageWithFloatModel]];
|
expectedResultCategoriesForClassifyBurgerImageWithFloatModel]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -630,7 +638,8 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
||||||
options.completion = ^(MPPImageClassifierResult *result, NSError *error) {
|
options.completion = ^(MPPImageClassifierResult *result, NSError *error) {
|
||||||
[self assertImageClassifierResult:result
|
[self assertImageClassifierResult:result
|
||||||
hasExpectedCategoriesCount:maxResults
|
hasExpectedCategoriesCount:maxResults
|
||||||
expectedCategories:[MPPImageClassifierTests
|
expectedCategories:
|
||||||
|
[MPPImageClassifierTests
|
||||||
expectedResultCategoriesForClassifyBurgerImageWithFloatModel]];
|
expectedResultCategoriesForClassifyBurgerImageWithFloatModel]];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -663,17 +672,18 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
||||||
options.completion = ^(MPPImageClassifierResult *result, NSError *error) {
|
options.completion = ^(MPPImageClassifierResult *result, NSError *error) {
|
||||||
[self assertImageClassifierResult:result
|
[self assertImageClassifierResult:result
|
||||||
hasExpectedCategoriesCount:maxResults
|
hasExpectedCategoriesCount:maxResults
|
||||||
expectedCategories:[MPPImageClassifierTests
|
expectedCategories:
|
||||||
|
[MPPImageClassifierTests
|
||||||
expectedResultCategoriesForClassifyBurgerImageWithFloatModel]];
|
expectedResultCategoriesForClassifyBurgerImageWithFloatModel]];
|
||||||
};
|
};
|
||||||
|
|
||||||
MPPImageClassifier *imageClassifier = [self imageClassifierWithOptionsSucceeds:options];
|
MPPImageClassifier *imageClassifier = [self imageClassifierWithOptionsSucceeds:options];
|
||||||
|
|
||||||
// TODO: Mimic initialization from CMSampleBuffer as live stream mode is most likely to be used with the iOS camera.
|
// TODO: Mimic initialization from CMSampleBuffer as live stream mode is most likely to be used
|
||||||
// AVCaptureVideoDataOutput sample buffer delegates provide frames of type `CMSampleBuffer`.
|
// with the iOS camera. AVCaptureVideoDataOutput sample buffer delegates provide frames of type
|
||||||
|
// `CMSampleBuffer`.
|
||||||
MPPImage *image = [self imageWithFileInfo:kBurgerImage];
|
MPPImage *image = [self imageWithFileInfo:kBurgerImage];
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
XCTAssertTrue([imageClassifier classifyAsyncImage:image timestampMs:i error:nil]);
|
XCTAssertTrue([imageClassifier classifyAsyncImage:image timestampMs:i error:nil]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
NS_SWIFT_NAME(imageFromBundle(class:filename:type:));
|
NS_SWIFT_NAME(imageFromBundle(class:filename:type:));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads an image from a file in an app bundle into a `MPPImage` object with the specified orientation.
|
* Loads an image from a file in an app bundle into a `MPPImage` object with the specified
|
||||||
|
* orientation.
|
||||||
*
|
*
|
||||||
* @param classObject The specified class associated with the bundle containing
|
* @param classObject The specified class associated with the bundle containing
|
||||||
* the file to be loaded.
|
* the file to be loaded.
|
||||||
|
|
|
@ -16,14 +16,17 @@
|
||||||
|
|
||||||
@interface UIImage (FileUtils)
|
@interface UIImage (FileUtils)
|
||||||
|
|
||||||
+(nullable UIImage *)imageFromBundleWithClass:(Class)classObject fileName:(NSString *)name ofType:(NSString *)type;
|
+ (nullable UIImage *)imageFromBundleWithClass:(Class)classObject
|
||||||
|
fileName:(NSString *)name
|
||||||
|
ofType:(NSString *)type;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation UIImage (FileUtils)
|
@implementation UIImage (FileUtils)
|
||||||
|
|
||||||
+(nullable UIImage *)imageFromBundleWithClass:(Class)classObject fileName:(NSString *)name ofType:(NSString *)type {
|
+ (nullable UIImage *)imageFromBundleWithClass:(Class)classObject
|
||||||
|
fileName:(NSString *)name
|
||||||
|
ofType:(NSString *)type {
|
||||||
NSString *imagePath = [[NSBundle bundleForClass:classObject] pathForResource:name ofType:type];
|
NSString *imagePath = [[NSBundle bundleForClass:classObject] pathForResource:name ofType:type];
|
||||||
if (!imagePath) return nil;
|
if (!imagePath) return nil;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user