困っていること
以下「モデル、実現したいこと」で記載した内容を、以下「コード」で書いたようにkerasで記述したですが、実現できずに困っています。どなたかkerasにお詳しい方、どのようにすれば「モデル、実現したいこと」に記載した内容のことを実現できるかご教示いただけないでしょうか?お手数ですが、よろしくお願い致します。
モデル、実現したいこと
<全体>
2つの入力→それぞれのネットワーク→結合(マージ)→共通のネットワーク→2つの出力(分岐)
<補足>
※ニューラルネットワークモデルが2つ存在(入力も2つある)しているが、
中間から最終層までモデルを共有していて、最終層で出力が2つに分岐する
※入力と出力は1対1で対応している
※2つのモデル間で共有したいのは、
結合後の共通のニューラルネットワークとその重みだけ
※2つのモデルを交互に学習させて、
結合後の共通のニューラルネットワークの重みを更新させたい
※1つのモデル(A)で学習しているときは、
もう1つのモデル(B)には入力はなされず、
B側のモデルは中間層までのニューラルネットワーク(=結合前まで)の重みは更新しない
私が書いたコード
#モデルA input1 = Input(shape=(128,),name="Input_1") x1 = Dense(128, activation="relu")(input1) x1_1 = Dense(64, activation="relu")(x1) x1_2 = Dense(32, activation="relu")(x1_1) nx1 = Model(inputs=input1, outputs=x1_2) #モデルB input2 = Input(shape=(129,),name="Input_2") x2 = Dense(128, activation="relu")(input2) x2_1 = Dense(64, activation="relu")(x2) x2_2 = Dense(32, activation="relu")(x2_1) nx2 = Model(inputs=input2, outputs=x2_2) #モデルA.Bの結合 combined = concatenate([nx1.output, nx2.output]) #モデルA,B結合後の共通のネットワーク y = Dense(32, activation="relu")(combined) y_1 = Dense(16, activation="relu")(y) y_2 = Dense(8, activation="relu")(y_1) y1 = Dense(1,name="Output_1")(y_2) y2 = Dense(1,name="Output_2")(y_2) model1 = Model(inputs=input1, outputs=y1) model2 = Model(inputs=input2, outputs=y2) model1.compile(loss='mean_squared_error', optimizer='adam') model2.compile(loss='mean_squared_error', optimizer='adam')
上記コードを実行した時のエラーメッセージ
Traceback (most recent call last): File "<ipython-input-57-fc6ceb5f5892>", line 57, in <module> model1 = Model(inputs=input1, outputs=y1) File "C:\Users...\AppData\Local\Continuum\anaconda3\lib\site-packages\keras\legacy\interfaces.py", line 91, in wrapper return func(*args, **kwargs) File "C:\Users...\AppData\Local\Continuum\anaconda3\lib\site-packages\keras\engine\network.py", line 93, in __init__ self._init_graph_network(*args, **kwargs) File "C:\Users...\AppData\Local\Continuum\anaconda3\lib\site-packages\keras\engine\network.py", line 231, in _init_graph_network self.inputs, self.outputs) File "C:\Users...\AppData\Local\Continuum\anaconda3\lib\site-packages\keras\engine\network.py", line 1443, in _map_graph_network str(layers_with_complete_input)) ValueError: Graph disconnected: cannot obtain value for tensor Tensor("Input_2_22:0", shape=(?, 128), dtype=float32) at layer "Input_2". The following previous layers were accessed without issue: []
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/06 14:40