質問編集履歴
1
エラー内容が変わった
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
invalid index to scalar variable.の解決
|
test
CHANGED
@@ -65,3 +65,167 @@
|
|
65
65
|
最後の行でエラーが出ているのですが解決方法がわかりません。
|
66
66
|
|
67
67
|
どなたかわかるかたいらっしゃったらお願いします。
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
#追記
|
74
|
+
|
75
|
+
(題名変えました)
|
76
|
+
|
77
|
+
前半に続くコードです。
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
def create_model():
|
82
|
+
|
83
|
+
model = models.Sequential()
|
84
|
+
|
85
|
+
model.add(layers.Conv2D(32, (3, 3), padding='same', activation='relu', input_shape=(28, 28, 1)))
|
86
|
+
|
87
|
+
model.add(layers.MaxPooling2D((2, 2), padding='same'))
|
88
|
+
|
89
|
+
model.add(layers.Conv2D(16, (3, 3), padding='same', activation='relu'))
|
90
|
+
|
91
|
+
model.add(layers.MaxPooling2D((2, 2), padding='same'))
|
92
|
+
|
93
|
+
model.add(layers.Conv2D(8, (3, 3), padding='same', activation='relu'))
|
94
|
+
|
95
|
+
model.add(layers.MaxPooling2D((2, 2), padding='same'))
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
model.add(layers.Conv2D(8, (3, 3), padding='same', activation='relu'))
|
100
|
+
|
101
|
+
model.add(layers.UpSampling2D((2, 2)))
|
102
|
+
|
103
|
+
model.add(layers.Conv2D(16, (3, 3), padding='same', activation='relu'))
|
104
|
+
|
105
|
+
model.add(layers.UpSampling2D((2, 2)))
|
106
|
+
|
107
|
+
model.add(layers.Conv2D(32, (3, 3), activation='relu'))
|
108
|
+
|
109
|
+
model.add(layers.UpSampling2D((2, 2)))
|
110
|
+
|
111
|
+
model.add(layers.Conv2D(1, (3, 3), padding='same', activation='sigmoid'))
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
model.compile(loss='binary_crossentropy', optimizer='sgd')
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
return model
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
model = create_model()
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
def show_result(j):
|
128
|
+
|
129
|
+
results = model.predict(test_images_noisy_2[j:j+10])
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
fig = plt.figure(figsize=(16, 2.7))
|
134
|
+
|
135
|
+
for i in range(10):
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
subplot = fig.add_subplot(3, 10, i+1)
|
140
|
+
|
141
|
+
subplot.set_xticks([])
|
142
|
+
|
143
|
+
subplot.set_yticks([])
|
144
|
+
|
145
|
+
subplot.imshow(test_images_noisy_2[j+i, :, :, 0],
|
146
|
+
|
147
|
+
vmin=0, vmax=1, cmap=plt.cm.gray_r)
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
subplot = fig.add_subplot(3, 10, i+11)
|
154
|
+
|
155
|
+
subplot.set_xticks([])
|
156
|
+
|
157
|
+
subplot.set_yticks([])
|
158
|
+
|
159
|
+
subplot.imshow(results[i, :, :, 0],
|
160
|
+
|
161
|
+
vmin=0, vmax=1, cmap=plt.cm.gray_r)
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
subplot = fig.add_subplot(3, 10, i+21)
|
168
|
+
|
169
|
+
subplot.set_xticks([])
|
170
|
+
|
171
|
+
subplot.set_yticks([])
|
172
|
+
|
173
|
+
subplot.imshow(np.abs(test_images_noisy_2[j+i, :, :, 0]-results[i, :, :, 0]),
|
174
|
+
|
175
|
+
vmin=0, vmax=1, cmap=plt.cm.gray_r)
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
train_num = 10
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
learn = model.fit(train_images[:30000], train_images[:30000], batch_size=16, epochs=1)
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
model.save('cnn_auto_model_noisy.h5')
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
#実行結果
|
198
|
+
|
199
|
+
ここでshow_result(0)で実行すると
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
runfile('C:/Users/user/.spyder-py3/untitled6.py', wdir='C:/Users/user/.spyder-py3')
|
204
|
+
|
205
|
+
Epoch 1/1
|
206
|
+
|
207
|
+
30000/30000 [==============================] - 71s 2ms/step - loss: 0.2707
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
show_result(0)
|
212
|
+
|
213
|
+
Traceback (most recent call last):
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
File "<ipython-input-100-84299c05f901>", line 1, in <module>
|
218
|
+
|
219
|
+
show_result(0)
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
File "C:\Users\user.spyder-py3\untitled6.py", line 60, in show_result
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
IndexError: invalid index to scalar variable.
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
がでてしまいます。
|