专栏名称: 机器学习研究会
机器学习研究会是北京大学大数据与机器学习创新中心旗下的学生组织,旨在构建一个机器学习从事者交流的平台。除了及时分享领域资讯外,协会还会举办各种业界巨头/学术神牛讲座、学术大牛沙龙分享会、real data 创新竞赛等活动。
目录
相关文章推荐
51好读  ›  专栏  ›  机器学习研究会

【推荐】用IOS 10 MPS框架实现支持GPU的快速CNN计算

机器学习研究会  · 公众号  · AI  · 2017-04-25 18:55

正文

请到「今天看啥」查看全文




点击上方 “机器学习研究会” 可以订阅哦
摘要

转自:爱可可-爱生活

At Athelas, we use Convolutional Neural Networks(CNNs) for a lot more than just classification! In this post, we’ll see how CNNs can be used, with great results, in image instance segmentation.

n iOS 10, API to implement and run Convolutional Neural Network (CNN) on iOS devices have been added to the MetalPerformanceShaders (MPS) framework. We can now take advantage of GPU on iOS devices to run fast CNN computation . In other word, we can use outcome of cutting edge deep learning technologies on your device even while offline.

Apple provides samples for the MPSCNN (MPSCNNHelloWorld / MetalImageRecognition), and I integrated it into my sample code collection repo: https://github.com/shu223/iOS-10-Sampler


Realtime Image Recognition using MPSCNN


In these sample apps, pre-trained model parameters (weight / bias) are used in the app, and those files are named xxxx.dat .


What kind of file is this? Is this something special by Apple? Can MPS CNN use only this format? What format is the content?


In this article, I write about the model format of MPS CNN.


File format

The `xxxx.dat` files which are included in samples such as Apple’s MPSCNNHelloWorld or MetalImageRecognition are ordinary binary files . Thus those are NOT MPSCNN or Apple proprietary / exclusive.

This file can be loaded to memory without any dependencies on Metal or MetalPerformanceShaders as follows:

let fd = open( filePath, O_RDONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
assert(fd != -1, “Error: failed to open output file at \””+filePath+”\” errno = \(errno)\n”)
guard let hdr = mmap(nil, size, PROT_READ, MAP_FILE | MAP_SHARED, fd, 0) else {
close(fd)
return nil
}

Then, to use this with MPSCNN, Casting UnsafeMutableRawPointer to UnsafePointer ,

let p = UnsafePointer(hdr.assumingMemoryBound(to: Float.self))
assert(p != UnsafePointer(bitPattern: -1), “mmap failed with errno = \(errno)”)

and pass this pointer to the initializer of MPSCNNConvolution or MPSCNNFullyConnected.

public init(device: MTLDevice, convolutionDescriptor: MPSCNNConvolutionDescriptor, kernelWeights: UnsafePointer, biasTerms: UnsafePointer?, flags: MPSCNNConvolutionFlags)

MPSCNNConvolution or MPSCNNFullyConnected copies the parameters when it’s initialized, so you can release the data loaded on memory and close the file.

munmap(hdr, Int(size))
close(fd)

These are also independent of Metal or MetalPerformanceShaders, very generic methods for files or memory.


In conclusion, any file format can be used , as far as it can be read by the iOS app.


链接:

https://medium.com/@shu223/model-format-of-mpscnn-on-ios-metal-performance-shaders-94b653a3dcc8


github链接:

https://github.com/shu223/iOS-10-Sampler


原文链接:

http://m.weibo.cn/1402400261/4099626824419715

“完整内容”请点击【阅读原文】
↓↓↓






请到「今天看啥」查看全文