前提・実現したいこと
分類を行う人工知能の出力を時系列データとして扱う人工知能モデルの開発
発生している問題・エラーメッセージ
モデルを連結して学習を行おうとすると下記のようなエラーが出ます
ValueError: Graph disconnected: cannot obtain value for tensor Tensor("inputs_2_:0", shape=(None, 4, 10), dtype=float32) at layer "inputs_2_". The following previous layers were accessed without issue: []
該当のソースコード
constmodel
1from keras.layers import Input, Dense, LSTM, Concatenate, Activation 2from keras.models import Model 3 4 5class Mymodel(Model): 6 def __init__(self, hidden_finger_size, output_finger_size, output_hand_size, hidden_LSTM_size): 7 self.hidden_fing = hidden_finger_size 8 self.output_fing = output_finger_size 9 self.output_hand = output_hand_size 10 self.hidden_lstm = hidden_LSTM_size 11 12 def static_model(self, inputs): 13 #input 14 inputs[0] = Input(shape=(12, ), name='inputs_0') 15 inputs[1] = Input(shape=(15, ), name='inputs_1') 16 inputs[2] = Input(shape=(15, ), name='inputs_2') 17 inputs[3] = Input(shape=(15, ), name='inputs_3') 18 inputs[4] = Input(shape=(15, ), name='inputs_4') 19 20 #dense_1 21 dense_1_0 = Dense(self.hidden_fing, name='dense_1_0')(inputs[0]) 22 dense_1_1 = Dense(self.hidden_fing, name='dense_1_1')(inputs[1]) 23 dense_1_2 = Dense(self.hidden_fing, name='dense_1_2')(inputs[2]) 24 dense_1_3 = Dense(self.hidden_fing, name='dense_1_3')(inputs[3]) 25 dense_1_4 = Dense(self.hidden_fing, name='dense_1_4')(inputs[4]) 26 27 #activate_1 28 activation_1_0 = Activation(activation='sigmoid', name='activation_1_0')(dense_1_0) 29 activation_1_1 = Activation(activation='sigmoid', name='activation_1_1')(dense_1_1) 30 activation_1_2 = Activation(activation='sigmoid', name='activation_1_2')(dense_1_2) 31 activation_1_3 = Activation(activation='sigmoid', name='activation_1_3')(dense_1_3) 32 activation_1_4 = Activation(activation='sigmoid', name='activation_1_4')(dense_1_4) 33 34 #dense_2 35 dense_2_0 = Dense(self.output_fing, name='dense_2_0')(activation_1_0) 36 dense_2_1 = Dense(self.output_fing, name='dense_2_1')(activation_1_1) 37 dense_2_2 = Dense(self.output_fing, name='dense_2_2')(activation_1_2) 38 dense_2_3 = Dense(self.output_fing, name='dense_2_3')(activation_1_3) 39 dense_2_4 = Dense(self.output_fing, name='dense_2_4')(activation_1_4) 40 41 #activate_2 42 activation_2_0 = Activation(activation='sigmoid', name='activation_2_0')(dense_2_0) 43 activation_2_1 = Activation(activation='sigmoid', name='activation_2_1')(dense_2_1) 44 activation_2_2 = Activation(activation='sigmoid', name='activation_2_2')(dense_2_2) 45 activation_2_3 = Activation(activation='sigmoid', name='activation_2_3')(dense_2_3) 46 activation_2_4 = Activation(activation='sigmoid', name='activation_2_4')(dense_2_4) 47 48 #concatenate 49 concatenate = Concatenate()([activation_2_0, activation_2_1, activation_2_2, activation_2_3, activation_2_4]) 50 51 #dense_3 52 dense_3_ = Dense(self.output_hand, name='dense_3_')(concatenate) 53 activation_3_ = Activation(activation='sigmoid', name='activation_3_')(dense_3_) 54 55 return activation_3_ 56 57 def dynamic_model(self, inputs): 58 inputs_2_ = Input(shape=(4, 10, ), name='inputs_2_') 59 60 lstm_0 = LSTM(self.hidden_lstm, activation='sigmoid', name='lstm_0')(inputs_2_) 61 dense_4_ = Dense(self.output_hand, name='dense_4_')(lstm_0) 62 activation_4_ = Activation(activation='sigmoid', name='activation_4_')(dense_4_) 63 64 return activation_4_ 65
train
1import sys, time, csv, os 2 3my_path = ".." 4sys.path.append(my_path) 5 6from my_dataset.load_hand import load_hand_data 7from Myfunction import Myfunction 8from const_model import Mymodel 9 10from keras.layers import Input, Dense, LSTM, Flatten, Concatenate, Activation 11from keras.models import Model 12from keras.utils import plot_model 13 14import matplotlib.pyplot as plt 15import numpy as np 16import tensorflow as tf 17 18 19I = [12, 15, 15, 15, 15] 20epochs = 1 21batch_size = 40 22time_size = 4 23drop_out = 0.5 24 25hidden_finger_size = 10 #指の中間層サイズ 26output_finger_size = 5 #指の出力層サイズ 27output_hand_size = 10 #手の出力層サイズ 28hidden_LSTM_size = 10 #LSTMの中間層サイズ 29 30mymodel = Mymodel(hidden_finger_size, output_finger_size, output_hand_size, hidden_LSTM_size) 31func = Myfunction(batch_size) 32 33 34train_x, train_t, test_x, test_t = load_hand_data(["a.txt", "i.txt", "u.txt", "e.txt", "ku.txt", "se.txt", "so.txt", "ma.txt", "ru.txt", "ya.txt"], 35 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) 36#reshape_train_data_to_batch 37tr_batch_x, tr_batch_t = func.get_batch(train_x, train_t) 38te_batch_x, te_batch_t = func.get_test_batch(test_x, test_t) 39 40#train_data 41h_1_0 = tr_batch_x[:, :I[0]] #親指 42h_1_1 = tr_batch_x[:, I[0]:I[0]+I[1]] #人差し指 43h_1_2 = tr_batch_x[:, I[0]+I[1]:I[0]+I[1]+I[2]] #中指 44h_1_3 = tr_batch_x[:, I[0]+I[1]+I[2]:I[0]+I[1]+I[2]+I[3]] #薬指 45h_1_4 = tr_batch_x[:, I[0]+I[1]+I[2]+I[3]:] #小指 46#test_data 47h_2_0 = te_batch_x[:, :I[0]] #親指 48h_2_1 = te_batch_x[:, I[0]:I[0]+I[1]] #人差し指 49h_2_2 = te_batch_x[:, I[0]+I[1]:I[0]+I[1]+I[2]] #中指 50h_2_3 = te_batch_x[:, I[0]+I[1]+I[2]:I[0]+I[1]+I[2]+I[3]] #薬指 51h_2_4 = te_batch_x[:, I[0]+I[1]+I[2]+I[3]:] #小指 52 53 54#input 55inputs_0 = Input(shape=(12, ), name='inputs_0') 56inputs_1 = Input(shape=(15, ), name='inputs_1') 57inputs_2 = Input(shape=(15, ), name='inputs_2') 58inputs_3 = Input(shape=(15, ), name='inputs_3') 59inputs_4 = Input(shape=(15, ), name='inputs_4') 60inputs = [inputs_0, inputs_1, inputs_2, inputs_3, inputs_4] 61 62 63static_outputs = mymodel.static_model(inputs) 64dynamic_outputs = mymodel.dynamic_model(static_outputs) 65 66 67#train 68model = Model(inputs=inputs, outputs=dynamic_outputs) 69model.compile(optimizer='adam', 70 loss='categorical_crossentropy', 71 metrics=['accuracy']) 72history = model.fit([h_1_0, h_1_1, h_1_2, h_1_3, h_1_4], tr_batch_t, 73 batch_size=batch_size, 74 epochs=epochs, 75 verbose=1, 76 validation_data=([h_2_0, h_2_1, h_2_2, h_2_3, h_2_4], te_batch_t)) 77 78
試したこと
前回の投稿から、モデルをクラス化しました
クラス化した一つめのモデルの方は学習まで持って行けたのですが、二つ目のモデルの方を繋げて学習を行おうとするとエラーが
出ました
補足情報(FW/ツールのバージョンなど)
python3.6
keras2.3.1
回答1件
あなたの回答
tips
プレビュー