TensorFlow alexnet在华为Mate10上运行方法
我使用的caffe模型:https://github.com/BVLC/caffe/tree/ea455eb29393ebe6de9f14e88bfce9eae74edf6d/models/bvlc_alexnet
其中,需要下载deploy prototxt文件和caffmodel以供转换模型用。
首先将caffe模型转换为TensorFlow,参考:https://github.com/ethereon/caffe-tensorflow
但是将其生产pb模型参考了如下代码,见https://github.com/ethereon/caffe-tensorflow/issues/23
from googlenet import GoogleNet # the output python script of caffe2tensorflow
import tensorflow as tf
from freeze_graph import freeze_graph # tensorflow comes up with a tool allowing freeze graph x = tf.placeholder(tf.float32, shape=[1, 224, 224, 3])
y = tf.placeholder(tf.float32, shape=[1, 1000]) net = GoogleNet({'data': x})
sess = tf.InteractiveSession()
sess.run(tf.initialize_all_variables())
net.load('googlenet.npy', sess)
saver = tf.train.Saver()
saver.save(sess, 'chkpt', global_step=0, latest_filename='chkpt_state')
tf.train.write_graph(sess.graph.as_graph_def(), './', googlenet.pb', False) input_saver_def_path = ''
input_binary=True
input_checkpoint_path = 'chkpt-0'
input_graph_path = 'googlenet.pb'
output_graph_path = 'googlenet.pb'
output_node_names = 'prob'
restore_op_name = "save/restore_all"
filename_tensor_name = "save/Const:0"
clear_devices = True freeze_graph(input_graph_path, input_saver_def_path,
input_binary, input_checkpoint_path,
output_node_names, restore_op_name,
filename_tensor_name, output_graph_path,
clear_devices, "")
注意,input node name改变了,自己print graph就知道。
另外一个博客里 见 https://ndres.me/post/convert-caffe-to-tensorflow/ ,提到自己fork的caffe to TensorFlow可以生成pb,但是我自己尝试发现针对alexnet抛出了异常。因此就没有使用。
还有就是 https://www.cs.toronto.edu/~guerzhoy/tf_alexnet/ 里提到有现成的模型,原文如下:
AlexNet implementation + weights in TensorFlow
This is a quick and dirty AlexNet implementation in TensorFlow. You may also be interested in Davi Frossard's VGG16 code/weights.
- myalexnet_forward.py -- the implementation itself + testing code for versions of TensorFlow current in 2017 (Python 3).
- myalexnet_forward.py -- for older versions of TensorFlowm in Python 2(See this version for a variable rather than placeholder input; you probably want the myalexnet_forward.py version if you want to fine-tune the networks.)
- bvlc_alexnet.npy -- the weights; they need to be in the working directory
- caffe_classes.py -- the classes, in the same order as the outputs of the network
- poodle.png, laska.png, dog.png, dog2.png, quail227.JPEG -- test images (images should be 227x227x3)
Credits:
- The model and weights are from Caffe
- The weights were converted using caffe-tensorflow, and code was taken from there as well
但是我自己使用的时候发现会抛出异常,可能是因为我使用的TensorFlow 1.3版本问题。因此最后也没有使用。
其次,就是模型压缩,命令为:
~/tensorflow-master/transform_graph/tensorflow/tools/graph_transforms/transform_graph --in_graph=alexnet.pb --outputs="prob" --out_graph=quantized_alexnet.pb --transforms='quantize_weights'
最后,导入pb到andriod项目里,我参考了:http://blog.csdn.net/u014432647/article/details/74743332和https://github.com/ppplinday/alexnet-tensorflow-android-withoutfc67
注意我是自己bazel compile TensorFlow 1.0生成的arm64-v8a的inferance so和jar文件。
值得一提的是,在https://github.com/ppplinday/alexnet-tensorflow-android-withoutfc67里提到,其使用的模型在android红米机器上inference时间是0.713s,华为mate10上稍微快点,是0.6s。
贴下http://blog.csdn.net/u014432647/article/details/74743332 原文内容:
首先先说明一下这个alexnet是进过修改的网络,由于模型太大,我把alexnet的全连接层6和全连接7给删除了,测试手机是红米Note 4X,cpu是高通骁龙625。
分别放出测试代码的github
arm compute library:
https://github.com/ppplinday/alexnet-armcomputelibrary-android-withoutfc67
tensorflow:
https://github.com/ppplinday/alexnet-tensorflow-android-withoutfc67
测试结果为:
arm compute lilrary:0.422s
tensorflow:0.713s
arm compute library比tensorflow快了差不多百分之40。arm这个也是有一定的优化,但是现在还是有挺多bug,而且接口暂时只提供C++,可以等之后成熟了再使用。
大致过程记录在此,以备忘。
TensorFlow alexnet在华为Mate10上运行方法的更多相关文章
- TensorFlow分布式在Amazon AWS上运行
TensorFlow分布式在Amazon AWS上运行 Amazon AWS 提供采用 NVIDIA K8 GPU 的 P2.x 机器.为了能够使用,第一步还需要创建一个 Amazon AWS 账户, ...
- Android项目的targetSDK>=23,在低于Android6.0的部分测试机(类似华为)上运行时出现的系统权限问题
相信大家对Android6.0以上的动态权限已经有所了解,很多童鞋也已经跃跃欲试地将自己项目的targetSDK升级到了23及其以上,很不幸的是我也成为了其中一员,然而我还是图样图森破了,升级之后的问 ...
- Firefox上运行自动化测试脚本提示元素无法点击“WebDriverException: Message: Element is not clickable at point“解决方法
1. Firefox上运行脚本时提示“WebDriverException: Message: Element is not clickable at point (934.316650390625, ...
- Visual Studio写的项目在 IIS 服务器上运行的两种简单方法
首先需要PC上开启了IIS服务,相关方法网上很多,也很简单 第一种:直接在项目中操作 1.创建一个项目,然后右击选中项目,右击,单击属性,打开项目属性标签页面 如图,选择Web标签,在服务器栏目中选中 ...
- mac 上运行cassandra出现的java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostException: : : unknown error错误解决方法
mac 上运行cassandra出现的java.net.MalformedURLException: Local host name unknown: java.net.UnknownHostExce ...
- 在PC上运行安卓(Android)应用程序的4个方法
我有一部荣耀3C,一般放在宿舍(我随身携带的是一部诺基亚E63,小巧.稳定.待机时间长),在宿舍我就会用它在微信上看公众号里的文章,最近要考驾照也在上面用驾考宝典.最近想在实验室用这两个软件,但又懒得 ...
- 发布Qt Quick桌面应用程序的方法(使得planets在XP上运行)
发布Qt Quick桌面应用程序的方法 Qt是一款优秀的跨平台开发框架,它可以在桌面.移动平台以及嵌入式平台上运行.目前Qt 5介绍程序发布的文章帖子比较少.大家又非常想要知道如何发布Qt应用程序,于 ...
- pycharm上运行django服务器端、以及创建app方法
快来加入群[python爬虫交流群](群号570070796),发现精彩内容. 安装Django 下载Django包,解压缩. CMD 进入解压路径下. 执行:python setup.py in ...
- iOS开发手记 - iOS9.3 Xcode7打包ipa文件在其他越狱机器上运行的方法和一些问题
现在Xcode7可以用一个appleid就可以往手机上部署测试app,不再需要$99,这也是方便.但是要把app发给别人的手机上运行还是不行,除非别人的手机在你身边可以直接通过Xcode安装 关于怎么 ...
随机推荐
- 从Element.getElementsByTagName方法说起
一.getElementsByTagName方法: 我们先看几个解释:1)W3C:getElementsByTagName() 方法可返回带有指定标签名的对象的集合.没有说明返回值的具体类型.2)菜鸟 ...
- 梦想CAD控件COM接口光栅图处理
在CAD操作过程中,我们在设计绘图时,光栅图像也就是我们常说的图片,应用非常广泛,在CAD中可以直接插入光栅图像,并且可以对光栅图像进行裁剪.透明度调整等一些操作,在网页可以快速实现我们所需功能. 一 ...
- [Linux]正则表达式和grep使用【转载】
[Linux]正则表达式和grep使用 2018年12月05日 23:45:54 祥知道 阅读数 78 标签: 正则表达式grepLinuxegrep 更多 个人分类: Linux 所属专栏: Li ...
- Linux System
Linux System linux 是一个功能强大的操作系统,同时它是一个自由软件,是免费的.源代码开放的,编制它的目的是建立不受任何商品化软件版权制约的.全世界都能自由使用的UNIX兼容产品.各种 ...
- C++ string 是否以‘\0’结尾 讨论
转载https://blog.csdn.net/qq_31930499/article/details/80374310 之前在某篇文章中看到,C语言字符串是以’\0’结尾的,但是C++string类 ...
- 阿里云创建CentOS系统设置
1 首先设置你购买的云盘配置,例如cpu,内存,磁盘类型.容量,网络类型等 2.阿里云可以使用浏览器进行远程shell连接 首先需要输入远程密码,第一次连接的时候会提示 一定要牢记 输入密码后进入sh ...
- Java:冒泡排序 | 二分查找
2018-10-29 20:16:46 冒泡排序 例子(对数字排序): 假设有这样一组数字:32, 8, 128, 2, 64 现在对其进行冒泡排序(*表示下次比较的开始数字): 32>8? t ...
- buf.writeFloatBE()函数详解
buf.writeFloatBE(value, offset[, noAssert]) buf.writeFloatLE(value, offset[, noAssert]) value {Numbe ...
- Cmake的介绍和使用 Cmake实践
Cmake的介绍和使用 Cmake实践http://www.cppblog.com/Roger/archive/2011/11/17/160368.html
- swift bug 调试记(wsgi.input)
第一次指定纠删码策略,修改了一部分swift代码后,执行PUT object,就被一个bug拦住.产生bug代码段如下: try: with ChunkReadTimeout(self.client_ ...