質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

0回答

2985閲覧

Keras LSTM 学習のloss,val_lossが変化しない場合がある Deep Learning

Dpulex

総合スコア9

Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

1グッド

1クリップ

投稿2020/03/14 15:45

編集2022/01/12 10:55

前提・実現したいこと

Kerasを用いてLSTMを動かしているのですが、学習がうまくいく場合とうまくいかない場合が存在するのですが、
なぜムラが存在するのかがわからないです。loss,val_lossの部分が全く変化しない時が存在します。

追記:
学習が成功している方はかなり省略していますが、どちらの場合でもloss: - mse: - val_loss: - val_mse: の値が固定されている以外は同じような表記のされ方でターミナルに書かれています。

発生している問題・エラーメッセージ

学習が成功していると思われる場合 5834/5834 [==============================] - 2s 284us/step - loss: 0.0241 - mse: 0.0241 - val_loss: 0.0049 - val_mse: 0.0049 Epoch 2/200 5834/5834 [==============================] - 1s 142us/step - loss: 0.0023 - mse: 0.0023 - val_loss: 9.0606e-04 - val_mse: 9.0606e-04 学習が上手く行っていないと考えられる場合 Using TensorFlow backend. lstm112-2.py:50: RuntimeWarning: invalid value encountered in true_divide x_train = (x_train - mi)/(ma - mi) lstm112-2.py:52: RuntimeWarning: invalid value encountered in true_divide y_train = (y_train - mi)/(ma - mi) 2020-03-15 00:34:13.169460: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA 2020-03-15 00:34:13.206396: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7f84e82c36a0 initialized for platform Host (this does not guarantee that XLA will be used). Devices: 2020-03-15 00:34:13.206414: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version [<tf.Tensor 'activation_1/Relu:0' shape=(None, 5, 1) dtype=float32>] Model: "sequential_1" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= bidirectional_1 (Bidirection (None, 5, 256) 133120 _________________________________________________________________ dense_1 (Dense) (None, 5, 1) 257 _________________________________________________________________ activation_1 (Activation) (None, 5, 1) 0 ================================================================= Total params: 133,377 Trainable params: 133,377 Non-trainable params: 0 _________________________________________________________________ None Train on 5834 samples, validate on 1459 samples Epoch 1/200 2020-03-15 00:34:14.473405: E tensorflow/core/grappler/optimizers/meta_optimizer.cc:561] remapper failed: Invalid argument: MutableGraphView::MutableGraphView error: node 'loss/activation_1_loss/mean_squared_error/weighted_loss/concat' has self cycle fanin 'loss/activation_1_loss/mean_squared_error/weighted_loss/concat'. 2020-03-15 00:34:14.486520: E tensorflow/core/grappler/optimizers/dependency_optimizer.cc:717] Iteration = 0, topological sort failed with message: The graph couldn't be sorted in topological order. 2020-03-15 00:34:14.492424: E tensorflow/core/grappler/optimizers/dependency_optimizer.cc:717] Iteration = 1, topological sort failed with message: The graph couldn't be sorted in topological order. 2020-03-15 00:34:14.549041: E tensorflow/core/grappler/optimizers/meta_optimizer.cc:561] arithmetic_optimizer failed: Invalid argument: The graph couldn't be sorted in topological order. 2020-03-15 00:34:14.552868: E tensorflow/core/grappler/optimizers/meta_optimizer.cc:561] remapper failed: Invalid argument: MutableGraphView::MutableGraphView error: node 'loss/activation_1_loss/mean_squared_error/weighted_loss/concat' has self cycle fanin 'loss/activation_1_loss/mean_squared_error/weighted_loss/concat'. 2020-03-15 00:34:14.557423: E tensorflow/core/grappler/optimizers/dependency_optimizer.cc:717] Iteration = 0, topological sort failed with message: The graph couldn't be sorted in topological order. 2020-03-15 00:34:14.561990: E tensorflow/core/grappler/optimizers/dependency_optimizer.cc:717] Iteration = 1, topological sort failed with message: The graph couldn't be sorted in topological order. 2020-03-15 00:34:14.579734: W tensorflow/core/common_runtime/process_function_library_runtime.cc:697] Ignoring multi-device function optimization failure: Invalid argument: The graph couldn't be sorted in topological order. 5600/5834 [===========================>..] - ETA: 0s - loss: 0.1171 - mse: 0.11712020-03-15 00:34:15.622048: E tensorflow/core/grappler/optimizers/meta_optimizer.cc:561] remapper failed: Invalid argument: MutableGraphView::MutableGraphView error: node 'loss/activation_1_loss/mean_squared_error/weighted_loss/concat' has self cycle fanin 'loss/activation_1_loss/mean_squared_error/weighted_loss/concat'. 2020-03-15 00:34:15.624523: E tensorflow/core/grappler/optimizers/dependency_optimizer.cc:717] Iteration = 0, topological sort failed with message: The graph couldn't be sorted in topological order. 2020-03-15 00:34:15.625641: E tensorflow/core/grappler/optimizers/dependency_optimizer.cc:717] Iteration = 1, topological sort failed with message: The graph couldn't be sorted in topological order. 2020-03-15 00:34:15.635130: E tensorflow/core/grappler/optimizers/meta_optimizer.cc:561] arithmetic_optimizer failed: Invalid argument: The graph couldn't be sorted in topological order. 2020-03-15 00:34:15.635882: E tensorflow/core/grappler/optimizers/meta_optimizer.cc:561] remapper failed: Invalid argument: MutableGraphView::MutableGraphView error: node 'loss/activation_1_loss/mean_squared_error/weighted_loss/concat' has self cycle fanin 'loss/activation_1_loss/mean_squared_error/weighted_loss/concat'. 2020-03-15 00:34:15.636640: E tensorflow/core/grappler/optimizers/dependency_optimizer.cc:717] Iteration = 0, topological sort failed with message: The graph couldn't be sorted in topological order. 2020-03-15 00:34:15.637402: E tensorflow/core/grappler/optimizers/dependency_optimizer.cc:717] Iteration = 1, topological sort failed with message: The graph couldn't be sorted in topological order. 2020-03-15 00:34:15.642129: W tensorflow/core/common_runtime/process_function_library_runtime.cc:697] Ignoring multi-device function optimization failure: Invalid argument: The graph couldn't be sorted in topological order. 5834/5834 [==============================] - 2s 279us/step - loss: 0.1172 - mse: 0.1172 - val_loss: 0.1182 - val_mse: 0.1182 Epoch 2/200 5834/5834 [==============================] - 1s 140us/step - loss: 0.1172 - mse: 0.1172 - val_loss: 0.1182 - val_mse: 0.1182

該当のソースコード

python3

1#coding:utf-8 2import csv 3import re 4import datetime 5import time 6import numpy as np 7import pandas as pd 8import math 9import pylab 10import os 11import os.path 12import matplotlib.pyplot as plt 13from keras.models import Sequential 14from keras.layers.core import Dense, Activation 15from keras.layers.recurrent import LSTM 16from keras.layers.wrappers import Bidirectional 17from keras.models import Model 18from keras.optimizers import Adam 19from keras.callbacks import EarlyStopping 20from keras.layers import Input, LSTM, GRU, RepeatVector 21from keras.layers.core import Dense, Lambda 22from keras import objectives 23from sklearn import datasets 24from sklearn.model_selection import train_test_split 25from sklearn.utils import shuffle 26from sklearn.utils import shuffle 27from keras import initializers 28from sklearn import preprocessing 29from sklearn.metrics import roc_curve, auc 30 31data = np.loadtxt("./data/main.csv",delimiter=",") 32x = data[:,:5] 33y = data[:,:5] 34c = len(data[0]) - 1 35df = pd.read_csv("./data/main.csv",delimiter=",") 36length = len(df.index) 37x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42) 38 39mi = x_train.min(axis=0, keepdims=True) 40ma = x_train.max(axis=0, keepdims=True) 41 42x_train = (x_train - mi)/(ma - mi) 43x_train[np.isnan(x_train)] = 0 44y_train = (y_train - mi)/(ma - mi) 45y_train[np.isnan(y_train)] = 0 46 47x_train = x_train.reshape(-1, c, 1) 48y_train = y_train.reshape(-1, c, 1) 49 50x_train, x_valid, y_train, y_valid = \ 51 train_test_split(x_train, y_train, test_size=0.2) 52 53''' 54モデル設定 55''' 56n_in = 1 57n_long = c 58n_hidden = 128 59n_out = 1 60 61early_stopping = EarlyStopping(monitor='val_mse', patience=30, verbose=1) 62 63model = Sequential() 64model.add(Bidirectional(LSTM(n_hidden,return_sequences = True), 65 input_shape=(n_long,n_in))) 66model.add(Dense(n_out, kernel_initializer=initializers.random_normal())) 67model.add(Activation('relu')) 68 69model.compile(loss='mean_squared_error', 70 optimizer=Adam(lr=0.001, beta_1=0.9, beta_2=0.999), 71 metrics=['mse']) 72print(model.outputs) 73print(model.summary()) 74 75''' 76モデル学習 77''' 78 79epochs = 200 80batch_size = 50 81 82hist = model.fit(x_train, y_train, 83 batch_size=batch_size, 84 epochs=epochs, 85 validation_data=(x_valid, y_valid), 86 callbacks=[early_stopping]) 87
s.k👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問