 
         self.measureBlock {
             for _ in 1...1 {
-                net.forward(input!)
+                self.net!.forward(input!)
             }
         }
     }



class MetalDetectorTests: XCTestCase {
    
    override func setUp() {
        super.setUp()
        // Put setup code here. This method is called before the invocation of each test method in the class.
    }
    
    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }
    
    func testInitMetal() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct results.
        print("Hello, I am a test!")
        let metalDevice = MTLCreateSystemDefaultDevice()
        XCTAssert(metalDevice != nil)
    }

    func argMax(arr : [Float]) -> (Int, Float) {

        return (idx, maxv)
    }

    func checkMetrics(name: String, L1: Float, err1: Float, L2: Float, err2: Float) {
        let realL1 = engine!.L1(net!.blobs[name]!)
        let realL2 = engine!.L2(net!.blobs[name]!)
        let realErr1 = abs(L1-realL1)/L1
        let realErr2 = abs(L2-realL2)/L2
        print("\(name): L1: \(realL1), err1: \(realErr1), L2: \(realL2), err2: \(realErr2)")
        XCTAssertEqualWithAccuracy(realL1, L1, accuracy: L1 * err1)
        XCTAssertEqualWithAccuracy(realL2, L2, accuracy: L2 * err2)
    }

    func testGoogleNetOnCat() {
        let input = engine!.GetResourceAsMetalTexture("cat.png")
        XCTAssert(input != nil)
        if input == nil {
            return
        }
        XCTAssert(input != nil)

        var ans = net!.forward(input!)
        // HACK: find the answer
        for i in 1...5 {
            let (idx, p) = argMax(ans)
            ans[idx] = 0
            print("\(i). \(net!.labels[idx]) - \(p)")
        }
        checkMetrics("data", L1: 8815415, err1: 6E-5, L2: 646363264, err2: 2E-4)
        checkMetrics("conv1_7x7_s2", L1: 26894028, err1: 5E-3, L2: 7389178368, err2: 1E-2)
        checkMetrics("pool1_3x3_s2", L1: 15706585, err1: 5E-3, L2: 5238782464, err2: 1E-2)
        checkMetrics("pool1_norm1", L1: 6763517, err1: 5E-3, L2: 470019456, err2: 1E-2)
        checkMetrics("conv2_3x3_reduce", L1: 4607045, err1: 5E-3, L2: 365177216, err2: 1E-2)
        checkMetrics("conv2_3x3", L1: 6190394, err1: 1E-2, L2: 651581568, err2: 1E-2)
        checkMetrics("conv2_norm2", L1: 4979390.500000, err1: 1E-2, L2: 350693696, err2: 1E-2)
        checkMetrics("pool2_3x3_s2", L1: 3983016, err1: 1E-2, L2: 300735104, err2: 1E-2)
        checkMetrics("inception_3a_1x1", L1: 1376699, err1: 1E-2, L2: 133712880, err2: 1E-2)
        checkMetrics("inception_3a_3x3_reduce", L1: 1716600.250000, err1: 1E-2, L2: 141276912, err2: 2E-2)
        checkMetrics("inception_3a_3x3", L1: 2320588.250000, err1: 2E-2, L2: 287686272, err2: 4E-2)
        checkMetrics("inception_3a_5x5_reduce", L1: 418858.343750, err1: 1E-2, L2: 37575728, err2: 1E-2)
        checkMetrics("inception_3a_5x5", L1: 697953.750000, err1: 1E-2, L2: 80932752, err2: 1E-2)
        checkMetrics("inception_3a_pool", L1: 8837156, err1: 1E-2, L2: 766142080, err2: 1E-2)
        checkMetrics("inception_3a_pool_proj", L1: 460720.125000, err1: 2E-2, L2: 39634208, err2: 4E-2)
        checkMetrics("inception_3a_output", L1: 4855965, err1: 1E-2, L2: 541964032, err2: 2E-2)
        checkMetrics("inception_3b_output", L1: 2070707.625000, err1: 2E-2, L2: 173486784, err2: 4E-2)
        checkMetrics("inception_4a_output", L1: 803036.125000, err1: 4E-2, L2: 76048768, err2: 4E-2)
        checkMetrics("inception_4b_output", L1: 1172061, err1: 4E-2, L2: 77093112, err2: 4E-2)
        checkMetrics("inception_4c_output", L1: 907352.500000, err1: 0.032, L2: 62197672, err2: 0.04)
        checkMetrics("inception_4d_output", L1: 464165.843750, err1: 0.045, L2: 27689768, err2: 0.07)

        /*print("Pool1_3x3_s2: ")
        var buf = Array<Float>(count: 56 * 56, repeatedValue: 0)
        net!.blobs["pool1_3x3_s2"]!.getBytes(&buf, bytesPerRow: 56 * 4, bytesPerImage: 56 * 56 * 4,
            fromRegion: MTLRegionMake2D(0, 0, 56, 56), mipmapLevel: 0, slice: 0)
        for j in 0...6 {
            for i in 0...16 {
