机器人与人工智能爱好者论坛

 找回密码
 立即注册
查看: 11071|回复: 1
打印 上一主题 下一主题

Facebook和微软发布机器学习工具ONNX,PyTorch训练的模型轻松转到Caffe2

[复制链接]

292

主题

321

帖子

6124

积分

版主

Rank: 7Rank: 7Rank: 7

积分
6124
跳转到指定楼层
楼主
发表于 2017-9-9 11:25:15 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

Facebook和微软发布机器学习工具ONNX,PyTorch训练的模型轻松转到Caffe2


2017年09月08日



Facebook和微软周四在各自的博客中发布了ONNX,即“开放神经网络转换”工具。

简单地说,这个新工具能把一种框架训练的模型,转换成另一种框架所需的格式。比如说,机器学习开发者可以将PyTorch训练的模型转换到Caffe2上,减少从研究到产品化所耗费的时间。

Facebook在博客中说,ONNX只是第一步,他们的目标是建立一个开放的生态,让AI开发者能在最先进的工具之间轻松流动,选择最适合自己的框架。

在Facebook内部,研究和产品应用之间就有着很明显的区隔,这家公司一直有两个机器学习团队:FAIR(人工智能研究院)和AML(应用机器学习),FAIR专注于前沿性研究,而AML则关注如何将人工智能产品化。

深度学习框架的选择是造成这种区别的关键。FAIR习惯于使用PyTorch。这种深度学习框架可以不考虑资源限制,在研究中取得漂亮的结果。

然而在现实世界中,大部分人都受限于智能手机和计算机的计算能力。当AML希望开发可以部署、可以规模化的产品时,通常会选择Caffe2。Caffe2也是一种深度学习框架,但针对资源效率进行了优化。尤其是Caffe2Go特别关注了在性能不足的移动设备上优化机器学习模型。

Facebook和微软的合作帮助研究者方便地将用PyTorch开发的模型转换为Caffe2模型。通过降低两种框架之间切换的障碍,Facebook和微软可以推动研究的普及,加速整个商业化进程。

在这个月过完之前,微软的CNTK、Facebook的Caffe2和PyTorch都将支持ONNX。



但距离“开放生态”的愿景,ONNX还有很远的路要走。并不是所有公司都在用PyTorch、Caffe2和CNTK,现在使用人数最多的框架,依然是Google的TensorFlow,而亚马逊收编的MXNet、老牌的Theano、百度的paddle等等都各有一批用户。

也正因为机器学习框架这么多,功能大同小异,才让ONNX这样的工具有用武之地。

大部分机器学习框架的功能,都是让开发者能更容易地建立、运行神经网络的计算图,而这些框架之间的核心区别,就在于它们用各不相同的格式来表示这些计算图。

ONNX提供一种共享的模型表示,提升了AI框架之间的互操作性。



在科研范畴之外,其他人也在试图将机器学习模型更方便地转换为针对特定设备优化的形式。

例如,苹果的CoreML就可以帮助开发者转换某些类型的模型。目前,CoreML还不支持TensorFlow,而且创建自定义转换器的过程很复杂,转换器最后有可能无法使用。

随着谷歌和苹果等公司加大对定制硬件上机器学习框架的优化,继续关注互操作性非常重要。

目前,ONNX已经在Github上发布,地址:https://github.com/onnx/onnx



回复

使用道具 举报

292

主题

321

帖子

6124

积分

版主

Rank: 7Rank: 7Rank: 7

积分
6124
沙发
 楼主| 发表于 2017-9-9 11:26:28 | 只看该作者
Open Neural Network Exchange (ONNX)
Open Neural Network Exchange (ONNX) is the first step toward an open ecosystem that empowers AI developers to choose the right tools as their project evolves. ONNX provides an open source format for AI models. It defines an extensible computation graph model, as well as definitions of built-in operators and standard data types. Initially we focus on the capabilities needed for inferencing (evaluation).
Caffe2, PyTorch, and Cognitive Toolkit will be supporting ONNX. Enabling interoperability between different frameworks and streamlining the path from research to production will increase the speed of innovation in the AI community. We are an early stage and we invite the community to submit feedback and help us further evolve ONNX.
Folder Structure
  • onnx/: the main folder that all code lies under
    • onnx.proto: the protobuf (v2.6.1) that contains all the structures
    • checker.py: utility to check whether a serialized ONNX proto is legal.
    • defs/: subfolder that defines the ONNX operators.
    • test/: test files

InstallationBinaries
A binary build of ONNX is available from Conda:
conda install -c ezyang onnxDocker
A docker image with ONNX, PyTorch, and Caffe2 is availiable for quickly trying tutorials that use ONNX. Simply run:
docker run -i -t houseroad/onnx-docker /bin/bash
Currently the image only supports CPU computation with GPU support coming soon.
Source
You will need an install of protobuf and numpy to build ONNX. One easy way to get these dependencies is via Anaconda:
# Use conda-forge protobuf, as defaults doesn't come with protocconda install -c conda-forge protobuf numpy
You can then install ONNX from PyPi:
pip install onnx
After installation, run
python -c 'import onnx'
to verify it works. Note that this command does not work from a source checkout directory; in this case you'll see:
ModuleNotFoundError: No module named 'onnx.onnx_cpp2py_export'
Change into another directory to fix this error.
Testing
ONNX uses pytest as test driver. In order to run tests, first you need to install pytest:
pip install pytest-cov
After installing pytest, do
pytest
to run tests.
Development
During development it's convenient to install ONNX in development mode:
git clone --recursive https://github.com/onnx/onnx.gitpip install -e onnx/
Then, after you have made changes to
  • Python files, the changes are immediately effective in your installation, you do not need to install again.
  • C++ files, you need to do install again to trigger the native extension build.
License

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|Archiver|手机版|小黑屋|陕ICP备15012670号-1    

GMT+8, 2024-5-16 06:09 , Processed in 0.058516 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表