我正在从不推荐使用的迁移我的神经网络:
init(device: MTLDevice, convolutionDescriptor: MPSCNNConvolutionDescriptor, kernelWeights: UnsafePointer<Float>, biasTerms: UnsafePointer<Float>?, flags: MPSCNNConvolutionFlags)
至
init(device: MTLDevice, weights: MPSCNNConvolutionDataSource)
我已经实现了一个MPSCNNConvolutionDataSource
经过良好调试的并且适用于我的所有层,除了一个。仅出于测试目的,我在这里自己调用数据源函数以及不推荐使用的 init() ,MPSCNNFullyConnected
以确保正确实现数据源。我知道这不是它的预期用途,但我希望相同的数据进入两个 MPSCNNFullyConnected() 构造函数。以下代码运行,NN 正常工作。
/* This code runs as intended */
let datasource = DataSource("test", 8, 8, 224, 1024, .reLU)
_ = datasource.load()
let layer = MPSCNNFullyConnected(device: device,
convolutionDescriptor: datasource.descriptor(),
kernelWeights: UnsafeMutablePointer<Float>(mutating: datasource.weights().assumingMemoryBound(to: Float.self)),
biasTerms: datasource.biasTerms(),
flags: .none)
当我用新的 init() 实例化全连接层时,网络会失败。以下代码运行但 NN 无法正常工作。
/* This code does run, but the layer does NOT output the correct values */
let datasource = DataSource("test", 8, 8, 224, 1024, .reLU)
let layer = MPSCNNFullyConnected(device: device, weights: datasource)
有什么建议为什么两个电话不相同?