【发布时间】:2020-04-05 23:16:23
【问题描述】:
目前我面临在 MacOS 的 Objective-c/C++ XCode 项目中实现的 YOLOv3 的性能问题,但是性能太慢了。我对 MacOS 和 XCode 没有太多经验,所以我遵循了 this 教程。执行时间约为 0.25 秒。
设置: 我在 MacBook Pro Intel Core i5 3.1 GHz 和图形 Intel Iris Plus Graphic 650 1536MB 上运行它,性能约为 4 fps。这是可以理解的,GPU并不强大,它主要使用CPU。准确地说,它令人印象深刻,因为它比在 CPU 上运行的 Pytorch 实现更快。但是,我在 MacBook pro Intel i7 2.7GHz 和 AMD Radeon Pro 460 上运行此示例,性能仅为 6 fps。
this 网站的性能应该要好得多。您能否让我知道我在哪里做错了,或者这是我可以通过此设置获得的最佳性能吗?请注意,我已经检查了系统监视器,并且 GPU 在这两种情况下都已完全使用。
这是我的初始化:
//loading model
MLModel *model_ml = [[[YOLOv3 alloc] init] model];
float confidencerThreshold = 0.8;
NSMutableArray<Prediction*> *predictions = [[NSMutableArray alloc] init];
VNCoreMLModel *model = [VNCoreMLModel modelForMLModel:model_ml error:nil];
VNCoreMLRequest *request = [[VNCoreMLRequest alloc] initWithModel:model completionHandler:^(VNRequest * _Nonnull request, NSError * _Nullable error){
for(VNRecognizedObjectObservation *observation in request.results)
{
if(observation.confidence > confidencerThreshold){
CGRect rect = observation.boundingBox;
Prediction* prediction = [[Prediction alloc] initWithValues: 0 Confidence: observation.confidence BBox: rect];
[predictions addObject:prediction];
}
}
}];
request.imageCropAndScaleOption = VNImageCropAndScaleOptionScaleFill;
float ratio = height/CGFloat(width);
还有我的循环实现
cv::Mat frame;
int i = 0;
while(1){
cap>>frame;
if(frame.empty()){
break;
}
image = CGImageFromCVMat(frame.clone());
VNImageRequestHandler *imageHandler = [[VNImageRequestHandler alloc] initWithCGImage:image options:nil];
NSDate *methodStart = [NSDate date]; //Measuring performance here
NSError *error = nil;
[imageHandler performRequests:@[request] error:&error]; //Call request
if(error){
NSLog(@"%@",error.localizedDescription);
}
NSDate *methodFinish = [NSDate date];
NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:methodStart]; //get execution time
// draw bounding boxes
for(Prediction *prediction in predictions){
CGRect rect = [prediction getBBox];
cv::rectangle(frame,cv::Point(rect.origin.x * width,(1 - rect.origin.y) * height),
cv::Point((rect.origin.x + rect.size.width) * width, (1 - (rect.origin.y + rect.size.height)) * height),
cv::Scalar(0,255,0), 1,8,0);
}
std::cout<<"Execution time "<<executionTime<<" sec"<<" Frame id: "<<i<<" with size "<<frame.size()<<std::endl;
[predictions removeAllObjects];
}
cap.release();
谢谢。
【问题讨论】:
标签: objective-c macos yolo coreml