         dispatch_async(dispatch_get_main_queue(), {
             self.infoLabel.text = label
         })
-
-        /*if true {
-            let commandBuffer = commandQueue!.commandBuffer()
-            let commandEncoder = commandBuffer.computeCommandEncoder()
-            commandEncoder.setComputePipelineState(float2BGRAState!)
-            commandEncoder.setTexture(net!.blobs["data"]!, atIndex: 0)
-            commandEncoder.setTexture(outputBGRA, atIndex: 1)
-            let threadsPerThreadgroup = MTLSizeMake(16, 16, 1)
-            let threadgroupsPerGrid = MTLSizeMake(windowSize / threadsPerThreadgroup.width,
-                windowSize / threadsPerThreadgroup.height, 1)
-            commandEncoder.dispatchThreadgroups(threadgroupsPerGrid, threadsPerThreadgroup: threadsPerThreadgroup)
-            commandEncoder.endEncoding()
-            commandBuffer.commit();
-            commandBuffer.waitUntilCompleted()
-        }*/
-
-
-        // Copy data from the output texture.
-        /*var imageBuf = Array<UInt8>(count: windowSize * windowSize * 4, repeatedValue: 0)
-        outputBGRA!.getBytes(&imageBuf, bytesPerRow: windowSize*4,
-            fromRegion: MTLRegionMake2D(0, 0, windowSize, windowSize), mipmapLevel: 0)
-
-        let colorSpace = CGColorSpaceCreateDeviceRGB()
-        let context = CGBitmapContextCreate(&imageBuf, windowSize, windowSize, 8, 4*windowSize, colorSpace,
-            CGImageAlphaInfo.PremultipliedFirst.rawValue | CGBitmapInfo.ByteOrder32Little.rawValue)
-        if context == nil {
-            print("Could not create context from image buf")
-            exit(1)
-        }
-        let cgImg = CGBitmapContextCreateImage(context)
-        if cgImg == nil {
-            print("Could not create CGImage from context")
-            exit(1)
-        }
-        let uiImg = UIImage(CGImage:cgImg!, scale: 1, orientation: UIImageOrientation.Up)
-        UIImageWriteToSavedPhotosAlbum(uiImg, nil, nil, nil)*/
-        // DO NOT FORGET to release cgImg and uiImg.
     }
 }

        }
    }

    private func loadKernelState(kernelName: String) -> MTLComputePipelineState? {
        let f = metalLib!.newFunctionWithName(kernelName)
        if f == nil {
            print("Could not load \(kernelName) from the library")
            exit(1)
        }
        do {
            return try metalDevice!.newComputePipelineStateWithFunction(f!)
        } catch {
            print("Could not create pipeline state for \(kernelName)")
            exit(1)
        }
    }

    private func initMetal() {
        engine = Engine()
        net = Net(engine: engine!, config: GoogLeNetConfig(),
            threadsPerThreadgroup: GoogLeNetProfile.GetThreadsPerThreadgroup())
        metalDevice = MTLCreateSystemDefaultDevice()
        CVMetalTextureCacheCreate(kCFAllocatorDefault, nil, metalDevice!, nil, &textureCache)
        metalLib = metalDevice!.newDefaultLibrary()!
        commandQueue = metalDevice!.newCommandQueue()

        cropAndRotateState = loadKernelState("cropAndRotate")
        crop352x288to224State = loadKernelState("crop352x288to224")
        float2BGRAState = loadKernelState("float2BGRA")

        // init output texture
        let outputDesc = MTLTextureDescriptor()

    func captureOutput(captureOutput: AVCaptureOutput!,
            didOutputSampleBuffer sampleBuffer: CMSampleBuffer!,
            fromConnection connection: AVCaptureConnection!) {
        self.frameCount++
        if self.frameCount < 50 {
            return
