所以基本上,我訓練了一個帶有調整大小層的模型。這是我的模型:
model = Sequential()
model.add(keras.layers.Lambda(
lambda image: tf.image.resize(
image,
(470,470),
method = tf.image.ResizeMethod.BICUBIC,
preserve_aspect_ratio = True
)
))
model.add(Conv2D(32, (3, 3), activation='relu', input_shape=shape))
model.add(MaxPool2D((2, 2)))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPool2D((2, 2)))
model.add(Conv2D(128, (3, 3), activation='relu'))
model.add(MaxPool2D((2, 2)))
model.add(Flatten())
model.add(Dense(256, activation='relu'))
model.add(Dropout(0.33))
model.add(Dense(128, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
在使用第一層之前,我可以保存并加載模型,但現在加載時出現此錯誤:
ValueError: The channel dimension of the inputs should be defined. The input_shape received is (None, None, None, None), where axis -1 (0-based) is the channel dimension, which found to be `None`.
我首先像這樣加載我的資料:
model2 = load_model('catsanddogs.h5')
并且還嘗試了一些來自github問題的解決方案,使它像這樣model =load_model('catsanddogs.h5',custom_objects={"tf":tf})
有誰知道如何正確加載這個模型?
uj5u.com熱心網友回復:
對于將來遇到此問題的任何人,不要使用 lambda 層,而是使用 keras 調整大小層。此外,無法加載的 h5 檔案仍然適用于 huggingface。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/482761.html
上一篇:從張量生成數量遞增的片段
