ミニバッチ学習をTensorflowで書いていたところ,
sess.run(train_step, feed_dict = {X: batch_x, t: batch_t})
で
Attempted to use a closed Session.
というエラーがでました.
エラーの内容を調べてみましたが改善方法がわかりません.
よろしくお願いします.
エラーコード
RuntimeError Traceback (most recent call last) <ipython-input-106-037e1a6e1227> in <module> 10 batch_x = train_x[sff_idx[idx: idx + batch_size]] 11 batch_t = train_t[sff_idx[idx: idx + batch_size]] ---> 12 sess.run(train_step, feed_dict = {X: batch_x, t: batch_t}) 13 14 if epoch % 100 == 0: ~\Anaconda3\envs\cpu\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata) 948 try: 949 result = self._run(None, fetches, feed_dict, options_ptr, --> 950 run_metadata_ptr) 951 if run_metadata: 952 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr) ~\Anaconda3\envs\cpu\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata) 1094 # Check session. 1095 if self._closed: -> 1096 raise RuntimeError('Attempted to use a closed Session.') 1097 if self.graph.version == 0: 1098 raise RuntimeError('The Session graph is empty. Add operations to the ' RuntimeError: Attempted to use a closed Session.
記述コード
入力層:60,隠れ層:60,出力層:1 のNNを作成しようとしています
入力データは(60,120)で60次元のデータを120個用意しており,内100個を学習データ,残り20個をテストデータにしています
出力データは(120,1)で1次元データを120個用意し,内100個を学習データ,残り20個をテストデータにしています
これらは,記述コードより前でcsvファイルから読み込み済みです
エラーが出ているのは最後の行のみです.
##学習を実行 with tf.Session() as sess: init_op = tf.global_variables_initializer() sess.run(init_op) ##学習データを習得 from sklearn.model_selection import train_test_split ##説明変数(入力特徴量) x = DataFrame(input_data) x2 = DataFrame(input_test_data) ##目的変数(評価データ) y = DataFrame(learning_output_data) y2 = DataFrame(learning_test_data) ##説明変数・目的変数をそれぞれ訓練データ・テストデータに分割 train_x = x test_x = x2 train_t = y test_t = y2 #データの整形 train_x = train_x.astype(np.float) test_x = test_x.astype(np.float) train_t = keras.utils.to_categorical(train_t) test_t = keras.utils.to_categorical(test_t) ##ミニバッチ学習 num_epoch = 10000 num_data = train_x.shape[0] batch_size = 10 for epoch in range(num_epoch): sff_idx = np.random.permutation(num_data) for idx in range(0, num_data, batch_size): batch_x = train_x[sff_idx[idx: idx + batch_size]] batch_t = train_t[sff_idx[idx: idx + batch_size]] sess.run(train_step, feed_dict = {X: batch_x, t: batch_t})
補足情報
jupyter notebook 使用
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/25 01:03