Saving/Loading network doesn’t work properly
AlbanPerli opened this issue · 1 comments
AlbanPerli commented
Hi @collinhundley,
the network is not saved properly, so it’s not loaded properly.
The costKey is not filled,
public func save(to url: URL) throws {
let json: [String : Any] = [
NeuralNet.inputsKey : structure.inputs,
NeuralNet.hiddenKey : structure.hidden,
NeuralNet.outputsKey : structure.outputs,
NeuralNet.momentumKey : momentumFactor,
NeuralNet.learningKey : learningRate,
NeuralNet.hiddenActivationKey : hiddenActivation.stringValue(),
NeuralNet.outputActivationKey : outputActivation.stringValue(),
NeuralNet.weightsKey : allWeights(),
]
// ...
}
but it’s mandatory in the init function
guard let inputs = array[NeuralNet.inputsKey] as? Int,
let hidden = array[NeuralNet.hiddenKey] as? Int,
let outputs = array[NeuralNet.outputsKey] as? Int,
let momentum = array[NeuralNet.momentumKey] as? Float,
let lr = array[NeuralNet.learningKey] as? Float,
let hiddenActivationStr = array[NeuralNet.hiddenActivationKey] as? String,
let outputActivationStr = array[NeuralNet.outputActivationKey] as? String,
let costStr = array[NeuralNet.costKey] as? String,
let weights = array[NeuralNet.weightsKey] as? [Float]
else {
throw Error.initialization("One or more required NeuralNet properties are missing.")
}
Fixed by adding:
NeuralNet.costKey : costFunction.stringValue()
in the saved json array.
Thx for the good work!
Alban
collinhundley commented
Fixed by #2