This repository was archived by the owner on Apr 23, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 150
Adding shape-based inference tests for all image classification models #198
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4ffd92e
Implemented inference tests with random tensors and starting weights …
BradLarson 1f81754
Made sure tests ran on Linux, reshaped output of SqueezeNet to match …
BradLarson da0605f
WideResNet is expressed in terms of CIFAR10, so altered the inputs an…
BradLarson 3fb1703
Wrapping the reshaping line in SqueezeNet.
BradLarson eec5585
Reset ownership.
BradLarson 2ff6e37
Reworked TensorShape initializers to use array literals.
BradLarson 09ec265
Minor formatting tweak to SqueezeNet.
BradLarson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| // Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import TensorFlow | ||
| import XCTest | ||
|
|
||
| @testable import ImageClassificationModels | ||
|
|
||
| final class ImageClassificationInferenceTests: XCTestCase { | ||
| override class func setUp() { | ||
| Context.local.learningPhase = .inference | ||
| } | ||
|
|
||
| func testLeNet() { | ||
| let leNet = LeNet() | ||
| let input = Tensor<Float>( | ||
| randomNormal: TensorShape(1, 28, 28, 1), mean: Tensor<Float>(0.5), | ||
| standardDeviation: Tensor<Float>(0.1), seed: (0xffeffe, 0xfffe)) | ||
| let result = leNet(input) | ||
| XCTAssertEqual(result.shape, TensorShape(1, 10)) | ||
| } | ||
|
|
||
| func testResNet() { | ||
| let inputCIFAR = Tensor<Float>( | ||
| randomNormal: TensorShape(1, 32, 32, 3), mean: Tensor<Float>(0.5), | ||
| standardDeviation: Tensor<Float>(0.1), seed: (0xffeffe, 0xfffe)) | ||
| let resNet18CIFAR = ResNetBasic(inputKind: .resNet18, dataKind: .cifar) | ||
| let resNet18CIFARResult = resNet18CIFAR(inputCIFAR) | ||
| XCTAssertEqual(resNet18CIFARResult.shape, TensorShape(1, 10)) | ||
|
BradLarson marked this conversation as resolved.
Outdated
|
||
|
|
||
| let resNet34CIFAR = ResNetBasic(inputKind: .resNet34, dataKind: .cifar) | ||
| let resNet34CIFARResult = resNet34CIFAR(inputCIFAR) | ||
| XCTAssertEqual(resNet34CIFARResult.shape, TensorShape(1, 10)) | ||
|
|
||
| let resNet50CIFAR = ResNet(inputKind: .resNet50, dataKind: .cifar) | ||
| let resNet50CIFARResult = resNet50CIFAR(inputCIFAR) | ||
| XCTAssertEqual(resNet50CIFARResult.shape, TensorShape(1, 10)) | ||
|
|
||
| let resNet101CIFAR = ResNet(inputKind: .resNet101, dataKind: .cifar) | ||
| let resNet101CIFARResult = resNet101CIFAR(inputCIFAR) | ||
| XCTAssertEqual(resNet101CIFARResult.shape, TensorShape(1, 10)) | ||
|
|
||
| let resNet152CIFAR = ResNet(inputKind: .resNet152, dataKind: .cifar) | ||
| let resNet152CIFARResult = resNet152CIFAR(inputCIFAR) | ||
| XCTAssertEqual(resNet152CIFARResult.shape, TensorShape(1, 10)) | ||
|
|
||
| let inputImageNet = Tensor<Float>( | ||
| randomNormal: TensorShape(1, 224, 224, 3), mean: Tensor<Float>(0.5), | ||
| standardDeviation: Tensor<Float>(0.1), seed: (0xffeffe, 0xfffe)) | ||
| let resNet18ImageNet = ResNetBasic(inputKind: .resNet18, dataKind: .imagenet) | ||
| let resNet18ImageNetResult = resNet18ImageNet(inputImageNet) | ||
| XCTAssertEqual(resNet18ImageNetResult.shape, TensorShape(1, 1000)) | ||
|
|
||
| let resNet34ImageNet = ResNetBasic(inputKind: .resNet34, dataKind: .imagenet) | ||
| let resNet34ImageNetResult = resNet34ImageNet(inputImageNet) | ||
| XCTAssertEqual(resNet34ImageNetResult.shape, TensorShape(1, 1000)) | ||
|
|
||
| let resNet50ImageNet = ResNet(inputKind: .resNet50, dataKind: .imagenet) | ||
| let resNet50ImageNetResult = resNet50ImageNet(inputImageNet) | ||
| XCTAssertEqual(resNet50ImageNetResult.shape, TensorShape(1, 1000)) | ||
|
|
||
| let resNet101ImageNet = ResNet(inputKind: .resNet101, dataKind: .imagenet) | ||
| let resNet101ImageNetResult = resNet101ImageNet(inputImageNet) | ||
| XCTAssertEqual(resNet101ImageNetResult.shape, TensorShape(1, 1000)) | ||
|
|
||
| let resNet152ImageNet = ResNet(inputKind: .resNet152, dataKind: .imagenet) | ||
| let resNet152ImageNetResult = resNet152ImageNet(inputImageNet) | ||
| XCTAssertEqual(resNet152ImageNetResult.shape, TensorShape(1, 1000)) | ||
| } | ||
|
|
||
| func testResNetV2() { | ||
| let input = Tensor<Float>( | ||
| randomNormal: TensorShape(1, 224, 224, 3), mean: Tensor<Float>(0.5), | ||
| standardDeviation: Tensor<Float>(0.1), seed: (0xffeffe, 0xfffe)) | ||
| let resNet18ImageNet = PreActivatedResNet18(imageSize: 224, classCount: 1000) | ||
| let resNet18ImageNetResult = resNet18ImageNet(input) | ||
| XCTAssertEqual(resNet18ImageNetResult.shape, TensorShape(1, 1000)) | ||
|
|
||
| let resNet34ImageNet = PreActivatedResNet34(imageSize: 224, classCount: 1000) | ||
| let resNet34ImageNetResult = resNet34ImageNet(input) | ||
| XCTAssertEqual(resNet34ImageNetResult.shape, TensorShape(1, 1000)) | ||
| } | ||
|
|
||
| func testSqueezeNet() { | ||
| let input = Tensor<Float>( | ||
| randomNormal: TensorShape(1, 224, 224, 3), mean: Tensor<Float>(0.5), | ||
| standardDeviation: Tensor<Float>(0.1), seed: (0xffeffe, 0xfffe)) | ||
| let squeezeNet = SqueezeNet(classCount: 1000) | ||
| let squeezeNetResult = squeezeNet(input) | ||
| XCTAssertEqual(squeezeNetResult.shape, TensorShape(1, 1000)) | ||
| } | ||
|
|
||
| func testWideResNet() { | ||
| let input = Tensor<Float>( | ||
| randomNormal: TensorShape(1, 32, 32, 3), mean: Tensor<Float>(0.5), | ||
| standardDeviation: Tensor<Float>(0.1), seed: (0xffeffe, 0xfffe)) | ||
| let wideResNet16 = WideResNet(kind: .wideResNet16) | ||
| let wideResNet16Result = wideResNet16(input) | ||
| XCTAssertEqual(wideResNet16Result.shape, TensorShape(1, 10)) | ||
|
|
||
| let wideResNet16k10 = WideResNet(kind: .wideResNet16k10) | ||
| let wideResNet16k10Result = wideResNet16k10(input) | ||
| XCTAssertEqual(wideResNet16k10Result.shape, TensorShape(1, 10)) | ||
|
|
||
| let wideResNet22 = WideResNet(kind: .wideResNet22) | ||
| let wideResNet22Result = wideResNet22(input) | ||
| XCTAssertEqual(wideResNet22Result.shape, TensorShape(1, 10)) | ||
|
|
||
| let wideResNet22k10 = WideResNet(kind: .wideResNet22k10) | ||
| let wideResNet22k10Result = wideResNet22k10(input) | ||
| XCTAssertEqual(wideResNet22k10Result.shape, TensorShape(1, 10)) | ||
|
|
||
| let wideResNet28 = WideResNet(kind: .wideResNet28) | ||
| let wideResNet28Result = wideResNet28(input) | ||
| XCTAssertEqual(wideResNet28Result.shape, TensorShape(1, 10)) | ||
|
|
||
| let wideResNet28k12 = WideResNet(kind: .wideResNet28k12) | ||
| let wideResNet28k12Result = wideResNet28k12(input) | ||
| XCTAssertEqual(wideResNet28k12Result.shape, TensorShape(1, 10)) | ||
|
|
||
| let wideResNet40k1 = WideResNet(kind: .wideResNet40k1) | ||
| let wideResNet40k1Result = wideResNet40k1(input) | ||
| XCTAssertEqual(wideResNet40k1Result.shape, TensorShape(1, 10)) | ||
|
|
||
| let wideResNet40k2 = WideResNet(kind: .wideResNet40k2) | ||
| let wideResNet40k2Result = wideResNet40k2(input) | ||
| XCTAssertEqual(wideResNet40k2Result.shape, TensorShape(1, 10)) | ||
|
|
||
| let wideResNet40k4 = WideResNet(kind: .wideResNet40k4) | ||
| let wideResNet40k4Result = wideResNet40k4(input) | ||
| XCTAssertEqual(wideResNet40k4Result.shape, TensorShape(1, 10)) | ||
|
|
||
| let wideResNet40k8 = WideResNet(kind: .wideResNet40k8) | ||
| let wideResNet40k8Result = wideResNet40k8(input) | ||
| XCTAssertEqual(wideResNet40k8Result.shape, TensorShape(1, 10)) | ||
| } | ||
| } | ||
|
|
||
| extension ImageClassificationInferenceTests { | ||
| static var allTests = [ | ||
| ("testLeNet", testLeNet), | ||
| ("testResNet", testResNet), | ||
| ("testResNetV2", testResNetV2), | ||
| ("testSqueezeNet", testSqueezeNet), | ||
| ("testWideResNet", testWideResNet), | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| import XCTest | ||
|
|
||
| #if !os(macOS) | ||
| public func allTests() -> [XCTestCaseEntry] { | ||
| return [ | ||
| testCase(ImageClassificationInferenceTests.allTests), | ||
| ] | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| import XCTest | ||
|
|
||
| import ImageClassificationTests | ||
| import MiniGoTests | ||
|
|
||
| var tests = [XCTestCaseEntry]() | ||
| tests += ImageClassificationTests.allTests() | ||
| tests += MiniGoTests.allTests() | ||
| XCTMain(tests) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.