Adds delegate to enable GPU acceleration in MPPVisionTask
This commit is contained in:
parent
e39119ae53
commit
0a68d8d502
|
@ -16,6 +16,11 @@
|
|||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
typedef NS_ENUM(NSInteger, MPPBaseOptionsDelegate) {
|
||||
MPPBaseOptionsDelegateCPU = 0,
|
||||
MPPBaseOptionsDelegateGPU = 1
|
||||
} NS_SWIFT_NAME(BaseOptionsDelegate);
|
||||
|
||||
/**
|
||||
* Holds the base options that is used for creation of any type of task. It has fields with
|
||||
* important information acceleration configuration, TFLite model source etc.
|
||||
|
@ -26,6 +31,12 @@ NS_SWIFT_NAME(BaseOptions)
|
|||
/** The path to the model asset to open and mmap in memory. */
|
||||
@property(nonatomic, copy) NSString *modelAssetPath;
|
||||
|
||||
/**
|
||||
* The delegate to run MediaPipe. If the delegate is not set, the default
|
||||
* delegate CPU is used. Use `delegate_options` to configure advanced
|
||||
* features of the selected delegate.
|
||||
*/
|
||||
@property(nonatomic) MPPBaseOptionsDelegate delegate;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
MPPBaseOptions *baseOptions = [[MPPBaseOptions alloc] init];
|
||||
|
||||
baseOptions.modelAssetPath = self.modelAssetPath;
|
||||
|
||||
baseOptions.delegate = self.delegate;
|
||||
return baseOptions;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,16 @@ using BaseOptionsProto = ::mediapipe::tasks::core::proto::BaseOptions;
|
|||
if (self.modelAssetPath) {
|
||||
baseOptionsProto->mutable_model_asset()->set_file_name(self.modelAssetPath.UTF8String);
|
||||
}
|
||||
switch (self.delegate) {
|
||||
case MPPBaseOptionsDelegateCPU: {
|
||||
baseOptionsProto->mutable_acceleration()->mutable_tflite();
|
||||
break;
|
||||
}
|
||||
case MPPBaseOptionsDelegateGPU: {
|
||||
baseOptionsProto->mutable_acceleration()->mutable_gpu();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -98,6 +98,8 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
if (imageBuffer == NULL) {
|
||||
return nil;
|
||||
}
|
||||
_pixelBuffer = imageBuffer;
|
||||
CVPixelBufferRetain(imageBuffer);
|
||||
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
|
|
|
@ -32,6 +32,10 @@ using ::mediapipe::Timestamp;
|
|||
@implementation MPPVisionPacketCreator
|
||||
|
||||
+ (Packet)createPacketWithMPPImage:(MPPImage *)image error:(NSError **)error {
|
||||
if ((image.imageSourceType == MPPImageSourceTypePixelBuffer || image.imageSourceType == MPPImageSourceTypeSampleBuffer) && [image pixelBuffer] != nil) {
|
||||
return MakePacket<mediapipe::Image>([image pixelBuffer]);
|
||||
}
|
||||
|
||||
std::unique_ptr<ImageFrame> imageFrame = [image imageFrameWithError:error];
|
||||
|
||||
if (!imageFrame) {
|
||||
|
@ -44,14 +48,9 @@ using ::mediapipe::Timestamp;
|
|||
+ (Packet)createPacketWithMPPImage:(MPPImage *)image
|
||||
timestampInMilliseconds:(NSInteger)timestampInMilliseconds
|
||||
error:(NSError **)error {
|
||||
std::unique_ptr<ImageFrame> imageFrame = [image imageFrameWithError:error];
|
||||
auto packet = [self createPacketWithMPPImage:image error:error];
|
||||
|
||||
if (!imageFrame) {
|
||||
return Packet();
|
||||
}
|
||||
|
||||
return MakePacket<Image>(std::move(imageFrame))
|
||||
.At(Timestamp(int64(timestampInMilliseconds * kMicroSecondsPerMilliSecond)));
|
||||
return packet.At(Timestamp(int64(timestampInMilliseconds * kMicroSecondsPerMilliSecond)));
|
||||
}
|
||||
|
||||
+ (Packet)createPacketWithNormalizedRect:(NormalizedRect &)normalizedRect {
|
||||
|
|
Loading…
Reference in New Issue
Block a user