質問編集履歴
1
エラー内容が変わった
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
invalid index to scalar variable.の解決
|
body
CHANGED
@@ -31,4 +31,86 @@
|
|
31
31
|
|
32
32
|
|
33
33
|
最後の行でエラーが出ているのですが解決方法がわかりません。
|
34
|
-
どなたかわかるかたいらっしゃったらお願いします。
|
34
|
+
どなたかわかるかたいらっしゃったらお願いします。
|
35
|
+
|
36
|
+
|
37
|
+
#追記
|
38
|
+
(題名変えました)
|
39
|
+
前半に続くコードです。
|
40
|
+
|
41
|
+
def create_model():
|
42
|
+
model = models.Sequential()
|
43
|
+
model.add(layers.Conv2D(32, (3, 3), padding='same', activation='relu', input_shape=(28, 28, 1)))
|
44
|
+
model.add(layers.MaxPooling2D((2, 2), padding='same'))
|
45
|
+
model.add(layers.Conv2D(16, (3, 3), padding='same', activation='relu'))
|
46
|
+
model.add(layers.MaxPooling2D((2, 2), padding='same'))
|
47
|
+
model.add(layers.Conv2D(8, (3, 3), padding='same', activation='relu'))
|
48
|
+
model.add(layers.MaxPooling2D((2, 2), padding='same'))
|
49
|
+
|
50
|
+
model.add(layers.Conv2D(8, (3, 3), padding='same', activation='relu'))
|
51
|
+
model.add(layers.UpSampling2D((2, 2)))
|
52
|
+
model.add(layers.Conv2D(16, (3, 3), padding='same', activation='relu'))
|
53
|
+
model.add(layers.UpSampling2D((2, 2)))
|
54
|
+
model.add(layers.Conv2D(32, (3, 3), activation='relu'))
|
55
|
+
model.add(layers.UpSampling2D((2, 2)))
|
56
|
+
model.add(layers.Conv2D(1, (3, 3), padding='same', activation='sigmoid'))
|
57
|
+
|
58
|
+
model.compile(loss='binary_crossentropy', optimizer='sgd')
|
59
|
+
|
60
|
+
return model
|
61
|
+
|
62
|
+
model = create_model()
|
63
|
+
|
64
|
+
def show_result(j):
|
65
|
+
results = model.predict(test_images_noisy_2[j:j+10])
|
66
|
+
|
67
|
+
fig = plt.figure(figsize=(16, 2.7))
|
68
|
+
for i in range(10):
|
69
|
+
|
70
|
+
subplot = fig.add_subplot(3, 10, i+1)
|
71
|
+
subplot.set_xticks([])
|
72
|
+
subplot.set_yticks([])
|
73
|
+
subplot.imshow(test_images_noisy_2[j+i, :, :, 0],
|
74
|
+
vmin=0, vmax=1, cmap=plt.cm.gray_r)
|
75
|
+
|
76
|
+
|
77
|
+
subplot = fig.add_subplot(3, 10, i+11)
|
78
|
+
subplot.set_xticks([])
|
79
|
+
subplot.set_yticks([])
|
80
|
+
subplot.imshow(results[i, :, :, 0],
|
81
|
+
vmin=0, vmax=1, cmap=plt.cm.gray_r)
|
82
|
+
|
83
|
+
|
84
|
+
subplot = fig.add_subplot(3, 10, i+21)
|
85
|
+
subplot.set_xticks([])
|
86
|
+
subplot.set_yticks([])
|
87
|
+
subplot.imshow(np.abs(test_images_noisy_2[j+i, :, :, 0]-results[i, :, :, 0]),
|
88
|
+
vmin=0, vmax=1, cmap=plt.cm.gray_r)
|
89
|
+
|
90
|
+
|
91
|
+
train_num = 10
|
92
|
+
|
93
|
+
|
94
|
+
learn = model.fit(train_images[:30000], train_images[:30000], batch_size=16, epochs=1)
|
95
|
+
|
96
|
+
|
97
|
+
model.save('cnn_auto_model_noisy.h5')
|
98
|
+
|
99
|
+
#実行結果
|
100
|
+
ここでshow_result(0)で実行すると
|
101
|
+
|
102
|
+
runfile('C:/Users/user/.spyder-py3/untitled6.py', wdir='C:/Users/user/.spyder-py3')
|
103
|
+
Epoch 1/1
|
104
|
+
30000/30000 [==============================] - 71s 2ms/step - loss: 0.2707
|
105
|
+
|
106
|
+
show_result(0)
|
107
|
+
Traceback (most recent call last):
|
108
|
+
|
109
|
+
File "<ipython-input-100-84299c05f901>", line 1, in <module>
|
110
|
+
show_result(0)
|
111
|
+
|
112
|
+
File "C:\Users\user.spyder-py3\untitled6.py", line 60, in show_result
|
113
|
+
|
114
|
+
IndexError: invalid index to scalar variable.
|
115
|
+
|
116
|
+
がでてしまいます。
|