0
亞馬遜有關於如何在iOS上使用他們的機器學習平臺的文檔,但沒有Swift實現,我無法將其翻譯成Swift。下面是Objective-C代碼:iOS亞馬遜機器學習Swift
// Use a created model that has a created real-time endpoint
NSString *MLModelId = @"example-model-id";
// Call GetMLModel to get the realtime endpoint URL
AWSMachineLearningGetMLModelInput *getMLModelInput = [AWSMachineLearningGetMLModelInput new];
getMLModelInput.MLModelId = MLModelId;
[[[MachineLearning getMLModel:getMLModelInput] continueWithSuccessBlock:^id(AWSTask *task) {
AWSMachineLearningGetMLModelOutput *getMLModelOutput = task.result;
// Validate that the ML model is completed
if (getMLModelOutput.status != AWSMachineLearningEntityStatusCompleted) {
NSLog(@"ML Model is not completed");
return nil;
}
// Validate that the realtime endpoint is ready
if (getMLModelOutput.endpointInfo.endpointStatus != AWSMachineLearningRealtimeEndpointStatusReady) {
NSLog(@"Realtime endpoint is not ready");
return nil;
}
}
AWSMachineLearningPredictInput *predictInput = [AWSMachineLearningPredictInput new];
predictInput.predictEndpoint = getMLModelOutput.endpointInfo.endpointUrl;
predictInput.MLModelId = MLModelId;
predictInput.record = @{};
// Call and return prediction
return [MachineLearning predict:predictInput];
這裏是我的嘗試SWIFT代碼
var getMLModelInput = AWSMachineLearningGetMLModelInput()
// Use a created model that has a created real-time endpoint
let MLModelId = "example-model-id"
// Call GetMLModel to get the realtime endpoint URL
getMLModelInput.MLModelId = MLModelId;
let task = AWSMachineLearning.getMLModel(getMLModelInput) // This line won't work because the method .getMLModel expects and instance of AWSMachineLearning
我是想用於上傳代碼後,我斯威夫特代碼模型到S3這樣的:
let transferManager = AWSS3TransferManager.defaultS3TransferManager()
let testFileURL1 = NSURL(fileURLWithPath: NSTemporaryDirectory()).URLByAppendingPathComponent("tmp")
let uploadRequest1 : AWSS3TransferManagerUploadRequest = AWSS3TransferManagerUploadRequest()
let data = userCSV.dataUsingEncoding(NSUTF8StringEncoding)
data!.writeToURL(testFileURL1, atomically: true)
uploadRequest1.bucket = "users/1"
uploadRequest1.key = "tmpkey.csv"
uploadRequest1.body = testFileURL1
let task = transferManager.upload(uploadRequest1)
task.continueWithBlock { (task) -> AnyObject! in
if task.error != nil {
print("Error: \(task.error)")
} else {
print("Upload successful")
}
return nil
}
但我不知道如何構建機器學習模型的任務對象。任何幫助將非常感激!