-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from qoncept/swift-3
Update for Swift 3
- Loading branch information
Showing
55 changed files
with
1,232 additions
and
1,329 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,7 @@ | ||
import Foundation | ||
|
||
extension String { | ||
public func stringByAppendingPathComponent(str: String) -> String { | ||
return (self as NSString).stringByAppendingPathComponent(str) | ||
public func stringByAppendingPathComponent(_ str: String) -> String { | ||
return (self as NSString).appendingPathComponent(str) | ||
} | ||
} | ||
} |
This file contains 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 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 was deleted.
Oops, something went wrong.
This file contains 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,32 @@ | ||
import XCTest | ||
import TensorSwift | ||
@testable import MNIST | ||
|
||
class ClassifierTests: XCTestCase { | ||
func testClassify() { | ||
|
||
let classifier = Classifier(path: Bundle(for: ViewController.self).resourcePath!) | ||
let (images, labels) = downloadTestData() | ||
|
||
let count = 1000 | ||
|
||
let xArray: [[Float]] = images.withUnsafeBytes { ptr in | ||
[UInt8](UnsafeBufferPointer(start: UnsafePointer<UInt8>(ptr + 16), count: 28 * 28 * count)) | ||
.map { Float($0) / 255.0 } | ||
.grouped(28 * 28) | ||
} | ||
|
||
let yArray: [Int] = labels.withUnsafeBytes { ptr in | ||
[UInt8](UnsafeBufferPointer(start: UnsafePointer<UInt8>(ptr + 8), count: count)) | ||
.map { Int($0) } | ||
} | ||
|
||
let accuracy = Float(zip(xArray, yArray) | ||
.reduce(0) { $0 + (classifier.classify(Tensor(shape: [28, 28, 1], elements: $1.0)) == $1.1 ? 1 : 0) }) | ||
/ Float(yArray.count) | ||
|
||
print("accuracy: \(accuracy)") | ||
|
||
XCTAssertGreaterThan(accuracy, 0.97) | ||
} | ||
} |
Oops, something went wrong.