[英]Implementation of image pre-processing methods on android
Could you please suggest a library (or a snippet) to implement pre-processing Python methods (eg numpy.expand_dims()
or img_to_array
) on Android API 18 (to deploy an app based on TensorFlow Mobile)? 您能否建议一个库(或代码段)在Android API 18上实施预处理的Python方法(例如numpy.expand_dims()
或img_to_array
)(以部署基于TensorFlow Mobile的应用程序)? There are analogous libraries to Python on Java (eg ND4J), but they require device or emulator that runs API level 21 or higher. 有与Java上的Python类似的库(例如ND4J),但是它们需要运行API级别21或更高级别的设备或仿真器。
from keras.preprocessing.image import img_to_array
import numpy as np
image = img_to_array(image)
image = np.expand_dims(image, axis=0)
image /= 255.
I an interactive session: 我是一个互动环节:
In [168]: np.source(np.expand_dims)
In file: /usr/local/lib/python3.5/dist-packages/numpy/lib/shape_base.py
def expand_dims(a, axis):
"""
.... docs
"""
a = asarray(a)
shape = a.shape
if axis > a.ndim or axis < -a.ndim - 1:
# 2017-05-17, 1.13.0
warnings.warn("Both axis > a.ndim and axis < -a.ndim - 1 are "
"deprecated and will raise an AxisError in the future.",
DeprecationWarning, stacklevel=2)
# When the deprecation period expires, delete this if block,
if axis < 0:
axis = axis + a.ndim + 1
# and uncomment the following line.
# axis = normalize_axis_index(axis, a.ndim + 1)
return a.reshape(shape[:axis] + (1,) + shape[axis:])
So basically it uses reshape
, with a shape that includes a size 1
dimension in the right place. 因此,基本上,它使用reshape
,其形状在正确的位置包括尺寸为1
尺寸。 That could also have been done with the [:,:,np.newaxis,...]
syntax. 也可以使用[:,:,np.newaxis,...]
语法来完成。
Whether any of that is portable to Java depends on the array implementation in that language. 是否可以移植到Java中取决于该语言的数组实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.