繁体   English   中英

在处理 keras 功能 model - Keras、ZCB20B802A3F21255E054E488 的输入张量时发现意外实例

[英]Found unexpected instance while processing input tensors for keras functional model - Keras, Tensorflow

我对 ML 和图像识别主题基本上是超级新手,为了学习,我目前正在尝试做的是复制并制作来自 kaggle.com 的在线教程( https://www.kaggle. com/pavansanagapati/simple-tutorial-on-object-recognition )在我的桌面 PyCharm 应用程序上工作。

我有一个严重的(至少对于初学者来说)问题,我已经坚持了一段时间。 您可以在下面看到我现在正在处理的错误。

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

我将非常感谢有关如何处理该问题的所有答案和想法。 干杯!

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM