   }
 
   func setUpCoreImage() {
-    let status = CVPixelBufferCreate(nil, YOLO.inputWidth, YOLO.inputHeight,
-                                     kCVPixelFormatType_32BGRA, nil,
-                                     &resizedPixelBuffer)
-    if status != kCVReturnSuccess {
-      print("Error: could not create resized pixel buffer", status)
+    // Since we might be running several requests in parallel, we also need
+    // to do the resizing in different pixel buffers or we might overwrite a
+    // pixel buffer that's already in use.
+    for _ in 0..<YOLO.maxBoundingBoxes {
+      var resizedPixelBuffer: CVPixelBuffer?
+      let status = CVPixelBufferCreate(nil, YOLO.inputWidth, YOLO.inputHeight,
+                                       kCVPixelFormatType_32BGRA, nil,
+                                       &resizedPixelBuffer)
+
+      if status != kCVReturnSuccess {
+        print("Error: could not create resized pixel buffer", status)
+      }
+      resizedPixelBuffers.append(resizedPixelBuffer)
     }
   }
 

  var colors: [UIColor] = []

  let ciContext = CIContext()
  var resizedPixelBuffer: CVPixelBuffer?

  var framesDone = 0
  var frameCapturingStartTime = CACurrentMediaTime()


    // Vision will automatically resize the input image.
    let handler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer)
    let request = requests[inflightIndex]

    // Because perform() will block until after the request completes, we
    // run it on a concurrent background queue, so that the next frame can
