質問編集履歴
2
全体コードを追加しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -19,6 +19,48 @@
|
|
19
19
|
|
20
20
|
変更点などよろしくお願いします。
|
21
21
|
|
22
|
+
### コード全体
|
23
|
+
```
|
24
|
+
import tensorflow as tf
|
25
|
+
import datetime
|
26
|
+
import numpy as np
|
27
|
+
mnist = tf.keras.datasets.mnist
|
28
|
+
|
29
|
+
(x_train, y_train),(x_test, y_test) = mnist.load_data()
|
30
|
+
x_train, x_test = x_train / 255.0, x_test / 255.0
|
31
|
+
|
32
|
+
model = tf.keras.models.Sequential([
|
33
|
+
tf.keras.layers.Flatten(input_shape=(28, 28)),
|
34
|
+
tf.keras.layers.Dense(512, activation=tf.nn.relu),
|
35
|
+
tf.keras.layers.Dropout(0.2),
|
36
|
+
tf.keras.layers.Dense(10, activation=tf.nn.softmax)
|
37
|
+
])
|
38
|
+
model.compile(optimizer='adam',
|
39
|
+
loss='sparse_categorical_crossentropy',
|
40
|
+
metrics=['accuracy'])
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
log_dir="logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M")
|
45
|
+
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)
|
46
|
+
|
47
|
+
|
48
|
+
model.fit(x=x_train,
|
49
|
+
y=y_train,
|
50
|
+
epochs=5,
|
51
|
+
validation_data=(x_test, y_test),
|
52
|
+
callbacks=[tensorboard_callback])
|
53
|
+
|
54
|
+
|
55
|
+
file_writer = tf.summary.create_file_writer(log_dir)
|
56
|
+
with file_writer.as_default():
|
57
|
+
images = np.reshape(x_train[0:10], (-1, 28, 28, 1))
|
58
|
+
tf.summary.image("25 training data examples", images, max_outputs=10, step=epoch)
|
59
|
+
|
60
|
+
|
61
|
+
model.evaluate(x_test, y_test)
|
62
|
+
```
|
63
|
+
|
22
64
|
### 環境
|
23
65
|
Anaconda3
|
24
66
|
python3.7.7
|
1
文の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -13,9 +13,12 @@
|
|
13
13
|
NameError: name 'epoch' is not defined
|
14
14
|
```
|
15
15
|
と出ます。
|
16
|
-
](479330c82417ff546b0849de47edd1e2.jpeg)
|
17
16
|
|
17
|
+
↓のようにしたいです。
|
18
|
+
](479330c82417ff546b0849de47edd1e2.jpeg)
|
18
19
|
|
20
|
+
変更点などよろしくお願いします。
|
21
|
+
|
19
22
|
### 環境
|
20
23
|
Anaconda3
|
21
24
|
python3.7.7
|