【问题标题】:Found unexpected instance while processing input tensors for keras functional model - Keras, Tensorflow在处理 keras 功能模型的输入张量时发现意外实例 - Keras,Tensorflow
【发布时间】:2022-11-11 05:02:01
【问题描述】:

我正在尝试在我的桌面 PyCharm 应用程序上复制来自 Kaggle (https://www.kaggle.com/pavansanagapati/simple-tutorial-on-object-recognition) 的在线教程。

但我收到一个错误:

Traceback (most recent call last):
File "C:\Users\blahblah\main.py", line 195, in <module>
activations = get_featuremaps(cnn_model, int(layer_num), test_img)
File "C:\Users\blahblah\main.py", line 187, in get_featuremaps
get_activations = K.function([cnn_model.layers[0].input, K.learning_phase()],
File "C:\Users\blahblah\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\backend.py", line 4229, in function
model = models.Model(inputs=inputs, outputs=outputs)
File "C:\Users\blahblah\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\training\tracking\base.py", line 530, in _method_wrapper
result = method(self, *args, **kwargs)
File "C:\Users\blahblah\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\engine\functional.py", line 143, in __init__
if not all([functional_utils.is_input_keras_tensor(t)
File "C:\Users\blahblah\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\engine\functional.py", line 143, in <listcomp>
if not all([functional_utils.is_input_keras_tensor(t)
File "C:\Users\blahblah\AppData\Local\Programs\Python\Python39\lib\site-packages\keras\engine\functional_utils.py", line 47, in is_input_keras_tensor
raise ValueError(_KERAS_TENSOR_TYPE_CHECK_ERROR_MSG.format(tensor))
ValueError: Found unexpected instance while processing input tensors for keras functional model. Expecting KerasTensor which is from tf.keras.Input() or output from keras layer call(). Got: 0

这就是有问题的代码。

def get_featuremaps(cnn_model, layer_idx, X_batch):
    get_activations = K.function([cnn_model.layers[0].input, K.learning_phase()],
                                 [cnn_model.layers[layer_idx].output, ])
    activations = get_activations([X_batch, 0])
    return activations

如何处理?

【问题讨论】:

    标签: python tensorflow keras kaggle


    【解决方案1】:

    游戏迟到了,但看起来你的输入不是 keras 张量。你能告诉我你的输入吗?

    【讨论】:

    最近更新 更多