我使用的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 = Truefreeze_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++,可以等之后成熟了再使用。

大致过程记录在此,以备忘。

转载于:https://www.cnblogs.com/bonelee/p/8492525.html

TensorFlow alexnet在华为Mate10上运行方法相关推荐

  1. 【转载】logcat在华为手机上运行时无法抓取log的问题

    2019独角兽企业重金招聘Python工程师标准>>> logcat在华为手机上运行时,若一直提示请等待,无法抓取log,则很可能是系统没有打开log开关导致,操作方法如下: 1. ...

  2. Android项目的targetSDK=23,在低于Android6.0的部分测试机(类似华为)上运行时出现的系统权限问题...

    相信大家对Android6.0以上的动态权限已经有所了解,很多童鞋也已经跃跃欲试地将自己项目的targetSDK升级到了23及其以上,很不幸的是我也成为了其中一员,然而我还是图样图森破了,升级之后的问 ...

  3. 在Android 华为手机上运行React_Native工程时出现了如下错误,做以记录:

    报错:unable to load script from assets 'index.android bundle' ,make sure your bundle is packaged corre ...

  4. 【新手向】TensorFlow 安装教程:RK3399上运行谷歌人工智能

    从AlphaGo大胜李世石后,谷歌的人工智能备受关注.人工智能好像离我们好远,深度学习算法貌似非常复杂.但其实看看你的手机上的语音助手,相机上的人脸识别,今日头条上帮你自动筛选出来的新闻,还有各大音乐 ...

  5. TensorFlow 安装教程:RK3399上运行谷歌人工智能

    从AlphaGo大胜李世石后,谷歌的人工智能备受关注.人工智能好像离我们好远,深度学习算法貌似非常复杂.但其实看看你的手机上的语音助手,相机上的人脸识别,今日头条上帮你自动筛选出来的新闻,还有各大音乐 ...

  6. AlexNet原文解读+colab上运行caffe+caffe神经网络可视化(没有完成)

    ##########################下面是资源############################################################## 论文原文链接 ...

  7. 华为Android10版怎么截屏,华为Mate10怎么截屏?华为Mate10两种截图方法

    10月20日上午,华为带来了一款年度高端旗舰机----华为Mate10,主打大屏商务体验,该机已经在电商平台和线下渠道上市发售了.拿到真机之后相信不少朋友打使用过程当中需要用到截图操作.那么.华为Ma ...

  8. DL框架之Tensorflow:深度学习框架Tensorflow的简介、安装、使用方法之详细攻略

    DL框架之Tensorflow:深度学习框架Tensorflow的简介.安装.使用方法之详细攻略 目录 Tensorflow的简介 1.描述 2.TensorFlow的六大特征 3.了解Tensorf ...

  9. 华为手机上高德sdk定位不准

    问题 在华为手机上测试高德sdk时,发现在切换城市或默认定位当前城市时,总是返回默认定位位置北京. 原因 由于华为的芯片是自主研发,导致和高德sdk的接口不兼容.因此无法准确定位. 高德sdk定位的逻 ...

最新文章

  1. Google正式收购百度
  2. C++ multimap 的插入,遍历,删除
  3. python接口测试之requests详解_Python接口测试-requests库
  4. The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
  5. 今天开始学opnet14.5
  6. UI培训之零基础如何自学UI设计?
  7. JavaSE网络编程练习
  8. 网络流媒体下载的 10 种方法(以下载 Echo 音乐为例)
  9. windows关闭休眠
  10. Fandis COSTECH A17M23SWB MT0再见,故宫
  11. 新计算机是飞行模式怎么开,win10自己打开飞行模式,怎么处理
  12. 组装台式机后进入PE,检测不到硬盘的解决方法
  13. 3D打印机的优势到底在哪
  14. 微信小程序联盟:官方文档+精品教程+demo集合(12月更新……)
  15. 【s3.amazonaws.com】【github.com】拒绝了我们的连接请求-解决方案
  16. python--爬虫--积累--多图片网站抓取加速方案和调优记录
  17. 如春日细雨般的缠绵,浸润心扉
  18. CAS:1347750-20-2,氨基PEG巯基,NH2-PEG-SH,Amine-PEG-Thiol
  19. Java程序性能优化 读书笔记(十)并行设计模式:Future模式
  20. java文件打包成jar文件_将java文件打包成jar包步骤

热门文章

  1. framebuffer结构体分析
  2. note js 创建项目_vue.js使用vuecli3快速创建项目
  3. win10 修改gitlab账号_玩转gitlab + jenkins
  4. django重置密码发送html邮件,Django实现发送邮件找回密码功能
  5. android序列化异常,关于序列化:错误:Android中的序列化和反序列化
  6. elasticsearch 分页_[Springboot实战系列]整合ElasticSearch实现数据模糊搜索
  7. linux windows 字符编码转换,Linux操作系统下汉字编码的转换
  8. java获取24小时制时间格式_java 日期格式时间24小时制
  9. 非平衡电桥电阻计算_什么是RTD热电阻?两线制和三线制RTD有什么不同?
  10. php mysql商品管理_PHP基础示例:商品信息管理系统v1.1[转]