ios - MPSCNN Weight Ordering -


the metal performance shader framework provides support building own convolutional neural nets. when creating instance mspcnnconvolution requires 4d weight tensor init parameter represented 1d float pointer.

init(device: mtldevice,   convolutiondescriptor: mpscnnconvolutiondescriptor,   kernelweights: unsafepointer<float>,   biasterms: unsafepointer<float>?,   flags: mpscnnconvolutionflags) 

the documentation has 4d tensor

the layout of filter weight arranged can reinterpreted 4d tensor (array) weight[outputchannels][kernelheight][kernelwidth][inputchannels/groups]

unfortunately information doesn't tell me how arrange 4d array 1 dimensional float pointer.

i tried ordering weights bnns counterpart requires it, without luck.

how represent 4d tensor (array) 1d float pointer (array)?

ps: tried arranging c array , getting pointer flat array, didn't work.

update

@rhythmicfistman: that's how stored in plain array, can convert usafepointer<float> (but doesn't work):

var output = array<float>(repeating: 0, count: weights.count)  o in 0..<outputchannels {     ky in 0..<kernelheight {         kx in 0..<kernelwidth {             in 0..<inputchannels {                 let offset = ((o * kernelheight + ky) * kernelwidth + kx) * inputchannels +                 output[offset] = ...             }         }     } } 

ok figured out. here 2 python functions use reform convolutions , connected matrices

# shape required mpscnn [oc kh kw ic] # tensorflow order [kh kw ic oc] def convshape(a):     = np.swapaxes(a, 2, 3)     = np.swapaxes(a, 1, 2)     = np.swapaxes(a, 0, 1)     return  # connected requires x/y swap def fullshape(a):     = np.swapaxes(a, 0, 1)     return 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -