在从VNClassificationObservation获取时遇到问题。
我的目标id是识别对象并显示带有对象名称的弹出窗口,我可以获取名称,但无法获取对象坐标或边框。
下面是代码:
let handler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer, options: requestOptions)
do {
try handler.perform([classificationRequest, detectFaceRequest])
} catch {
print(error)
}然后我来处理
func handleClassification(request: VNRequest, error: Error?) {
guard let observations = request.results as? [VNClassificationObservation] else {
fatalError("unexpected result type from VNCoreMLRequest")
}
// Filter observation
let filteredOservations = observations[0...10].filter({ $0.confidence > 0.1 })
// Update UI
DispatchQueue.main.async { [weak self] in
for observation in filteredOservations {
print("observation: ",observation.identifier)
//HERE: I need to display popup with observation name
}
}
}更新:
lazy var classificationRequest: VNCoreMLRequest = {
// Load the ML model through its generated class and create a Vision request for it.
do {
let model = try VNCoreMLModel(for: Inceptionv3().model)
let request = VNCoreMLRequest(model: model, completionHandler: self.handleClassification)
request.imageCropAndScaleOption = VNImageCropAndScaleOptionCenterCrop
return request
} catch {
fatalError("can't load Vision ML model: \(error)")
}
}()发布于 2017-06-23 01:10:59
这是因为分类器不返回对象坐标或帧。分类器只给出类别列表上的概率分布。
您在这里使用的是什么型号?
发布于 2017-06-23 23:10:18
纯分类器模型只能回答“这是什么图片?”,不能检测和定位图片中的对象。所有的free models on the Apple developer site (包括盗梦空间v3)都属于这种类型。
当Vision使用这样的模型时,它根据MLModel文件中声明的输出将模型标识为分类器,并返回VNClassificationObservation对象作为输出。
如果您找到或创建了一个经过训练以识别和定位对象的模型,您仍然可以将其与Vision一起使用。当您将该模型转换为Core格式时,MLModel文件将描述多个输出。当Vision使用具有多个输出的模型时,它返回一个VNCoreMLFeatureValueObservation对象数组-模型的每个输出一个对象。
模型如何声明其输出将决定哪些特征值代表什么。报告分类和边界框的模型可以输出一个字符串和四个双精度值,或者一个字符串和一个多数组,等等。
附录:这是一个在iOS 11上工作并返回VNCoreMLFeatureValueObservation的模型:TinyYOLO
发布于 2018-09-12 06:05:44
为了跟踪和识别对象,您必须使用Darknet创建自己的模型。我也遇到过同样的问题,并使用TuriCreate训练模型,而不是仅仅向框架提供图像,您还必须提供带有边界框的图像。苹果在这里记录了如何创建这些模型:Apple TuriCreate docs
https://stackoverflow.com/questions/44705116
复制相似问题