【发布时间】:2017-11-05 17:27:02
【问题描述】:
当我运行以下代码(来自this IPython notebook)时,我得到一个错误:
import theano
def get_submodel(model, start, end):
return theano.function([model.layers[start].input],
model.layers[end].get_output(train=False),
allow_input_downcast=True)
def get_encoder(ae):
return get_submodel(ae, 0, (len(ae.layers) // 2) - 1)
ae_encoder = get_encoder(ae)
这是错误信息:
Traceback (most recent call last):
File "Parametric t-SNE (Keras).py", line 432, in <module>
ae_encoder = get_encoder(ae)
File "Parametric t-SNE (Keras).py", line 424, in get_encoder
return get_submodel(ae, 0, (len(ae.layers) // 2) - 1)
File "Parametric t-SNE (Keras).py", line 422, in get_submodel
allow_input_downcast=True)
File "/usr/lib64/python3.4/site-packages/theano/compile/function.py", line 326, in function
output_keys=output_keys)
File "/usr/lib64/python3.4/site-packages/theano/compile/pfunc.py", line 397, in pfunc
for p in params]
File "/usr/lib64/python3.4/site-packages/theano/compile/pfunc.py", line 397, in <listcomp>
for p in params]
File "/usr/lib64/python3.4/site-packages/theano/compile/pfunc.py", line 496, in _pfunc_param_to_in
raise TypeError('Unknown parameter type: %s' % type(param))
TypeError: Unknown parameter type: <class 'tensorflow.python.framework.ops.Tensor'>
作为参考,这里是定义 ae 的地方:
n = X_train.shape[1]
ae = Sequential()
ae.add(Dense(500, activation='relu', weights=encoder.layers[0].get_weights(), input_shape=(n,)))
ae.add(Dense(500, activation='relu', weights=encoder.layers[1].get_weights()))
ae.add(Dense(2000, activation='relu', weights=encoder.layers[2].get_weights()))
ae.add(Dense(2, weights=encoder.layers[3].get_weights()))
ae.add(Dense(2000, activation='relu', weights=decoder.layers[0].get_weights()))
ae.add(Dense(500, activation='relu', weights=decoder.layers[1].get_weights()))
ae.add(Dense(500, activation='relu', weights=decoder.layers[2].get_weights()))
ae.add(Dense(n, weights=decoder.layers[3].get_weights()))
ae.compile(loss='mse', optimizer='rmsprop')
ae.fit(X_train, X_train, nb_epoch=100, verbose=2, batch_size=32)
根据对a similar question 的回答,我怀疑get_submodel 可能需要修改为使用符号变量而不是张量/矩阵。但是,我不确定如何执行此操作,以及为什么它甚至会给出错误,因为 GitHub 上的 IPython notebook 似乎没有包含任何错误消息。我无法找到有关tensorflow.python.framework.ops.Tensor 错误消息的更具体建议。
【问题讨论】:
-
您似乎有一个
tensorflow后端 - 而不是theano一个。 -
是的,这似乎是问题所在。非常感谢你! (我是所有这些机器学习框架的新手。)
-
好的 - 那么我会制定一个答案。
-
你让它运行了吗?
-
该部分现在运行。我有能力得到另一个错误,尽管它来自代码的不同部分。
标签: python tensorflow keras theano