博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在android上跑 keras 或 tensorflow 模型
阅读量:5924 次
发布时间:2019-06-19

本文共 4794 字,大约阅读时间需要 15 分钟。

https://groups.google.com/forum/#!topic/keras-users/Yob7mIDmTFs

http://talc1.loria.fr/users/cerisara/posts/tflow/

 

The current Tensorflow sample on Android loads tensorflow_inception_graph.pb. Assuming one can convert a model generated by Keras to a Tensorflow graph and replace the file, I believe it should work. This is our step #1 -- to make the model running on Android. However, it is still different to our original goal: running Keras model on Android. It is more like a process to convert (and compress?) Keras model to Tensorflow, and run Tensorflow on Android (please correct me if my understanding about Keras and Tensorflow is not correct). If it is possible, we are hoping to make the Keras model run on Android with minimum changes to the model source built on desktop. That is why Bafu mentioned porting python modules to Android (mainly rely on Kivy).
                                                                                
Our project has just started and is still at very early stage, so any comment/suggestion is more than welcome :).
If it goes well, we plan to share more technical details in two or three months.    

 

 

==============

Short story

Do you want to design (and not only use) a deep learning model on an Android tablet, while on the go ? Here are the steps to do (explanations come later on):

  • install Termux from google play, because its command-line git is flawless
  • install GNURoot Debian from google play, to have a Debian linux on your tablet (all without rooting your tablet !)
  • within Debian, install python (apt-get install python python-scipy python-numpy python-pip) Note that you must install scipy and numpy with apt-get and not pip (!) because scipy compilation from pip fails on my Lollipop.
  • you can now install Theano with pip install theano
  • and finally install keras: pip install keras
  • last important trick: before running Keras, create a new directory in /usr/urhome because on my Lollipop, importing theano from within python fails due to issues with exec flag on /home. But it works in /usr.
  • So you may import Keras within python after: HOME=/usr/urhome KERAS_BACKEND=theano python

It works ! Of course, not very fast: I've run the Keras reuters examples, which takes 36s per iteration (!), but gives in the end the same 79.5% accuracy than on my computer. So it's not obviously done to really train models, but rather to debug, write and test Keras code on the go.

Note that you'll be able to design deep learning models with Keras-theano: I've tried to install Tensorflow (see below) but it's much more difficult than Theano. The good news is that the Keras models are independent from the backend, so the models you design with Keras-theano will run with Keras-Tensorflow on another machine as well.

Long story

There are several options to get a linux distro on your tablet:

  • If you have a rooted phone, you may want to give one of the many android application that allows to install Debian on your mobile. I don't want to root it (because all rooting apps I have tried so far have failed, and my last try at rooting the tabler with adb made my tablet run into a boot loop that I have had all difficulties to fix... So, no more rooting for me !)
  • On a non rooted android, the best I have found is GNURoot, which gives you a (nearly) full Debian.

But this Debian comes with a number of issues:

  • It takes more than 2GB of memory, and you may not be able to use it on your sdcard (without rooting, and the sdcard is protected on lollilop; I've managed to be able to write on it, but because it's FAT, there is no way to change file permissions and make them executable. So, many issues come from this limitation, and it's best to use it only from the internal memory)
  • You can run python, libreoffice... but because it's ARM, there are several important programs (for me) that just can't be installed; for instance, tensorflow or the google android python API.
  • git is here, but it is not working fine, because of file permissions on ssh keys
  • Sometimes, file management has minor issues, and you cannot remove a directory with rm -rf

To cope with the last two issues, I recommend installing also Termux, which git program is the best I've found so far (works perfectl) and which handles very well all file systems: I can even "git clone" on the external card with termux, which is impossible with GNURoot. But termux is limited because it cannot access the Debian repositories.

Additional notes on getting tensorflow python API, which failed for me so far:

  • You cannot install tensorflow with pip on 32 bits CPU, so you must compile tensorflow from source.
  • But this requires the bazel building executable, which is also not easy to compile on arm 32 bits: see for how to do it.
  • Compiling Bazel fails for me because it required a 32-bit arm protobuf, which I may have tried to compile as well, but wait, that was enough for me ;-)

 

转载地址:http://qzavx.baihongyu.com/

你可能感兴趣的文章
日期的常规运用
查看>>
pgrep 查询进程的工具
查看>>
OAF_架构MVC系列3 - View的概述(概念)
查看>>
java的定时器用法
查看>>
TempDB--临时表的缓存
查看>>
什么是java 序列化,如何实现java 序列化?
查看>>
Java模式(适配器模式)
查看>>
腾讯开放平台:无法拉起客户端分享的问题
查看>>
因你常说没关系,他便不觉对不起。
查看>>
Android 4.4 KitKat升级率已经接近18%(2014-07-09 07:29)
查看>>
Python list去重及找出,统计重复项
查看>>
C#Light 再推荐,顺便介绍WP8 功能展示项目
查看>>
查询所有数据库,数据集
查看>>
[转]虚拟现实和现实增强技术带来的威胁
查看>>
lua 按拉分析与合成
查看>>
借蜡烛
查看>>
Android中的UriMatcher、ContentUrist和ContentResolver
查看>>
我的VIM配置
查看>>
安装RVDS2.2
查看>>
使用ThinkPHP框架高速开发站点(多图)
查看>>