質問編集履歴
1
ソースコードを補足しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,6 +60,35 @@
|
|
60
60
|
### 該当のソースコード
|
61
61
|
|
62
62
|
```python
|
63
|
+
#データの分割
|
64
|
+
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
|
65
|
+
data_dir,
|
66
|
+
validation_split=0.2,
|
67
|
+
subset="training",
|
68
|
+
seed=123,
|
69
|
+
image_size=(img_height, img_width),
|
70
|
+
batch_size=batch_size)
|
71
|
+
val_ds = tf.keras.preprocessing.image_dataset_from_directory(
|
72
|
+
data_dir,
|
73
|
+
validation_split=0.2,
|
74
|
+
subset="validation",
|
75
|
+
seed=123,
|
76
|
+
image_size=(img_height, img_width),
|
77
|
+
batch_size=batch_size)
|
78
|
+
|
79
|
+
#標準化
|
80
|
+
AUTOTUNE = tf.data.AUTOTUNE
|
81
|
+
|
82
|
+
train_ds = train_ds.cache().shuffle(1000).prefetch(buffer_size=AUTOTUNE)
|
83
|
+
val_ds = val_ds.cache().prefetch(buffer_size=AUTOTUNE)
|
84
|
+
|
85
|
+
normalization_layer = layers.experimental.preprocessing.Rescaling(1./255)
|
86
|
+
|
87
|
+
normalized_ds = train_ds.map(lambda x, y: (normalization_layer(x), y))
|
88
|
+
image_batch, labels_batch = next(iter(normalized_ds))
|
89
|
+
first_image = image_batch[0]
|
90
|
+
print(np.min(first_image), np.max(first_image))
|
91
|
+
|
63
92
|
num_classes = 4
|
64
93
|
|
65
94
|
def conv2d(filters, kernel_size, strides=1, bias_init=1, **kwargs):
|
@@ -120,12 +149,11 @@
|
|
120
149
|
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
|
121
150
|
return model
|
122
151
|
|
123
|
-
# コンパイル
|
124
152
|
model = AlexNet()
|
125
153
|
|
126
154
|
# モデル構成の確認
|
127
155
|
model.summary()
|
128
|
-
|
156
|
+
#訓練
|
129
157
|
history = model.fit(
|
130
158
|
train_ds,
|
131
159
|
validation_data=val_ds,
|