Functions
The following functions are available globally.
-
Returns the top
kpredictions from Core ML classification results as an array of(String, Double)pairs.Declaration
Swift
public func top(_ k: Int, _ prob: [String: Double]) -> [(String, Double)] -
Returns the top
kpredictions from Vision classification results as an array of(String, Double)pairs.Declaration
Swift
public func top(_ k: Int, _ observations: [VNClassificationObservation]) -> [(String, Double)]
-
Undocumented
Declaration
Swift
public func clamp<T: Comparable>(_ x: T, min: T, max: T) -> T
-
Creates a RGB pixel buffer of the specified width and height.
Declaration
Swift
public func createPixelBuffer(width: Int, height: Int) -> CVPixelBuffer? -
First crops the pixel buffer, then resizes it.
Declaration
Swift
public func resizePixelBuffer(_ srcPixelBuffer: CVPixelBuffer, cropX: Int, cropY: Int, cropWidth: Int, cropHeight: Int, scaleWidth: Int, scaleHeight: Int) -> CVPixelBuffer? -
Resizes a CVPixelBuffer to a new width and height.
Declaration
Swift
public func resizePixelBuffer(_ pixelBuffer: CVPixelBuffer, width: Int, height: Int) -> CVPixelBuffer? -
Resizes a CVPixelBuffer to a new width and height.
Declaration
Swift
public func resizePixelBuffer(_ pixelBuffer: CVPixelBuffer, width: Int, height: Int, output: CVPixelBuffer, context: CIContext)
-
Computes intersection-over-union overlap between two bounding boxes.
Declaration
Swift
public func IOU(_ a: CGRect, _ b: CGRect) -> Float -
Removes bounding boxes that overlap too much with other boxes that have a higher score.
Declaration
Swift
public func nonMaxSuppression(predictions: [NMSPrediction], iouThreshold: Float, maxBoxes: Int) -> [Int] -
Removes bounding boxes that overlap too much with other boxes that have a higher score.
Based on code from https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/kernels/non_max_suppression_op.cc
Note
This version of NMS ignores the class of the bounding boxes. Since it selects the bounding boxes in a greedy fashion, if a certain class has many boxes that are selected, then it is possible none of the boxes of the other classes get selected.
Declaration
Swift
public func nonMaxSuppression(predictions: [NMSPrediction], indices: [Int], iouThreshold: Float, maxBoxes: Int) -> [Int]Parameters
predictionsan array of bounding boxes and their scores
indiceswhich predictions to look at
iouThresholdused to decide whether boxes overlap too much
maxBoxesthe maximum number of boxes that will be selected
Return Value
the array indices of the selected bounding boxes
-
nonMaxSuppressionMultiClass(numClasses:predictions:scoreThreshold:iouThreshold:maxPerClass:maxTotal:)Multi-class version of non maximum suppression.
Where
nonMaxSuppression()does not look at the class of the predictions at all, the multi-class version first selects the best bounding boxes for each class, and then keeps the best ones of those.With this method you can usually expect to see at least one bounding box for each class (unless all the scores for a given class are really low).
Based on code from: https://github.com/tensorflow/models/blob/master/object_detection/core/post_processing.py
Declaration
Swift
public func nonMaxSuppressionMultiClass(numClasses: Int, predictions: [NMSPrediction], scoreThreshold: Float, iouThreshold: Float, maxPerClass: Int, maxTotal: Int) -> [Int]Parameters
numClassesthe number of classes
predictionsan array of bounding boxes and their scores
scoreThresholdused to only keep bounding boxes with a high enough score
iouThresholdused to decide whether boxes overlap too much
maxPerClassthe maximum number of boxes that will be selected per class
maxTotalmaximum number of boxes that will be selected over all classes
Return Value
the array indices of the selected bounding boxes
Functions Reference