Updated formatted
This commit is contained in:
parent
da8b60700b
commit
8682a3ffd9
|
@ -20,7 +20,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
@interface MPPBaseOptions (Helpers)
|
||||
|
||||
- (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
|
||||
|
||||
|
|
|
@ -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 kBurgerRotatedImage = @{@"name" : @"burger_rotated", @"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 NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
||||
|
||||
|
@ -112,7 +113,7 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
|||
|
||||
#pragma mark Assert Classify Results
|
||||
|
||||
-(MPPImage *)imageWithFileInfo:(NSDictionary *)fileInfo {
|
||||
- (MPPImage *)imageWithFileInfo:(NSDictionary *)fileInfo {
|
||||
MPPImage *image = [MPPImage imageFromBundleWithClass:[MPPImageClassifierTests class]
|
||||
fileName:fileInfo[@"name"]
|
||||
ofType:fileInfo[@"type"]];
|
||||
|
@ -121,7 +122,8 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
|||
return image;
|
||||
}
|
||||
|
||||
-(MPPImage *)imageWithFileInfo:(NSDictionary *)fileInfo orientation:(UIImageOrientation)orientation {
|
||||
- (MPPImage *)imageWithFileInfo:(NSDictionary *)fileInfo
|
||||
orientation:(UIImageOrientation)orientation {
|
||||
MPPImage *image = [MPPImage imageFromBundleWithClass:[MPPImageClassifierTests class]
|
||||
fileName:fileInfo[@"name"]
|
||||
ofType:fileInfo[@"type"]
|
||||
|
@ -242,10 +244,12 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
|||
- (void)testClassifyWithModelPathAndFloatModelSucceeds {
|
||||
MPPImageClassifier *imageClassifier = [self imageClassifierFromModelFileWithName:kFloatModelName];
|
||||
|
||||
[self assertResultsOfClassifyImageWithFileInfo:kBurgerImage
|
||||
[self
|
||||
assertResultsOfClassifyImageWithFileInfo:kBurgerImage
|
||||
usingImageClassifier:imageClassifier
|
||||
expectedCategoriesCount:kMobileNetCategoriesCount
|
||||
equalsCategories:[MPPImageClassifierTests
|
||||
equalsCategories:
|
||||
[MPPImageClassifierTests
|
||||
expectedResultCategoriesForClassifyBurgerImageWithFloatModel]];
|
||||
}
|
||||
|
||||
|
@ -257,10 +261,12 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
|||
|
||||
MPPImageClassifier *imageClassifier = [self imageClassifierWithOptionsSucceeds:options];
|
||||
|
||||
[self assertResultsOfClassifyImageWithFileInfo:kBurgerImage
|
||||
[self
|
||||
assertResultsOfClassifyImageWithFileInfo:kBurgerImage
|
||||
usingImageClassifier:imageClassifier
|
||||
expectedCategoriesCount:maxResults
|
||||
equalsCategories:[MPPImageClassifierTests
|
||||
equalsCategories:
|
||||
[MPPImageClassifierTests
|
||||
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
|
||||
usingImageClassifier:imageClassifier
|
||||
|
@ -434,7 +441,8 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
|||
categoryName:@"folding chair"
|
||||
displayName:nil] ];
|
||||
|
||||
MPPImage *image = [self imageWithFileInfo:kMultiObjectsRotatedImage orientation:UIImageOrientationRight];
|
||||
MPPImage *image = [self imageWithFileInfo:kMultiObjectsRotatedImage
|
||||
orientation:UIImageOrientationRight];
|
||||
|
||||
// roi around folding chair
|
||||
MPPImageClassifierResult *imageClassifierResult =
|
||||
|
@ -606,7 +614,6 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
|||
|
||||
MPPImageClassifier *imageClassifier = [self imageClassifierWithOptionsSucceeds:options];
|
||||
|
||||
|
||||
MPPImage *image = [self imageWithFileInfo:kBurgerImage];
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
@ -615,7 +622,8 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
|||
error:nil];
|
||||
[self assertImageClassifierResult:imageClassifierResult
|
||||
hasExpectedCategoriesCount:maxResults
|
||||
expectedCategories:[MPPImageClassifierTests
|
||||
expectedCategories:
|
||||
[MPPImageClassifierTests
|
||||
expectedResultCategoriesForClassifyBurgerImageWithFloatModel]];
|
||||
}
|
||||
}
|
||||
|
@ -630,7 +638,8 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
|||
options.completion = ^(MPPImageClassifierResult *result, NSError *error) {
|
||||
[self assertImageClassifierResult:result
|
||||
hasExpectedCategoriesCount:maxResults
|
||||
expectedCategories:[MPPImageClassifierTests
|
||||
expectedCategories:
|
||||
[MPPImageClassifierTests
|
||||
expectedResultCategoriesForClassifyBurgerImageWithFloatModel]];
|
||||
};
|
||||
|
||||
|
@ -663,17 +672,18 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
|||
options.completion = ^(MPPImageClassifierResult *result, NSError *error) {
|
||||
[self assertImageClassifierResult:result
|
||||
hasExpectedCategoriesCount:maxResults
|
||||
expectedCategories:[MPPImageClassifierTests
|
||||
expectedCategories:
|
||||
[MPPImageClassifierTests
|
||||
expectedResultCategoriesForClassifyBurgerImageWithFloatModel]];
|
||||
};
|
||||
|
||||
MPPImageClassifier *imageClassifier = [self imageClassifierWithOptionsSucceeds:options];
|
||||
|
||||
// TODO: Mimic initialization from CMSampleBuffer as live stream mode is most likely to be used with the iOS camera.
|
||||
// AVCaptureVideoDataOutput sample buffer delegates provide frames of type `CMSampleBuffer`.
|
||||
// TODO: Mimic initialization from CMSampleBuffer as live stream mode is most likely to be used
|
||||
// with the iOS camera. AVCaptureVideoDataOutput sample buffer delegates provide frames of type
|
||||
// `CMSampleBuffer`.
|
||||
MPPImage *image = [self imageWithFileInfo:kBurgerImage];
|
||||
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
XCTAssertTrue([imageClassifier classifyAsyncImage:image timestampMs:i error:nil]);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
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
|
||||
* the file to be loaded.
|
||||
|
|
|
@ -16,14 +16,17 @@
|
|||
|
||||
@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
|
||||
|
||||
@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];
|
||||
if (!imagePath) return nil;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user