Merge pull request #4447 from priankakariatyml:ios-code-review-fixes
PiperOrigin-RevId: 534526451
This commit is contained in:
commit
1523cc48a1
|
@ -28,9 +28,7 @@ static NSString *const kExpectedErrorDomain = @"com.google.mediapipe.tasks";
|
|||
XCTAssertNotNil(error); \
|
||||
XCTAssertEqualObjects(error.domain, expectedError.domain); \
|
||||
XCTAssertEqual(error.code, expectedError.code); \
|
||||
XCTAssertNotEqual( \
|
||||
[error.localizedDescription rangeOfString:expectedError.localizedDescription].location, \
|
||||
NSNotFound)
|
||||
XCTAssertEqualObjects(error.localizedDescription, expectedError.localizedDescription)
|
||||
|
||||
#define AssertEqualCategoryArrays(categories, expectedCategories) \
|
||||
XCTAssertEqual(categories.count, expectedCategories.count); \
|
||||
|
|
|
@ -29,9 +29,7 @@ static const float kSimilarityDiffTolerance = 1e-4;
|
|||
XCTAssertNotNil(error); \
|
||||
XCTAssertEqualObjects(error.domain, expectedError.domain); \
|
||||
XCTAssertEqual(error.code, expectedError.code); \
|
||||
XCTAssertNotEqual( \
|
||||
[error.localizedDescription rangeOfString:expectedError.localizedDescription].location, \
|
||||
NSNotFound)
|
||||
XCTAssertEqualObjects(error.localizedDescription, expectedError.localizedDescription)
|
||||
|
||||
#define AssertTextEmbedderResultHasOneEmbedding(textEmbedderResult) \
|
||||
XCTAssertNotNil(textEmbedderResult); \
|
||||
|
|
|
@ -34,9 +34,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
|||
XCTAssertNotNil(error); \
|
||||
XCTAssertEqualObjects(error.domain, expectedError.domain); \
|
||||
XCTAssertEqual(error.code, expectedError.code); \
|
||||
XCTAssertNotEqual( \
|
||||
[error.localizedDescription rangeOfString:expectedError.localizedDescription].location, \
|
||||
NSNotFound)
|
||||
XCTAssertEqualObjects(error.localizedDescription, expectedError.localizedDescription)
|
||||
|
||||
#define AssertEqualCategoryArrays(categories, expectedCategories) \
|
||||
XCTAssertEqual(categories.count, expectedCategories.count); \
|
||||
|
|
|
@ -32,9 +32,7 @@ static NSString *const kLiveStreamTestsDictExpectationKey = @"expectation";
|
|||
XCTAssertNotNil(error); \
|
||||
XCTAssertEqualObjects(error.domain, expectedError.domain); \
|
||||
XCTAssertEqual(error.code, expectedError.code); \
|
||||
XCTAssertNotEqual( \
|
||||
[error.localizedDescription rangeOfString:expectedError.localizedDescription].location, \
|
||||
NSNotFound)
|
||||
XCTAssertEqualObjects(error.localizedDescription, expectedError.localizedDescription)
|
||||
|
||||
#define AssertEqualCategories(category, expectedCategory, detectionIndex, categoryIndex) \
|
||||
XCTAssertEqual(category.index, expectedCategory.index, \
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "mediapipe/tasks/cc/components/containers/proto/classifications.pb.h"
|
||||
|
||||
static const int kMicroSecondsPerMilliSecond = 1000;
|
||||
static const int kMicrosecondsPerMillisecond = 1000;
|
||||
|
||||
namespace {
|
||||
using ClassificationResultProto =
|
||||
|
@ -29,19 +29,26 @@ using ::mediapipe::Packet;
|
|||
|
||||
+ (nullable MPPImageClassifierResult *)imageClassifierResultWithClassificationsPacket:
|
||||
(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()) {
|
||||
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>()];
|
||||
|
||||
return [[MPPImageClassifierResult alloc]
|
||||
initWithClassificationResult:classificationResult
|
||||
timestampInMilliseconds:(NSInteger)(packet.Timestamp().Value() /
|
||||
kMicroSecondsPerMilliSecond)];
|
||||
kMicrosecondsPerMillisecond)];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue
Block a user