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.    

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

Deep Learning with Keras on Android

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: seehttps://github.com/samjabrahams/tensorflow-on-raspberry-pi/blob/master/GUIDE.md#3-build-bazel 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 ;-)

在android上跑 keras 或 tensorflow 模型的更多相关文章

  1. 使用C++部署Keras或TensorFlow模型

    本文介绍如何在C++环境中部署Keras或TensorFlow模型. 一.对于Keras, 第一步,使用Keras搭建.训练.保存模型. model.save('./your_keras_model. ...

  2. 26、android上跑apache的ftp服务

    一.为啥 在android设备跑ftp服务,在现场方便查看日志,目前就是这么用的. 二.前提: 从apache的官网下载依赖包:http://mina.apache.org/ftpserver-pro ...

  3. Win10上安装Keras 和 TensorFlow(GPU版本)

    一. 安装环境 Windows 10 64bit  家庭版 GPU: GeForce GTX1070 Python: 3.5 CUDA: CUDA Toolkit 8.0 GA1 (Sept 2016 ...

  4. Linux上多次restore Tensorflow模型报错

    环境:python3,tensotflow 在恢复了预先训练好的模型进行预测时,第一次是能够成功执行的,但我多次restore模型时,出现了以下问题: 1.ValueError: Variable c ...

  5. 移动端目标识别(1)——使用TensorFlow Lite将tensorflow模型部署到移动端(ssd)之TensorFlow Lite简介

    平时工作就是做深度学习,但是深度学习没有落地就是比较虚,目前在移动端或嵌入式端应用的比较实际,也了解到目前主要有 caffe2,腾讯ncnn,tensorflow,因为工作用tensorflow比较多 ...

  6. android上部署tensorflow

    https://www.jianshu.com/p/ddeb0400452f 按照这个博客就可以 https://github.com/CrystalChen1017/TSFOnAndroid 这个博 ...

  7. 三分钟快速上手TensorFlow 2.0 (上)——前置基础、模型建立与可视化

    本文学习笔记参照来源:https://tf.wiki/zh/basic/basic.html 学习笔记类似提纲,具体细节参照上文链接 一些前置的基础 随机数 tf.random uniform(sha ...

  8. 让“是男人就下到100层”在Android平台上跑起来

    原工程:https://github.com/jeekun/DownFloors 移植后的代码:HelloCpp.zip 移植后的APK:HelloCpp.apk 说明:(cocos2d-x版本是“ ...

  9. TensorFlow 在android上的Demo(1)

    转载时请注明出处: 修雨轩陈 系统环境说明: ------------------------------------ 操作系统 : ubunt 14.03 _ x86_64 操作系统 内存: 8GB ...

随机推荐

  1. Maven基础命令

    Maven 参数 -D 传入属性参数 -P 使用pom中指定的配置 -e 显示maven运行出错的信息 -o 离线执行命令,即不去远程仓库更新包 -X 显示maven允许的debug信息 -U 强制去 ...

  2. MySQL线程池总结

    线程池是Mysql5.6的一个核心功能,对于服务器应用而言,无论是web应用服务还是DB服务,高并发请求始终是一个绕不开的话题.当有大量请求并发访问时,一定伴随着资源的不断创建和释放,导致资源利用率低 ...

  3. 10个网页设计师必备的CSS技巧(转)

    英文原文:10 Essential CSS Rules for Web Designers CSS是网页设计师的基础,对CSS的了解能使他们能够设计出更加美观别致的网页.使用CSS技巧来巧妙地处理CS ...

  4. 敏捷软件开发实践-Release Process/Release Plan(转)

    介绍: 因为我们的开发周期是迭代进行的,以Sprint为单位,我们每个 Sprint如何去和客户说我们的成果呢,那么我就需要Demo和release一些新功能,或者一些bug fixing.Demo我 ...

  5. 【BZOJ】1064: [Noi2008]假面舞会(判环+gcd+特殊的技巧)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1064 表示想到某一种情况就不敢写下去了.... 就是找环的gcd...好可怕.. 于是膜拜了题解.. ...

  6. 单引號转义符q’的使用

    当字符串包括单引號时,能够使用转义符q'对单引號进行转义. q'后面的字符能够是:     !     [ ]     { }     ( )     < > 前提是这些字符不会出如今兴许 ...

  7. hdu 4240在(最大流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4240 思路:题意真的有点难理解:在城市A->B之间通过所有路径一小时之内能通过最大的车辆(Max ...

  8. C++ enum 枚举类型

    1. 枚举类型浅谈 假设我们要设计一个打开文件的函数, 打开文件由三种状态: input, output 和 append. 不使用枚举, 我们可能会写出如下的代码 const int input = ...

  9. 在scrollview中双击定点放大的代码

    双击放大是 iPhone 的一个基本操作,第三方程序里引入这一功能的话,主要是在 scrollview 呈现一张图片或者 PDF 页面时,双击可以放大,主要代码如下 - (void)scrollVie ...

  10. JAVA上百实例源码网站

    JAVA源码包1JAVA源码包2JAVA源码包3JAVA源码包4 JAVA开源包1 JAVA开源包2 JAVA开源包3 JAVA开源包4 JAVA开源包5 JAVA开源包6 JAVA开源包7 JAVA ...