質問編集履歴

2

情報の修正

2018/11/10 13:50

投稿

taiyo2017
taiyo2017

スコア170

test CHANGED
@@ -1 +1 @@
1
- ValueError: could not broadcast input array from shape (4,104) into shape (4)
1
+ ValueError: could not broadcast input array from shape (3,10) into shape (3)
test CHANGED
@@ -1,3 +1,3 @@
1
1
  TensorFlowとtflearnを使い、ネットワークを構築しています。
2
2
 
3
- ValueError: could not broadcast input array from shape (4,104) into shape (4) とエラーがでました。
3
+ ValueError: could not broadcast input array from shape (3,10) into shape (3) とエラーがでました。

1

情報の修正

2018/11/10 13:50

投稿

taiyo2017
taiyo2017

スコア170

test CHANGED
File without changes
test CHANGED
@@ -1,251 +1,3 @@
1
1
  TensorFlowとtflearnを使い、ネットワークを構築しています。
2
2
 
3
3
  ValueError: could not broadcast input array from shape (4,104) into shape (4) とエラーがでました。
4
-
5
- Tracebackには、
6
-
7
-
8
-
9
- ```ここに言語を入力
10
-
11
- ---------------------------------
12
-
13
- Run id: 2YMAQR
14
-
15
- Log directory: /tmp/tflearn_logs/
16
-
17
- Traceback (most recent call last):
18
-
19
- File "cnn.py", line 181, in <module>
20
-
21
- model.fit(trainDataSet, trainLabel, n_epoch=100, batch_size=32, validation_set=0.1, show_metric=True)
22
-
23
- File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tflearn/models/dnn.py", line 216, in fit
24
-
25
- callbacks=callbacks)
26
-
27
- File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tflearn/helpers/trainer.py", line 269, in fit
28
-
29
- for d in feed_dicts: standarize_dict(d)
30
-
31
- File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/tflearn/utils.py", line 160, in standarize_dict
32
-
33
- d[key] = np.asarray(d[key])
34
-
35
- File "/Users/xxx/anaconda/xxx/lib/python2.7/site-packages/numpy/core/numeric.py", line 501, in asarray
36
-
37
- return array(a, dtype, copy=False, order=order)
38
-
39
- ValueError: could not broadcast input array from shape (4,104) into shape (4)
40
-
41
- ```
42
-
43
- と出ました。
44
-
45
-
46
-
47
- ```ここに言語を入力
48
-
49
- import tensorflow as tf
50
-
51
- import tflearn
52
-
53
-
54
-
55
- from tflearn.layers.core import input_data,dropout,fully_connected
56
-
57
- from tflearn.layers.conv import conv_2d, max_pool_2d
58
-
59
- from tflearn.layers.normalization import local_response_normalization
60
-
61
- from tflearn.layers.estimator import regression
62
-
63
-
64
-
65
- tf.reset_default_graph()
66
-
67
- net = input_data(shape=[32, 4, 104, 1])
68
-
69
- net = conv_3d(net, 4, 16, activation='relu')
70
-
71
- net = max_pool_3d(net, 1)
72
-
73
- net = tflearn.activations.relu(net)
74
-
75
- net = dropout(net, 0.5)
76
-
77
- net = tflearn.fully_connected(net, 10, activation='softmax')
78
-
79
- net = tflearn.regression(net, optimizer='adam', learning_rate=0.5, loss='categorical_crossentropy')
80
-
81
-
82
-
83
- model = tflearn.DNN(net)
84
-
85
- model.fit(trainDataSet, trainLabel, n_epoch=100, batch_size=32, validation_set=0.1, show_metric=True)
86
-
87
-
88
-
89
- pred = np.array(model.predict(testDataSet).argmax(axis=1))
90
-
91
-
92
-
93
- label = testLabel.argmax(axis=1)
94
-
95
- accuracy = np.mean(pred == label, axis=0)
96
-
97
-
98
-
99
- print(accuracy)
100
-
101
- ```
102
-
103
- とコードを書きました。
104
-
105
- ```ここに言語を入力
106
-
107
- model.fit(trainDataSet, trainLabel, n_epoch=100, batch_size=32, validation_set=0.1, show_metric=True)
108
-
109
- ```
110
-
111
- の行でエラーが出ています。
112
-
113
-
114
-
115
- trainDataSetには
116
-
117
- ```ここに言語を入力
118
-
119
- [array([[0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
120
-
121
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
122
-
123
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0. ,
124
-
125
- 1. , 0. , 1. , 0. , 1. , 1. , 0. , 0. , 0. , 0. , 1. ,
126
-
127
- 0. , 0. , 0. , 0. , 0. , 0. , 1. , 1. , 0. , 0. , 0. ,
128
-
129
- 1. , 0. , 1. , 0. , 0. , 1. , 0. , 0. , 1. , 0. , 1. ,
130
-
131
- 1. , 1. , 0. , 0. , 0. , 0. , 0.25, 0.25, 0.25, 0.25, 0.25,
132
-
133
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
134
-
135
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
136
-
137
- 0.25, 0.25, 0.25, 0.25, 0.25],
138
-
139
- [0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
140
-
141
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
142
-
143
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0. ,
144
-
145
- 0. , 1. , 0. , 1. , 0. , 0. , 0. , 0. , 0. , 1. , 0. ,
146
-
147
- 1. , 1. , 1. , 0. , 1. , 0. , 0. , 0. , 1. , 1. , 1. ,
148
-
149
- 0. , 1. , 0. , 0. , 1. , 0. , 0. , 1. , 0. , 1. , 0. ,
150
-
151
- 0. , 0. , 0. , 1. , 1. , 0. , 0.25, 0.25, 0.25, 0.25, 0.25,
152
-
153
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
154
-
155
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
156
-
157
- 0.25, 0.25, 0.25, 0.25, 0.25],
158
-
159
- [0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
160
-
161
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
162
-
163
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0. ,
164
-
165
- 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 1. , 0. , 0. ,
166
-
167
- 0. , 0. , 0. , 0. , 0. , 1. , 0. , 0. , 0. , 0. , 0. ,
168
-
169
- 0. , 0. , 0. , 1. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,
170
-
171
- 0. , 0. , 1. , 0. , 0. , 1. , 0.25, 0.25, 0.25, 0.25, 0.25,
172
-
173
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
174
-
175
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
176
-
177
- 0.25, 0.25, 0.25, 0.25, 0.25],
178
-
179
- [0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
180
-
181
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
182
-
183
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 1. ,
184
-
185
- 0. , 0. , 0. , 0. , 0. , 0. , 1. , 1. , 0. , 0. , 0. ,
186
-
187
- 0. , 0. , 0. , 1. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,
188
-
189
- 0. , 0. , 0. , 0. , 0. , 0. , 1. , 0. , 0. , 0. , 0. ,
190
-
191
- 0. , 0. , 0. , 0. , 0. , 0. , 0.25, 0.25, 0.25, 0.25, 0.25,
192
-
193
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
194
-
195
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
196
-
197
- 0.25, 0.25, 0.25, 0.25, 0.25]],
198
-
199
-     ・
200
-
201
-     ・
202
-
203
-     ・
204
-
205
- dtype=float32), array([[0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
206
-
207
- 0.25, 0.25, 0.25, 1. , 0. , 0. , 1. , 0. , 0. , 0. , 0. ,
208
-
209
- 0. , 0. , 1. , 0. , 0. , 0. , 0.25, 0.25, 0.25, 0.25, 0.25,
210
-
211
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25],
212
-
213
- [0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
214
-
215
- 0.25, 0.25, 0.25, 0. , 0. , 0. , 0. , 1. , 1. , 1. , 1. ,
216
-
217
- 0. , 0. , 0. , 0. , 0. , 0. , 0.25, 0.25, 0.25, 0.25, 0.25,
218
-
219
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25],
220
-
221
- [0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
222
-
223
- 0.25, 0.25, 0.25, 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ,
224
-
225
- 1. , 0. , 0. , 0. , 0. , 0. , 0.25, 0.25, 0.25, 0.25, 0.25,
226
-
227
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25],
228
-
229
- [0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
230
-
231
- 0.25, 0.25, 0.25, 0. , 1. , 1. , 0. , 0. , 0. , 0. , 0. ,
232
-
233
- 0. , 1. , 0. , 1. , 1. , 1. , 0.25, 0.25, 0.25, 0.25, 0.25,
234
-
235
- 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25]],
236
-
237
- dtype=float32)]
238
-
239
- ```
240
-
241
- のようなarrayが入っていて、trainLabelには
242
-
243
- ```ここに言語を入力
244
-
245
- [array(1), array(1), ・・・ array(0), array(1)]
246
-
247
- ```
248
-
249
- のようにラベルが入っています。
250
-
251
- 何が原因でエラーが引き起こされるのかわかりません。どのようにコードを修正したらいいでしょうか?