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
public func prepareModel() { | |
let coremlModel = Model(version: 4, | |
shortDescription: "MNIST-Trainable", | |
author: "Jacopo Mangiavacchi", | |
license: "MIT", | |
userDefined: ["SwiftCoremltoolsVersion" : "0.0.12"]) { | |
Input(name: "image", shape: [1, 28, 28]) | |
Output(name: "output", shape: [10], featureType: .float) | |
TrainingInput(name: "image", shape: [1, 28, 28]) | |
TrainingInput(name: "output_true", shape: [1], featureType: .int) |
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
func prepareBatchProvider() -> MLBatchProvider { | |
var featureProviders = [MLFeatureProvider]() | |
var count = 0 | |
errno = 0 | |
let trainFilePath = Bundle.main.url(forResource: "mnist_train", withExtension: "csv")! | |
if freopen(trainFilePath.path, "r", stdin) == nil { | |
print("error opening file") | |
} | |
while let line = readLine()?.split(separator: ",") { |
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
import Foundation | |
struct OrderedDict<K: Hashable, V> { | |
var _dict = [K : V]() | |
var _ordered = [K]() | |
var keys: [K] { | |
_ordered | |
} | |
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
import Foundation | |
import CoreML | |
func generateData(sampleSize: Int = 100) -> ([Float], [Float]) { | |
let a: Float = 2.0 | |
let b: Float = 1.5 | |
var X = [Float]() | |
var Y = [Float]() |
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
import Foundation | |
import CoreML | |
func compileCoreML(path: String) -> (MLModel, URL) { | |
let modelUrl = URL(fileURLWithPath: path) | |
let compiledUrl = try! MLModel.compileModel(at: modelUrl) | |
print("Compiled Model Path: \(compiledUrl)") | |
return try! (MLModel(contentsOf: compiledUrl), compiledUrl) | |
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
import Foundation | |
import TensorFlow | |
import numsw | |
var tf = TensorFlow() | |
let a = tf.constant(NDArray<Float>(shape: [3], elements: [5, 7, 10])) | |
let b = tf.constant(NDArray<Float>(shape: [3], elements: [2, 3, 21])) | |
let c = tf.constant(NDArray<Float>(shape: [3], elements: [3, 5, 7])) |
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
let list = SwiftListWrapper(dataSize: 1) | |
list.push_back(value: "1".data(using: .utf8)!) | |
list.push_back(value: "2".data(using: .utf8)!) | |
list.push_back(value: "3".data(using: .utf8)!) | |
list.push_front(value: "0".data(using: .utf8)!) | |
XCTAssertEqual(list.size(), 4) | |
XCTAssertEqual(String.init(data: list.front()!, encoding: .utf8), "0") |
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
#include <list> | |
int main(int argc, const char * argv[]) { | |
std::list<void*> list; | |
list.push_back((void*)"1"); | |
list.push_back((void*)"2"); | |
list.push_back((void*)"3"); | |
list.push_front((void*)"0"); |
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
public final class SampleStruct { | |
public var key: Int32 | |
public var value: String | |
} | |
public protocol TestService { | |
func Hello(HelloString: String) throws -> String | |
func GetSampleStruct(key: Int32, value: String) throws -> SampleStruct | |
} |