teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

5

エラー修正

2021/06/09 00:27

投稿

MagMag
MagMag

スコア80

title CHANGED
File without changes
body CHANGED
@@ -33,52 +33,39 @@
33
33
 
34
34
  ### エラー内容
35
35
  ```
36
- 2021-06-04 09:37:59.938446: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:176] None of the MLIR Optimization Passes are enabled (registered 2)
37
- 2021-06-04 09:38:09.932287: W tensorflow/core/framework/op_kernel.cc:1767] OP_REQUIRES failed at reduction_ops_common.h:148 : Invalid argument: Invalid reduction dimension (1 for input with 0 dimension(s)
38
- 2021-06-04 09:38:09.932341: W tensorflow/core/framework/op_kernel.cc:1767] OP_REQUIRES failed at reduction_ops_common.h:148 : Invalid argument: Invalid reduction dimension (0 for input with 0 dimension(s)
36
+
37
+ 2021-06-09 09:24:09.395515: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:176] None of the MLIR Optimization Passes are enabled (registered 2)
38
+ 2021-06-09 09:24:20.065805: W tensorflow/core/framework/op_kernel.cc:1767] OP_REQUIRES failed at reduction_ops_common.h:148 : Invalid argument: Invalid reduction dimension (1 for input with 0 dimension(s)
39
+ 2021-06-09 09:24:20.065830: W tensorflow/core/framework/op_kernel.cc:1767] OP_REQUIRES failed at reduction_ops_common.h:148 : Invalid argument: Invalid reduction dimension (0 for input with 0 dimension(s)
39
40
  Traceback (most recent call last):
40
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
41
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
41
42
  exec(code_obj, self.user_global_ns, self.user_ns)
42
- File "<ipython-input-2-24da7a158fe8>", line 120, in <module>
43
+ File "<ipython-input-2-b0d746f88011>", line 1, in <module>
43
- y_cv = cross_val_predict(estimator, autoscaled_X, y, cv=cv, groups=list_group)
44
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/sklearn/utils/validation.py", line 72, in inner_f
45
- return f(**kwargs)
46
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/sklearn/model_selection/_validation.py", line 773, in cross_val_predict
47
- for train, test in cv.split(X, y, groups))
48
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 1041, in __call__
44
+ runfile('/Users/***/Documents/Projects/20210420/modeling_with_NN.py', wdir='/Users/***/Documents/Projects/20210420')
49
- if self.dispatch_one_batch(iterator):
50
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 859, in dispatch_one_batch
51
- self._dispatch(tasks)
52
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 777, in _dispatch
45
+ File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
53
- job = self._backend.apply_async(batch, callback=cb)
46
+ pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
54
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/_parallel_backends.py", line 208, in apply_async
55
- result = ImmediateResult(func)
56
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/_parallel_backends.py", line 572, in __init__
57
- self.results = batch()
58
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 263, in __call__
47
+ File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
59
- for func, args, kwargs in self.items]
48
+ exec(compile(contents+"\n", file, 'exec'), glob, loc)
60
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 263, in <listcomp>
49
+ File "/Users/***/Documents/Projects/20210420/modeling_with_NN.py", line 120, in <module>
61
- for func, args, kwargs in self.items]
62
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/sklearn/model_selection/_validation.py", line 862, in _fit_and_predict
63
- estimator.fit(X_train, y_train, **fit_params)
50
+ estimator.fit(X_prepaired, y)
64
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/keras/wrappers/scikit_learn.py", line 163, in fit
51
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/keras/wrappers/scikit_learn.py", line 163, in fit
65
52
  history = self.model.fit(x, y, **fit_args)
66
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/keras/engine/training.py", line 1158, in fit
53
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/keras/engine/training.py", line 1158, in fit
67
54
  tmp_logs = self.train_function(iterator)
68
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 889, in __call__
55
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 889, in __call__
69
56
  result = self._call(*args, **kwds)
70
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 950, in _call
57
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 950, in _call
71
58
  return self._stateless_fn(*args, **kwds)
72
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 3024, in __call__
59
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 3024, in __call__
73
60
  filtered_flat_args, captured_inputs=graph_function.captured_inputs) # pylint: disable=protected-access
74
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 1961, in _call_flat
61
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 1961, in _call_flat
75
62
  ctx, args, cancellation_manager=cancellation_manager))
76
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 596, in call
63
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 596, in call
77
64
  ctx=ctx)
78
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/execute.py", line 60, in quick_execute
65
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/tensorflow/python/eager/execute.py", line 60, in quick_execute
79
66
  inputs, attrs, num_outputs)
80
67
  tensorflow.python.framework.errors_impl.InvalidArgumentError: Invalid reduction dimension (1 for input with 0 dimension(s)
81
- [[node gradient_tape/sequential/dense_2/BiasAdd/Sum (defined at /Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/keras/engine/training.py:774) ]] [Op:__inference_train_function_602]
68
+ [[node gradient_tape/sequential/dense_2/BiasAdd/Sum (defined at /Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/keras/engine/training.py:774) ]] [Op:__inference_train_function_600]
82
69
  Function call stack:
83
70
  train_function
84
71
  ```

4

質問をシンプルに

2021/06/09 00:27

投稿

MagMag
MagMag

スコア80

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,4 @@
1
- Kerasにおいて、自作の損失関数(Spearmanの順相関係数)でモデリング構築したいのですが、以下のエラーが発生してしまいます。
1
+ Kerasにおいて、自作の損失関数(Spearmanの順相関係数)でモデリング構築したいのですが、学習時(estimator.fit実行時)に以下のエラーが発生してしまいます。
2
2
 
3
3
  エラー名で検索してもダイレクトに記載されているものが自分としては見つからず、対応方法がわからず(別のサイトでは、他のセッションが動いているとこのエラーを吐くとあったので、一応OSを再起動しましたが、問題再現しました)。アドバイスをいただけないでしょうか?
4
4
 
@@ -27,11 +27,8 @@
27
27
  model.compile(loss=spearman_score, optimizer='adam')
28
28
  return model
29
29
 
30
- # GroupKFold設定のため、Groupカテゴリを作成
31
- list_group = pd.factorize(ser_product)[0].tolist()
32
- cv = GroupKFold(n_splits=len(set(list_group)))
33
30
  estimator = KerasRegressor(build_fn=reg_model, epochs=100, batch_size=10, verbose=0)
34
- scores = cross_val_score(estimator, autoscaled_X, y, cv=cv, groups=list_group)
31
+ estimator.fit(X_prepaired, y)
35
32
  ```
36
33
 
37
34
  ### エラー内容

3

文言修正

2021/06/09 00:23

投稿

MagMag
MagMag

スコア80

title CHANGED
File without changes
body CHANGED
@@ -1,13 +1,12 @@
1
- Kerasにおいて、自作の損失関数Spearmanの順相関係数)も試したいのですが、エラーが発生します。
1
+ Kerasにおいて、自作の損失関数(Spearmanの順相関係数)でモデリング構築したいのですが、以下のエラーが発生してしいます。
2
2
 
3
- エラー名で検索してもらし回答こないのでが、アドバイスをいただけないでしょうか?ちなみに、損失関数部分は以下のリンクを見てコピペして作っています。
3
+ エラー名で検索してもダイレクトに記載さるもの自分としは見つからず、対応方法がわからず(別のサイトでは、他のセッションが動ているとこエラーを吐くとあったの、一応OSを再起動しましたが、問題再現しました)。アドバイスをいただけないでしょうか?
4
4
 
5
+ ちなみに、損失関数部分は以下のリンクを見てコピペして作っています。
5
6
  [StackOverFLlowのリンク](https://stackoverflow.com/questions/53404301/how-to-compute-spearman-correlation-in-tensorflow)
6
7
 
7
- エラー名で検索してもダイレクト記載されていが自分しては見つかず、わかりせんでした。別のサイトでは、他のセッション動いているとこのエラーを吐くとあったので、一応OSを再起動しましたが、問題再現しました
8
+ エラーにreduction dimensionとあるので、途中の層の設定の不備も考えましたが、損失関数をデフォルトにするとエラーは消えました。
8
9
 
9
- エラーにreduction dimensionとあるので、途中の層の設定の不備とも考えられるが、損失関数をデフォルトにするとエラーは消えました。
10
-
11
10
  ### コード
12
11
  ```Python
13
12
  # モジュールやデータ読み込みなど一部省略

2

エラー修正

2021/06/08 00:51

投稿

MagMag
MagMag

スコア80

title CHANGED
File without changes
body CHANGED
@@ -40,12 +40,49 @@
40
40
  2021-06-04 09:37:59.938446: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:176] None of the MLIR Optimization Passes are enabled (registered 2)
41
41
  2021-06-04 09:38:09.932287: W tensorflow/core/framework/op_kernel.cc:1767] OP_REQUIRES failed at reduction_ops_common.h:148 : Invalid argument: Invalid reduction dimension (1 for input with 0 dimension(s)
42
42
  2021-06-04 09:38:09.932341: W tensorflow/core/framework/op_kernel.cc:1767] OP_REQUIRES failed at reduction_ops_common.h:148 : Invalid argument: Invalid reduction dimension (0 for input with 0 dimension(s)
43
-
44
- Tracebck(....)
45
-
46
- tensorflow.python.framework.errors_impl.InvalidArgumentError:
47
- Invalid reduction dimension (1 for input with 0 dimension(s)
48
- [[node gradient_tape/sequential/dense_2/BiasAdd/Sum (defined at /Users/****/Documents/Projects/20210420/venv/lib/python3.7/site-packages/keras/engine/training.py:774) ]] [Op:__inference_train_function_602]
43
+ Traceback (most recent call last):
44
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
45
+ exec(code_obj, self.user_global_ns, self.user_ns)
46
+ File "<ipython-input-2-24da7a158fe8>", line 120, in <module>
47
+ y_cv = cross_val_predict(estimator, autoscaled_X, y, cv=cv, groups=list_group)
48
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/sklearn/utils/validation.py", line 72, in inner_f
49
+ return f(**kwargs)
50
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/sklearn/model_selection/_validation.py", line 773, in cross_val_predict
51
+ for train, test in cv.split(X, y, groups))
52
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 1041, in __call__
53
+ if self.dispatch_one_batch(iterator):
54
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 859, in dispatch_one_batch
55
+ self._dispatch(tasks)
56
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 777, in _dispatch
57
+ job = self._backend.apply_async(batch, callback=cb)
58
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/_parallel_backends.py", line 208, in apply_async
59
+ result = ImmediateResult(func)
60
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/_parallel_backends.py", line 572, in __init__
61
+ self.results = batch()
62
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 263, in __call__
63
+ for func, args, kwargs in self.items]
64
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 263, in <listcomp>
65
+ for func, args, kwargs in self.items]
66
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/sklearn/model_selection/_validation.py", line 862, in _fit_and_predict
67
+ estimator.fit(X_train, y_train, **fit_params)
68
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/keras/wrappers/scikit_learn.py", line 163, in fit
69
+ history = self.model.fit(x, y, **fit_args)
70
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/keras/engine/training.py", line 1158, in fit
71
+ tmp_logs = self.train_function(iterator)
72
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 889, in __call__
73
+ result = self._call(*args, **kwds)
74
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 950, in _call
75
+ return self._stateless_fn(*args, **kwds)
76
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 3024, in __call__
77
+ filtered_flat_args, captured_inputs=graph_function.captured_inputs) # pylint: disable=protected-access
78
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 1961, in _call_flat
79
+ ctx, args, cancellation_manager=cancellation_manager))
80
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 596, in call
81
+ ctx=ctx)
82
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/execute.py", line 60, in quick_execute
83
+ inputs, attrs, num_outputs)
84
+ tensorflow.python.framework.errors_impl.InvalidArgumentError: Invalid reduction dimension (1 for input with 0 dimension(s)
85
+ [[node gradient_tape/sequential/dense_2/BiasAdd/Sum (defined at /Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/keras/engine/training.py:774) ]] [Op:__inference_train_function_602]
49
86
  Function call stack:
50
87
  train_function
51
88
  ```

1

エラーの追記

2021/06/08 00:48

投稿

MagMag
MagMag

スコア80

title CHANGED
File without changes
body CHANGED
@@ -37,6 +37,12 @@
37
37
 
38
38
  ### エラー内容
39
39
  ```
40
+ 2021-06-04 09:37:59.938446: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:176] None of the MLIR Optimization Passes are enabled (registered 2)
41
+ 2021-06-04 09:38:09.932287: W tensorflow/core/framework/op_kernel.cc:1767] OP_REQUIRES failed at reduction_ops_common.h:148 : Invalid argument: Invalid reduction dimension (1 for input with 0 dimension(s)
42
+ 2021-06-04 09:38:09.932341: W tensorflow/core/framework/op_kernel.cc:1767] OP_REQUIRES failed at reduction_ops_common.h:148 : Invalid argument: Invalid reduction dimension (0 for input with 0 dimension(s)
43
+
44
+ Tracebck(....)
45
+
40
46
  tensorflow.python.framework.errors_impl.InvalidArgumentError:
41
47
  Invalid reduction dimension (1 for input with 0 dimension(s)
42
48
  [[node gradient_tape/sequential/dense_2/BiasAdd/Sum (defined at /Users/****/Documents/Projects/20210420/venv/lib/python3.7/site-packages/keras/engine/training.py:774) ]] [Op:__inference_train_function_602]