【发布时间】:2019-12-16 20:35:50
【问题描述】:
我正在尝试开始使用 Tensorflow-Hub 从图像中提取特征向量。但是,我不确定如何将 Tensorflow-Hub 输出(张量)转换为 numpy 向量。这是一个简单的例子:
from keras.preprocessing.image import load_img
import tensorflow_hub as hub
import tensorflow as tf
import numpy as np
im = load_img('sample.png')
im = np.expand_dims(im.resize((299,299)), 0)
module = hub.Module("https://tfhub.dev/google/imagenet/inception_v3/feature_vector/1")
out = module(im)
o = np.add(out, 0)
type(o)
docs 表示“NumPy 操作自动将张量转换为 NumPy ndarrays”,但我上面的np.add() 调用返回对象类型tensorflow.python.framework.ops.Tensor。有谁知道我如何从out 获得一个 numpy 数组?任何指针将不胜感激!
版本:
# output from `pip freeze | grep tensorflow`
tensorflow==1.14.0
tensorflow-estimator==1.14.0
tensorflow-hub==0.1.1
tensorflow-probability==0.6.0
【问题讨论】:
标签: python arrays numpy tensorflow