Merge pull request #4447 from priankakariatyml:ios-code-review-fixes

PiperOrigin-RevId: 534526451
This commit is contained in:
Copybara-Service 2023-05-23 12:55:35 -07:00
commit 1523cc48a1
5 changed files with 16 additions and 17 deletions

View File

@ -28,9 +28,7 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
XCTAssertNotNil(error); \ XCTAssertNotNil(error); \
XCTAssertEqualObjects(error.domain, expectedError.domain); \ XCTAssertEqualObjects(error.domain, expectedError.domain); \
XCTAssertEqual(error.code, expectedError.code); \ XCTAssertEqual(error.code, expectedError.code); \
XCTAssertNotEqual( \ XCTAssertEqualObjects(error.localizedDescription, expectedError.localizedDescription)
[error.localizedDescription rangeOfString:expectedError.localizedDescription].location, \
NSNotFound)
#define AssertEqualCategoryArrays(categories, expectedCategories) \ #define AssertEqualCategoryArrays(categories, expectedCategories) \
XCTAssertEqual(categories.count, expectedCategories.count); \ XCTAssertEqual(categories.count, expectedCategories.count); \

View File

@ -29,9 +29,7 @@ static const float kSimilarityDiffTolerance = 1e-4;
XCTAssertNotNil(error); \ XCTAssertNotNil(error); \
XCTAssertEqualObjects(error.domain, expectedError.domain); \ XCTAssertEqualObjects(error.domain, expectedError.domain); \
XCTAssertEqual(error.code, expectedError.code); \ XCTAssertEqual(error.code, expectedError.code); \
XCTAssertNotEqual( \ XCTAssertEqualObjects(error.localizedDescription, expectedError.localizedDescription)
[error.localizedDescription rangeOfString:expectedError.localizedDescription].location, \
NSNotFound)
#define AssertTextEmbedderResultHasOneEmbedding(textEmbedderResult) \ #define AssertTextEmbedderResultHasOneEmbedding(textEmbedderResult) \
XCTAssertNotNil(textEmbedderResult); \ XCTAssertNotNil(textEmbedderResult); \

View File

@ -34,9 +34,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
XCTAssertNotNil(error); \ XCTAssertNotNil(error); \
XCTAssertEqualObjects(error.domain, expectedError.domain); \ XCTAssertEqualObjects(error.domain, expectedError.domain); \
XCTAssertEqual(error.code, expectedError.code); \ XCTAssertEqual(error.code, expectedError.code); \
XCTAssertNotEqual( \ XCTAssertEqualObjects(error.localizedDescription, expectedError.localizedDescription)
[error.localizedDescription rangeOfString:expectedError.localizedDescription].location, \
NSNotFound)
#define AssertEqualCategoryArrays(categories, expectedCategories) \ #define AssertEqualCategoryArrays(categories, expectedCategories) \
XCTAssertEqual(categories.count, expectedCategories.count); \ XCTAssertEqual(categories.count, expectedCategories.count); \

View File

@ -32,9 +32,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
XCTAssertNotNil(error); \ XCTAssertNotNil(error); \
XCTAssertEqualObjects(error.domain, expectedError.domain); \ XCTAssertEqualObjects(error.domain, expectedError.domain); \
XCTAssertEqual(error.code, expectedError.code); \ XCTAssertEqual(error.code, expectedError.code); \
XCTAssertNotEqual( \ XCTAssertEqualObjects(error.localizedDescription, expectedError.localizedDescription)
[error.localizedDescription rangeOfString:expectedError.localizedDescription].location, \
NSNotFound)
#define AssertEqualCategories(category, expectedCategory, detectionIndex, categoryIndex) \ #define AssertEqualCategories(category, expectedCategory, detectionIndex, categoryIndex) \
XCTAssertEqual(category.index, expectedCategory.index, \ XCTAssertEqual(category.index, expectedCategory.index, \

View File

@ -17,7 +17,7 @@
#include "mediapipe/tasks/cc/components/containers/proto/classifications.pb.h" #include "mediapipe/tasks/cc/components/containers/proto/classifications.pb.h"
static const int kMicroSecondsPerMilliSecond = 1000; static const int kMicrosecondsPerMillisecond = 1000;
namespace { namespace {
using ClassificationResultProto = using ClassificationResultProto =
@ -29,19 +29,26 @@ using ::mediapipe::Packet;
+ (nullable MPPImageClassifierResult *)imageClassifierResultWithClassificationsPacket: + (nullable MPPImageClassifierResult *)imageClassifierResultWithClassificationsPacket:
(const Packet &)packet { (const Packet &)packet {
MPPClassificationResult *classificationResult; // Even if packet does not validate as the expected type, you can safely access the timestamp.
NSInteger timestampInMilliSeconds =
(NSInteger)(packet.Timestamp().Value() / kMicrosecondsPerMillisecond);
if (!packet.ValidateAsType<ClassificationResultProto>().ok()) { if (!packet.ValidateAsType<ClassificationResultProto>().ok()) {
return nil; // MPPClassificationResult's timestamp is populated from timestamp `ClassificationResultProto`'s
// timestamp_ms(). It is 0 since the packet can't be validated as a `ClassificationResultProto`.
return [[MPPImageClassifierResult alloc]
initWithClassificationResult:[[MPPClassificationResult alloc] initWithClassifications:@[]
timestampInMilliseconds:0]
timestampInMilliseconds:timestampInMilliSeconds];
} }
classificationResult = [MPPClassificationResult MPPClassificationResult *classificationResult = [MPPClassificationResult
classificationResultWithProto:packet.Get<ClassificationResultProto>()]; classificationResultWithProto:packet.Get<ClassificationResultProto>()];
return [[MPPImageClassifierResult alloc] return [[MPPImageClassifierResult alloc]
initWithClassificationResult:classificationResult initWithClassificationResult:classificationResult
timestampInMilliseconds:(NSInteger)(packet.Timestamp().Value() / timestampInMilliseconds:(NSInteger)(packet.Timestamp().Value() /
kMicroSecondsPerMilliSecond)]; kMicrosecondsPerMillisecond)];
} }
@end @end