Allow skipping of training

This commit is contained in:
Christoph Hagen 2024-06-12 16:13:42 +02:00
parent 796c18c7e0
commit 58b1dcb277
2 changed files with 9 additions and 4 deletions

View File

@ -23,6 +23,9 @@ struct CapTrain: AsyncParsableCommand {
@Option(name: .shortAndLong, help: "The path to the folder where the content (images, classifier, thumbnails) is stored") @Option(name: .shortAndLong, help: "The path to the folder where the content (images, classifier, thumbnails) is stored")
var folder: String? var folder: String?
@Flag(name: .long, help: "Only upload the previous classifier")
var skipTraining: Bool = false
func run() async throws { func run() async throws {
let configurationFile = try configurationFile() let configurationFile = try configurationFile()
@ -36,7 +39,6 @@ struct CapTrain: AsyncParsableCommand {
guard let authentication = authentication ?? configurationFile?.authentication else { guard let authentication = authentication ?? configurationFile?.authentication else {
throw TrainingError.missingArguments("authentication") throw TrainingError.missingArguments("authentication")
} }
let configuration = Configuration( let configuration = Configuration(
contentFolder: contentFolder, contentFolder: contentFolder,
trainingIterations: iterations, trainingIterations: iterations,
@ -44,7 +46,7 @@ struct CapTrain: AsyncParsableCommand {
authenticationToken: authentication) authenticationToken: authentication)
let creator = try ClassifierCreator(configuration: configuration, resume: resume) let creator = try ClassifierCreator(configuration: configuration, resume: resume)
try await creator.run() try await creator.run(skipTraining: skipTraining)
} }
private func configurationFile() throws -> ConfigurationFile? { private func configurationFile() throws -> ConfigurationFile? {

View File

@ -59,7 +59,7 @@ final class ClassifierCreator {
// MARK: Main function // MARK: Main function
func run() async throws { func run(skipTraining: Bool) async throws {
let imagesSnapshotDate = Date() let imagesSnapshotDate = Date()
let (classes, changedImageCount, changedMainImages) = try await loadImages() let (classes, changedImageCount, changedMainImages) = try await loadImages()
@ -78,13 +78,16 @@ final class ClassifierCreator {
let classifierVersion = try await getClassifierVersion() let classifierVersion = try await getClassifierVersion()
let newVersion = classifierVersion + 1 let newVersion = classifierVersion + 1
print(info: "Server: \(server.path)")
print(info: "Image directory: \(imageDirectory.absoluteURL.path)") print(info: "Image directory: \(imageDirectory.absoluteURL.path)")
print(info: "Model path: \(classifierUrl.path)") print(info: "Model path: \(classifierUrl.path)")
print(info: "Version: \(newVersion)") print(info: "Version: \(newVersion)")
print(info: "Classes: \(classes.count)") print(info: "Classes: \(classes.count)")
print(info: "Iterations: \(configuration.trainingIterations)") print(info: "Iterations: \(configuration.trainingIterations)")
try await trainAndSaveModel() if !skipTraining {
try await trainAndSaveModel()
}
try await uploadModel(version: newVersion) try await uploadModel(version: newVersion)
try await upload(classes: classes, lastUpdate: imagesSnapshotDate) try await upload(classes: classes, lastUpdate: imagesSnapshotDate)
try await createThumbnails(changed: changedMainImages) try await createThumbnails(changed: changedMainImages)