BradLarson / AlexNet-Swift

An implementation of the standard AlexNet convolutional network in Swift for TensorFlow
37 stars 2 forks source link

Value of type 'AlexNet' has no member 'allDifferentiableVariables' #4

Open frederick-greenacademy opened 4 years ago

frederick-greenacademy commented 4 years ago

Swift: 5.0.1 - Xcode: 11.3.1 Toolchain: Swift for Tensorflow 0.9

`for epochNumber in 0..<100 { let shuffledDataset = trainingImageDataset.combinedDataset.shuffled(sampleCount: 60, randomSeed: Int64(epochNumber)).batched(60) for datasetItem in shuffledDataset { let (currentLoss, gradients) = valueWithGradient(at: alexNet) { model -> Tensor in return loss(model: model, images: datasetItem.first, labels: datasetItem.second) }

    optimizer.update(&alexNet.allDifferentiableVariables, along: gradients)

    let currentTrainingAccuracy = accuracy(model: alexNet, images: trainingImageDataset.imageData, labels: trainingImageDataset.imageLabels)

    if ((epochNumber % validationInterval) == 0) {
        let currentValidationAccuracy = accuracy(model: alexNet, images: validationImageDataset.imageData, labels: validationImageDataset.imageLabels)
        print("\(epochNumber), \(currentLoss), \(currentTrainingAccuracy), \(currentValidationAccuracy)")
    } else {
        print("\(epochNumber), \(currentLoss), \(currentTrainingAccuracy)")
    }
}

} let endTime = -startTime.timeIntervalSinceNow`

BradLarson commented 4 years ago

Yeah, I haven't updated the syntax in this example for a while. Think the last toolchain I had this building with was 0.4.

I'll also need to modernize this for current use of image loading / saving, checkpoint restoration, and other things we've added since I last looked in on this. Thanks for the reminder, though.