Added MPPEmbeddingResult

This commit is contained in:
Prianka Liz Kariat 2023-01-25 20:17:04 +05:30
parent 7d62402768
commit db5ee6689f
3 changed files with 95 additions and 0 deletions

View File

@ -35,3 +35,9 @@ objc_library(
hdrs = ["sources/MPPEmbedding.h"],
)
objc_library(
name = "MPPEmbeddingResult",
srcs = ["sources/MPPEmbeddingResult.m"],
hdrs = ["sources/MPPEmbeddingResult.h"],
deps = [":MPPEmbedding"],
)

View File

@ -0,0 +1,59 @@
// Copyright 2023 The MediaPipe Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import <Foundation/Foundation.h>
#import "mediapipe/tasks/ios/components/containers/sources/MPPEmbedding.h"
NS_ASSUME_NONNULL_BEGIN
/** Represents the embedding results of a model. Typically used as a result for embedding tasks. */
NS_SWIFT_NAME(EmbeddingResult)
@interface MPPEmbeddingResult : NSObject
/**
* An Array of `MPPEmbedding` objects containing the embedding results for each head of the model.
*/
@property(nonatomic, readonly) NSArray<MPPEmbedding *> *embeddings;
/**
* @brief The optional timestamp (in milliseconds) of the start of the chunk of data corresponding
* to these results.
* This is only used for embedding extraction on time series (e.g. audio embedder). In these use
* cases, the amount of data to process might exceed the maximum size that the model can process: to
* solve this, the input data is split into multiple chunks starting at different timestamps.
*/
@property(nonatomic, readonly) NSInteger timestampMs;
/**
* Initializes a new `MPPEmbedding` with the given array of embeddings and timestamp (in
* milliseconds).
*
* @param embeddings An Array of `MPPEmbedding` objects containing the embedding results for each
* head of the model.
* @param timestampMs The optional timestamp (in milliseconds) of the start of the chunk of data
* corresponding to these results. Pass `0` if timestamp is absent.
*
* @return An instance of `MPPEmbeddingResult` initialized with the given array of embeddings and
* timestampMs.
*/
- (instancetype)initWithEmbeddings:(NSArray<MPPEmbedding *> *)embeddings
timestampMs:(NSInteger)timestampMs NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,30 @@
// Copyright 2023 The MediaPipe Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#import "mediapipe/tasks/ios/components/containers/sources/MPPEmbeddingResult.h"
@implementation MPPEmbeddingResult
- (instancetype)initWithEmbeddings:(NSArray<MPPEmbedding *> *)embeddings
timestampMs:(NSInteger)timestampMs {
self = [super init];
if (self) {
_embeddings = embeddings;
_timestampMs = timestampMs;
}
return self;
}
@end