[英]'Tensor' object has no attribute '_keras_history' Keras with no Tensorflow tensor
這段代碼:
a = Input(ish)
for i in range(a.shape[1]):
x=Conv2D(filters=50, kernel_size=3, padding='same', activation=rl)(a[:,i])
x=MaxPooling2D(pool_size=2)(x)
x=Dropout(0.5)(x)
x=Conv2D(filters=100, kernel_size=5, padding='same', activation=rl)(x)
x=MaxPooling2D(pool_size=2)(x)
x=Dropout(0.5)(x)
x=Conv2D(filters=200, kernel_size=7, padding='same', activation=rl)(x)
x=MaxPooling2D(pool_size=2)(x)
t=Flatten()(x)
t=Dropout(0.7)(t)
b=Dense(num_classes, activation='softmax')(t)
model = Model(inputs=a, outputs=b)
在最后一行中,給出此錯誤:
AttributeError: 'Tensor' object has no attribute '_keras_history'
您知道導致問題的原因是什么,如何解決?
為了保留Keras元數據,您必須在Lambda層中進行索引編制:
a = Input(ish)
for i in range(a.shape[1]):
x=Lambda(lambda x: x[:, i])(a)
x=Conv2D(filters=50, kernel_size=3, padding='same', activation=rl)(x)
x=MaxPooling2D(pool_size=2)(x)
x=Dropout(0.5)(x)
x=Conv2D(filters=100, kernel_size=5, padding='same', activation=rl)(x)
x=MaxPooling2D(pool_size=2)(x)
x=Dropout(0.5)(x)
x=Conv2D(filters=200, kernel_size=7, padding='same', activation=rl)(x)
x=MaxPooling2D(pool_size=2)(x)
t=Flatten()(x)
t=Dropout(0.7)(t)
b=Dense(num_classes, activation='softmax')(t)
model = Model(inputs=a, outputs=b)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.