簡體   English   中英

在Android上實現圖像預處理方法

[英]Implementation of image pre-processing methods on android

您能否建議一個庫(或代碼段)在Android API 18上實施預處理的Python方法(例如numpy.expand_dims()img_to_array )(以部署基於TensorFlow Mobile的應用程序)? 有與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.

我是一個互動環節:

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中取決於該語言的數組實現。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM