gpt4 book ai didi

python - Theano,类型错误: Unknown parameter type:

转载 作者:太空宇宙 更新时间:2023-11-03 14:33:17 25 4
gpt4 key购买 nike

当我运行以下代码(来自 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 笔记本似乎不包含任何错误消息。我无法找到有关 tensorflow.python.framework.ops.Tensor 错误消息的更具体建议。

最佳答案

看来您有一个 tensorflow 后端 - 而不是 theano 后端。这就是使用 theano.function 会生成错误的原因。尝试使用keras.backend.function

关于python - Theano,类型错误: Unknown parameter type: <class 'tensorflow.python.framework.ops.Tensor' >,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47124427/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com