|
|
@@ -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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|