首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >图像预处理方法在android上的实现

图像预处理方法在android上的实现
EN

Stack Overflow用户
提问于 2017-09-05 22:58:14
回答 1查看 510关注 0票数 1

您能否推荐一个库(或代码片段)来在Android API18上实现预处理Python方法(例如numpy.expand_dims()img_to_array) (以部署基于TensorFlow移动的应用程序)?有一些类似于Java上的Python的库(例如ND4J),但它们需要运行API21或更高级别的设备或仿真器。

代码语言:javascript
运行
复制
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.
EN

回答 1

Stack Overflow用户

发布于 2017-09-06 00:41:41

我有一个互动会话:

代码语言:javascript
运行
复制
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:])

所以基本上它使用了reshape,它的形状在正确的位置包含了一个大小为1的维度。使用[:,:,np.newaxis,...]语法也可以做到这一点。

其中是否可以移植到Java取决于该语言中的数组实现。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46058060

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档