2017-02-18 7 views
2

これは私の問題です。私はTimeDistributedレイヤーでプリトレインCNNネットワークの1つを使用したいと思います。しかし、私はそれを実装するいくつかの問題があります。ここでKerasはTimeDistributedで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を送ってやるが、INPUT1のために、INPUT2は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を使用していないと私は誰もがこれをやろうとしていない見たことを推測しています。私は誰かがこれについて私を導くことができれば嬉しいです

EDIT:

問題は、グラフに独自の入力を作成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) 

を試みたが、それは動作しません。

+0

プレースホルダの浮動小数点値を求めるようです。 'tf.Session.run'呼び出しの' feed_dict'に渡された内容をトレースできますか? – drpng

+0

で** tensorflow_backend.py **私はfeed_dictを印刷しましたが、この '[ dtype = bool>、] '。 ResNetは依然としてプレースホルダーで定義されています。 – rAyyy

+0

私は 'ResNet50.ResNet50(weights = 'imagenet'、input_tensor = x、include_top = False)のようなことをしなければならないと確信していますので、base_modelにプレースホルダーはありませんが、TimeDistributedを使ってそれを行う方法はわかりません。 – rAyyy

答えて

1

私の素早い解決策は少し醜いです。

私はちょうどResNetのコードをコピーし、TimeDistributedをすべてのレイヤーに追加してから、カスタマイズしたResNetの "基本" ResNetからウェイトをロードしました。

注:

GPU上のメモリの膨大な量を取るん。このような一連の画像を解析することができるようにするには。

+0

実際には、他の方法はありません。<あなたの解決策は現在可能です。 –

関連する問題