2023-10-23 12:28:35 +02:00
|
|
|
import ArgumentParser
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
@main
|
|
|
|
struct CapTrain: AsyncParsableCommand {
|
|
|
|
|
|
|
|
@Argument(help: "The path to the configuration file")
|
2023-10-23 14:58:58 +02:00
|
|
|
var configPath: String?
|
|
|
|
|
|
|
|
@Option(name: .shortAndLong, help: "The number of iterations to train")
|
|
|
|
var iterations: Int?
|
|
|
|
|
|
|
|
@Option(name: .shortAndLong, help: "The url of the caps server")
|
|
|
|
var serverPath: String?
|
|
|
|
|
|
|
|
@Option(name: .shortAndLong, help: "The authentication token for the server")
|
|
|
|
var authentication: String?
|
|
|
|
|
|
|
|
@Option(name: .shortAndLong, help: "The folder where the content (images, classifier, thumbnails) is stored")
|
|
|
|
var folder: String?
|
2023-10-23 12:28:35 +02:00
|
|
|
|
|
|
|
func run() async throws {
|
2023-10-23 14:58:58 +02:00
|
|
|
let configurationFile = try configurationFile()
|
|
|
|
guard let contentFolder = folder ?? configurationFile?.contentFolder,
|
|
|
|
let trainingIterations = iterations ?? configurationFile?.trainingIterations,
|
|
|
|
let serverPath = serverPath ?? configurationFile?.serverPath,
|
|
|
|
let authenticationToken = authentication ?? configurationFile?.authenticationToken
|
|
|
|
else {
|
|
|
|
throw TrainingError.missingArguments
|
|
|
|
}
|
|
|
|
|
|
|
|
let configuration = Configuration(
|
|
|
|
contentFolder: contentFolder,
|
|
|
|
trainingIterations: trainingIterations,
|
|
|
|
serverPath: serverPath,
|
|
|
|
authenticationToken: authenticationToken)
|
2023-10-23 12:28:35 +02:00
|
|
|
|
2023-10-23 14:58:58 +02:00
|
|
|
let creator = try ClassifierCreator(configuration: configuration)
|
2023-10-23 12:28:35 +02:00
|
|
|
try await creator.run()
|
|
|
|
}
|
2023-10-23 14:58:58 +02:00
|
|
|
|
|
|
|
private func configurationFile() throws -> ConfigurationFile? {
|
|
|
|
guard let configPath else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
let configurationFileUrl = URL(fileURLWithPath: configPath)
|
|
|
|
return try ConfigurationFile(at: configurationFileUrl)
|
|
|
|
}
|
2023-10-23 12:28:35 +02:00
|
|
|
}
|