【发布时间】:2018-06-27 18:04:18
【问题描述】:
我正在尝试创建一个模型图,其中我的输入是从我的 java 程序输入的 tensorflow 变量 在我的代码中,我使用 numpy 方法,我需要将我的 tensorflow 变量输入转换为 numpy 数组输入
这是我的代码 sn-p
import tensorflow as tf
import numpy as np
eps = np.finfo(float).eps
EXPORT_DIR = './model'
def standardize(x):
med0 = np.median(x)
mad0 = np.median(np.abs(x - med0))
x1 = (x - med0) / (mad0 + eps)
return x1
#tensorflow input variable
a = tf.placeholder(tf.float32, name="input")
with tf.Session() as session:
session.run(tf.global_variables_initializer())
#Converting the input variable to numpy array
tensor = a.eval()
#calling standardize method
numpyArray = standardize(tensor)
#converting numpy array to tf
tf.convert_to_tensor(numpyArray)
#creating graph
graph = tf.get_default_graph()
tf.train.write_graph(graph, EXPORT_DIR, 'model_graph.pb', as_text=False)
我收到错误:InvalidArgumentError(有关回溯,请参见上文):您必须在行 tensor = a.eval()
当我用常量值代替占位符时,它就会工作并生成图表。但我想从我的 java 代码中输入。 有没有办法做到这一点,或者我需要将我所有的 numpy 方法转换为 tensorflow 方法
【问题讨论】:
-
您只是转换为 numpy 并返回标准化吗?我宁愿直接在 TF 中这样做。然而,上面可能缺少的是 feed_dict。试试 a.eval(feed_dict={a:
}) -
实际上,我现在没有任何值可以提供,因为我正在使用它作为我的 android 应用程序的模型。更多信息请参考link
标签: python numpy tensorflow