質問編集履歴

2

修正

2019/07/17 23:05

投稿

wrkig
wrkig

スコア15

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- 環境は macOS version:10.14.5でjupyter labを使っています。
5
+ 環境は macOS version:10.14.5、python3.7でjupyter labを使っています。
6
6
 
7
7
 
8
8
 
@@ -204,9 +204,11 @@
204
204
 
205
205
 
206
206
 
207
- `plt.plot`の前に、`print`文挿入してみたのですが、出力は上と変わらずでした。どうやら`model.fit`の行で処理が終わっているようです。
207
+ `plt.plot([1, 5], [1, 10])`を書いてみたのですが、グラフが表示されませんでした。
208
-
208
+
209
- さらに、別セルで`print(history)`で確認したのですが、"__NameError: name 'history' is not defined__" となって`model.fit``history`に代入されませんでした。
209
+ pythonやkerasのバージョン原因で表示されことはあるのでしょうか?
210
+
211
+
210
212
 
211
213
  ```Python
212
214
 
@@ -324,17 +326,19 @@
324
326
 
325
327
 
326
328
 
327
- print("-" * 10)
329
+ print("-" * 20)
328
330
 
329
331
  print(epochs)
330
332
 
331
333
  print(history)
332
334
 
333
- print("-" * 10)
335
+ print("-" * 20)
336
+
337
+
338
+
339
+
340
+
334
-
341
+ plt.plot([1, 5], [1, 10]) # 追記
335
-
336
-
337
-
338
342
 
339
343
  plt.plot(epochs, acc, label="acc", ls="-", marker="o")
340
344
 

1

追記

2019/07/17 23:05

投稿

wrkig
wrkig

スコア15

test CHANGED
File without changes
test CHANGED
@@ -191,3 +191,159 @@
191
191
 
192
192
 
193
193
  何かわかることがございましたら、ご教示いただければ幸いです。
194
+
195
+
196
+
197
+
198
+
199
+ ---
200
+
201
+
202
+
203
+ **追記**
204
+
205
+
206
+
207
+ `plt.plot`の前に、`print`文を挿入してみたのですが、出力は上と変わらずでした。どうやら`model.fit`の行で処理が終わっているようです。
208
+
209
+ さらに、別セルで`print(history)`で確認したのですが、"__NameError: name 'history' is not defined__" となって`model.fit`が`history`に代入されていませんでした。
210
+
211
+ ```Python
212
+
213
+ import numpy as np
214
+
215
+ import matplotlib.pyplot as plt
216
+
217
+ from keras.datasets import mnist
218
+
219
+ from keras.layers import Activation, Dense, Dropout
220
+
221
+ from keras.models import Sequential, load_model
222
+
223
+ from keras.utils.np_utils import to_categorical
224
+
225
+ from keras import optimizers
226
+
227
+ from keras import models
228
+
229
+ from keras import layers
230
+
231
+ import tensorflow
232
+
233
+ import tensorboard
234
+
235
+ from livelossplot import PlotLossesKeras
236
+
237
+
238
+
239
+ %matplotlib inline
240
+
241
+
242
+
243
+ (X_train, y_train), (X_test, y_test) = mnist.load_data()
244
+
245
+
246
+
247
+ X_train = X_train.reshape(X_train.shape[0], 784)[:6000]
248
+
249
+ X_test = X_test.reshape(X_test.shape[0], 784)[:1000]
250
+
251
+ y_train = to_categorical(y_train)[:6000]
252
+
253
+ y_test = to_categorical(y_test)[:1000]
254
+
255
+
256
+
257
+ model = Sequential()
258
+
259
+ model.add(Dense(256, input_dim=784))
260
+
261
+ model.add(Activation("sigmoid"))
262
+
263
+ model.add(Dense(128))
264
+
265
+ model.add(Activation("sigmoid"))
266
+
267
+
268
+
269
+ model.add(Dropout(rate=0.5))
270
+
271
+
272
+
273
+ model.add(Dense(10))
274
+
275
+ model.add(Activation("softmax"))
276
+
277
+
278
+
279
+ sgd = optimizers.SGD(lr=0.1)
280
+
281
+
282
+
283
+ model.compile(optimizer=sgd, loss="categorical_crossentropy", metrics=["accuracy"])
284
+
285
+
286
+
287
+ # callbacks = [PlotLossesKeras()]
288
+
289
+
290
+
291
+ history = model.fit(
292
+
293
+ X_train,
294
+
295
+ y_train,
296
+
297
+ batch_size=32,
298
+
299
+ epochs=5,
300
+
301
+ verbose=1,
302
+
303
+ validation_data=(X_test, y_test),
304
+
305
+ # callbacks=[PlotLossesKeras()]
306
+
307
+ )
308
+
309
+
310
+
311
+ acc = history.history["acc"]
312
+
313
+ val_acc = history.history["val_acc"]
314
+
315
+ loss = history.history["loss"]
316
+
317
+ val_loss = history.history["val_loss"]
318
+
319
+
320
+
321
+ epochs = range(1, len(acc) + 1)
322
+
323
+
324
+
325
+
326
+
327
+ print("-" * 10)
328
+
329
+ print(epochs)
330
+
331
+ print(history)
332
+
333
+ print("-" * 10)
334
+
335
+
336
+
337
+
338
+
339
+ plt.plot(epochs, acc, label="acc", ls="-", marker="o")
340
+
341
+ plt.plot(epochs, val_acc, label="val_acc", ls="-", marker="x")
342
+
343
+ plt.ylabel("accuracy")
344
+
345
+ plt.xlabel("epoch")
346
+
347
+ plt.legend(loc="best")
348
+
349
+ ```