質問編集履歴

5

エラー修正

2021/06/09 00:27

投稿

MagMag
MagMag

スコア80

test CHANGED
File without changes
test CHANGED
@@ -68,97 +68,71 @@
68
68
 
69
69
  ```
70
70
 
71
- 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)
72
71
 
73
- 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)
74
72
 
75
- 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)
73
+ 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)
74
+
75
+ 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)
76
+
77
+ 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)
76
78
 
77
79
  Traceback (most recent call last):
78
80
 
79
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
81
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
80
82
 
81
83
  exec(code_obj, self.user_global_ns, self.user_ns)
82
84
 
83
- File "<ipython-input-2-24da7a158fe8>", line 120, in <module>
85
+ File "<ipython-input-2-b0d746f88011>", line 1, in <module>
84
86
 
85
- y_cv = cross_val_predict(estimator, autoscaled_X, y, cv=cv, groups=list_group)
87
+ runfile('/Users/***/Documents/Projects/20210420/modeling_with_NN.py', wdir='/Users/***/Documents/Projects/20210420')
86
88
 
87
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/sklearn/utils/validation.py", line 72, in inner_f
89
+ File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
88
90
 
89
- return f(**kwargs)
91
+ pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
90
92
 
91
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/sklearn/model_selection/_validation.py", line 773, in cross_val_predict
93
+ File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
92
94
 
93
- for train, test in cv.split(X, y, groups))
95
+ exec(compile(contents+"\n", file, 'exec'), glob, loc)
94
96
 
95
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 1041, in __call__
97
+ File "/Users/***/Documents/Projects/20210420/modeling_with_NN.py", line 120, in <module>
96
98
 
97
- if self.dispatch_one_batch(iterator):
99
+ estimator.fit(X_prepaired, y)
98
100
 
99
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 859, in dispatch_one_batch
100
-
101
- self._dispatch(tasks)
102
-
103
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 777, in _dispatch
104
-
105
- job = self._backend.apply_async(batch, callback=cb)
106
-
107
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/_parallel_backends.py", line 208, in apply_async
108
-
109
- result = ImmediateResult(func)
110
-
111
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/_parallel_backends.py", line 572, in __init__
112
-
113
- self.results = batch()
114
-
115
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 263, in __call__
116
-
117
- for func, args, kwargs in self.items]
118
-
119
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 263, in <listcomp>
120
-
121
- for func, args, kwargs in self.items]
122
-
123
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/sklearn/model_selection/_validation.py", line 862, in _fit_and_predict
124
-
125
- estimator.fit(X_train, y_train, **fit_params)
126
-
127
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/keras/wrappers/scikit_learn.py", line 163, in fit
101
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/keras/wrappers/scikit_learn.py", line 163, in fit
128
102
 
129
103
  history = self.model.fit(x, y, **fit_args)
130
104
 
131
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/keras/engine/training.py", line 1158, in fit
105
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/keras/engine/training.py", line 1158, in fit
132
106
 
133
107
  tmp_logs = self.train_function(iterator)
134
108
 
135
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 889, in __call__
109
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 889, in __call__
136
110
 
137
111
  result = self._call(*args, **kwds)
138
112
 
139
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 950, in _call
113
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 950, in _call
140
114
 
141
115
  return self._stateless_fn(*args, **kwds)
142
116
 
143
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 3024, in __call__
117
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 3024, in __call__
144
118
 
145
119
  filtered_flat_args, captured_inputs=graph_function.captured_inputs) # pylint: disable=protected-access
146
120
 
147
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 1961, in _call_flat
121
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 1961, in _call_flat
148
122
 
149
123
  ctx, args, cancellation_manager=cancellation_manager))
150
124
 
151
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 596, in call
125
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 596, in call
152
126
 
153
127
  ctx=ctx)
154
128
 
155
- File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/execute.py", line 60, in quick_execute
129
+ File "/Users/***/Documents/Projects/20210420/venv/lib/python3.7/site-packages/tensorflow/python/eager/execute.py", line 60, in quick_execute
156
130
 
157
131
  inputs, attrs, num_outputs)
158
132
 
159
133
  tensorflow.python.framework.errors_impl.InvalidArgumentError: Invalid reduction dimension (1 for input with 0 dimension(s)
160
134
 
161
- [[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]
135
+ [[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]
162
136
 
163
137
  Function call stack:
164
138
 

4

質問をシンプルに

2021/06/09 00:27

投稿

MagMag
MagMag

スコア80

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,4 @@
1
- Kerasにおいて、自作の損失関数(Spearmanの順相関係数)でモデリング構築したいのですが、以下のエラーが発生してしまいます。
1
+ Kerasにおいて、自作の損失関数(Spearmanの順相関係数)でモデリング構築したいのですが、学習時(estimator.fit実行時)に以下のエラーが発生してしまいます。
2
2
 
3
3
 
4
4
 
@@ -56,15 +56,9 @@
56
56
 
57
57
 
58
58
 
59
- # GroupKFold設定のため、Groupカテゴリを作成
60
-
61
- list_group = pd.factorize(ser_product)[0].tolist()
62
-
63
- cv = GroupKFold(n_splits=len(set(list_group)))
64
-
65
59
  estimator = KerasRegressor(build_fn=reg_model, epochs=100, batch_size=10, verbose=0)
66
60
 
67
- scores = cross_val_score(estimator, autoscaled_X, y, cv=cv, groups=list_group)
61
+ estimator.fit(X_prepaired, y)
68
62
 
69
63
  ```
70
64
 

3

文言修正

2021/06/09 00:23

投稿

MagMag
MagMag

スコア80

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

2

エラー修正

2021/06/08 00:51

投稿

MagMag
MagMag

スコア80

test CHANGED
File without changes
test CHANGED
@@ -82,17 +82,91 @@
82
82
 
83
83
  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)
84
84
 
85
+ Traceback (most recent call last):
85
86
 
87
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3437, in run_code
86
88
 
87
- Tracebck(....)
89
+ exec(code_obj, self.user_global_ns, self.user_ns)
88
90
 
91
+ File "<ipython-input-2-24da7a158fe8>", line 120, in <module>
89
92
 
93
+ y_cv = cross_val_predict(estimator, autoscaled_X, y, cv=cv, groups=list_group)
90
94
 
91
- tensorflow.python.framework.errors_impl.InvalidArgumentError:
95
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/sklearn/utils/validation.py", line 72, in inner_f
92
96
 
93
- Invalid reduction dimension (1 for input with 0 dimension(s)
97
+ return f(**kwargs)
94
98
 
95
- [[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]
99
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/sklearn/model_selection/_validation.py", line 773, in cross_val_predict
100
+
101
+ for train, test in cv.split(X, y, groups))
102
+
103
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 1041, in __call__
104
+
105
+ if self.dispatch_one_batch(iterator):
106
+
107
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 859, in dispatch_one_batch
108
+
109
+ self._dispatch(tasks)
110
+
111
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 777, in _dispatch
112
+
113
+ job = self._backend.apply_async(batch, callback=cb)
114
+
115
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/_parallel_backends.py", line 208, in apply_async
116
+
117
+ result = ImmediateResult(func)
118
+
119
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/_parallel_backends.py", line 572, in __init__
120
+
121
+ self.results = batch()
122
+
123
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 263, in __call__
124
+
125
+ for func, args, kwargs in self.items]
126
+
127
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/joblib/parallel.py", line 263, in <listcomp>
128
+
129
+ for func, args, kwargs in self.items]
130
+
131
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/sklearn/model_selection/_validation.py", line 862, in _fit_and_predict
132
+
133
+ estimator.fit(X_train, y_train, **fit_params)
134
+
135
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/keras/wrappers/scikit_learn.py", line 163, in fit
136
+
137
+ history = self.model.fit(x, y, **fit_args)
138
+
139
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/keras/engine/training.py", line 1158, in fit
140
+
141
+ tmp_logs = self.train_function(iterator)
142
+
143
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 889, in __call__
144
+
145
+ result = self._call(*args, **kwds)
146
+
147
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 950, in _call
148
+
149
+ return self._stateless_fn(*args, **kwds)
150
+
151
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 3024, in __call__
152
+
153
+ filtered_flat_args, captured_inputs=graph_function.captured_inputs) # pylint: disable=protected-access
154
+
155
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 1961, in _call_flat
156
+
157
+ ctx, args, cancellation_manager=cancellation_manager))
158
+
159
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 596, in call
160
+
161
+ ctx=ctx)
162
+
163
+ File "/Users/***/Documents/Projects/20210420AI/venv/lib/python3.7/site-packages/tensorflow/python/eager/execute.py", line 60, in quick_execute
164
+
165
+ inputs, attrs, num_outputs)
166
+
167
+ tensorflow.python.framework.errors_impl.InvalidArgumentError: Invalid reduction dimension (1 for input with 0 dimension(s)
168
+
169
+ [[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]
96
170
 
97
171
  Function call stack:
98
172
 

1

エラーの追記

2021/06/08 00:48

投稿

MagMag
MagMag

スコア80

test CHANGED
File without changes
test CHANGED
@@ -76,6 +76,18 @@
76
76
 
77
77
  ```
78
78
 
79
+ 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)
80
+
81
+ 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)
82
+
83
+ 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)
84
+
85
+
86
+
87
+ Tracebck(....)
88
+
89
+
90
+
79
91
  tensorflow.python.framework.errors_impl.InvalidArgumentError:
80
92
 
81
93
  Invalid reduction dimension (1 for input with 0 dimension(s)