簡體   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