這是我的問題,我想在TimeDistributed圖層中使用pretrain CNN網絡之一。但是我有一些問題來實現它。Keras pretrain有時間分佈的CNN
這裏是我的模型:
def bnn_model(max_len):
# sequence length and resnet input size
x = Input(shape=(maxlen, 224, 224, 3))
base_model = ResNet50.ResNet50(weights='imagenet', include_top=False)
for layer in base_model.layers:
layer.trainable = False
som = TimeDistributed(base_model)(x)
#the ouput of the model is [1, 1, 2048], need to squeeze
som = Lambda(lambda x: K.squeeze(K.squeeze(x,2),2))(som)
bnn = Bidirectional(LSTM(300))(som)
bnn = Dropout(0.5)(bnn)
pred = Dense(1, activation='sigmoid')(bnn)
model = Model(input=x, output=pred)
model.compile(optimizer=Adam(lr=1.0e-5), loss="mse", metrics=["accuracy"])
return model
當編譯模型我沒有錯誤。但是,當我開始訓練,我得到以下錯誤:
tensorflow/core/framework/op_kernel.cc:975] Invalid argument: You must feed a value for placeholder tensor 'input_2' with dtype float
[[Node: input_2 = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/gpu:0"]()]]
我檢查,我做派FLOAT32但對於輸入1,輸入2是存在於pretrain RESNET輸入。
只是在這裏有一個概述是模型總結。 (注:這是奇怪的是,它並沒有顯示RESNET裏面發生了什麼,但沒關係)
____________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
====================================================================================================
input_1 (InputLayer) (None, 179, 224, 224, 0
____________________________________________________________________________________________________
timedistributed_1 (TimeDistribut (None, 179, 1, 1, 204 23587712 input_1[0][0]
____________________________________________________________________________________________________
lambda_1 (Lambda) (None, 179, 2048) 0 timedistributed_1[0][0]
____________________________________________________________________________________________________
bidirectional_1 (Bidirectional) (None, 600) 5637600 lambda_1[0][0]
____________________________________________________________________________________________________
dropout_1 (Dropout) (None, 600) 0 bidirectional_1[0][0]
____________________________________________________________________________________________________
dense_1 (Dense) (None, 1) 601 dropout_1[0][0]
====================================================================================================
Total params: 29,225,913
Trainable params: 5,638,201
Non-trainable params: 23,587,712
____________________________________________________________________________________________________
我猜,我不正確地使用TimeDistributed,我沒有看見任何人試圖做到這一點。我希望有人能指導我。
編輯:
的問題來自於以下事實:ResNet50.ResNet50(weights='imagenet', include_top=False)
在圖中創建自己的輸入。
所以我想我需要做一些像ResNet50.ResNet50(weights='imagenet', input_tensor=x, include_top=False)
但我不知道如何將它與TimeDistributed
耦合。
我試圖
base_model = Lambda(lambda x : ResNet50.ResNet50(weights='imagenet', input_tensor=x, include_top=False))
som = TimeDistributed(base_model)(in_ten)
但它不工作。
它似乎要求佔位符的浮點值。你可以追蹤傳遞給'tf.Session.run'調用中'feed_dict'的東西嗎? – drpng
在** tensorflow_backend.py中,我打印了feed_dict,並得到了這個'[,, dtype = bool>,]'。 ResNet仍然使用佔位符定義,但不應該這樣做。 –
rAyyy
我很確定我應該做一些像'ResNet50.ResNet50(weights ='imagenet',input_tensor = x,include_top = False'),所以base_model中沒有佔位符,但我不明白如何用TimeDistributed來做到這一點。 – rAyyy