##### Copyright 2020 The TensorFlow Authors.
#@title Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # ่ฎพ็ฝฎๆฅๅฟ็บงๅซไธบERROR๏ผไปฅๅๅฐ่ญฆๅไฟกๆฏ
# ็ฆ็จ Gemini ็ๅบๅฑๅบ๏ผgRPC ๅ Abseil๏ผๅจๅๅงๅๆฅๅฟ่ญฆๅ
os.environ["GRPC_VERBOSITY"] = "ERROR"
os.environ["GLOG_minloglevel"] = "3" # 0: INFO, 1: WARNING, 2: ERROR, 3: FATAL
os.environ["GLOG_minloglevel"] = "true"
import logging
import tensorflow as tf
tf.get_logger().setLevel(logging.ERROR)
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
!export TF_FORCE_GPU_ALLOW_GROWTH=true
from pathlib import Path
temp_dir = Path(".temp")
temp_dir.mkdir(parents=True, exist_ok=True)
Keras Tuner ็ฎไป#
ๅจ TensorFlow.org ไธๆฅ็ | ๅจ Google Colab ไธญ่ฟ่ก | ๅจ GitHub ไธๆฅ็ๆบไปฃ็ | ไธ่ฝฝ็ฌ่ฎฐๆฌ |
ๆฆ่ฟฐ#
Keras Tuner ๆฏไธไธชๅบ๏ผๅฏๅธฎๅฉๆจไธบ TensorFlow ็จๅบ้ๆฉๆไฝณ็่ถ ๅๆฐ้ใไธบๆจ็ๆบๅจๅญฆไน (ML) ๅบ็จ้ๆฉๆญฃ็กฎ็่ถ ๅๆฐ้๏ผ่ฟไธ่ฟ็จ็งฐไธบ่ถ ๅๆฐ่ฐ่ๆ่ถ ่ฐใ
่ถ ๅๆฐๆฏๆงๅถ่ฎญ็ป่ฟ็จๅ ML ๆจกๅๆๆ็ๅ้ใ่ฟไบๅ้ๅจ่ฎญ็ป่ฟ็จไธญไฟๆไธๅ๏ผๅนถไผ็ดๆฅๅฝฑๅ ML ็จๅบ็ๆง่ฝใ่ถ ๅๆฐๆไธค็ง็ฑปๅ๏ผ
ๆจกๅ่ถ ๅๆฐ๏ผๅฝฑๅๆจกๅ็้ๆฉ๏ผไพๅฆ้่ๅฑ็ๆฐ้ๅๅฎฝๅบฆ
็ฎๆณ่ถ ๅๆฐ๏ผๅฝฑๅๅญฆไน ็ฎๆณ็้ๅบฆๅ่ดจ้๏ผไพๅฆ้ๆบๆขฏๅบฆไธ้ (SGD) ็ๅญฆไน ็ไปฅๅ k ่ฟ้ป (KNN) ๅ็ฑปๅจ็่ฟ้ปๆฐ
ๅจๆฌๆ็จไธญ๏ผๆจๅฐไฝฟ็จ Keras Tuner ๅฏนๅพๅๅ็ฑปๅบ็จๆง่ก่ถ ่ฐใ
่ฎพ็ฝฎ#
import tensorflow as tf
from tensorflow import keras
ๅฎ่ฃ ๅนถๅฏผๅ ฅ Keras Tunerใ
!pip install -q -U keras-tuner
import keras_tuner as kt
ไธ่ฝฝๅนถๅๅคๆฐๆฎ้#
ๅจๆฌๆ็จไธญ๏ผๆจๅฐไฝฟ็จ Keras Tuner ไธบๆไธชๅฏน Fashion MNIST ๆฐๆฎ้ๅ ็ๆ่ฃ ๅพๅ่ฟ่กๅ็ฑป็ๆบๅจๅญฆไน ๆจกๅๆพๅฐๆไฝณ่ถ ๅๆฐใ
ๅ ่ฝฝๆฐๆฎใ
(img_train, label_train), (img_test, label_test) = keras.datasets.fashion_mnist.load_data()
# Normalize pixel values between 0 and 1
img_train = img_train.astype('float32') / 255.0
img_test = img_test.astype('float32') / 255.0
ๅฎไนๆจกๅ#
ๆๅปบ็จไบ่ถ ่ฐ็ๆจกๅๆถ๏ผ้คไบๆจกๅๆถๆไนๅค๏ผ่ฟ่ฆๅฎไน่ถ ๅๆฐๆ็ดข็ฉบ้ดใๆจไธบ่ถ ่ฐ่ฎพ็ฝฎ็ๆจกๅ็งฐไธบ่ถ ๆจกๅใ
ๆจๅฏไปฅ้่ฟไธค็งๆนๅผๅฎไน่ถ ๆจกๅ๏ผ
ไฝฟ็จๆจกๅๆๅปบๅทฅๅ ทๅฝๆฐ
ๅฐ Keras Tuner API ็
HyperModel
็ฑปๅญ็ฑปๅ
ๆจ่ฟๅฏไปฅๅฐไธคไธช้ขๅฎไน็ HyperModel
็ฑป HyperXception ๅ HyperResNet ็จไบ่ฎก็ฎๆบ่ง่งๅบ็จใ
ๅจๆฌๆ็จไธญ๏ผๆจๅฐไฝฟ็จๆจกๅๆๅปบๅทฅๅ ทๅฝๆฐๆฅๅฎไนๅพๅๅ็ฑปๆจกๅใๆจกๅๆๅปบๅทฅๅ ทๅฝๆฐๅฐ่ฟๅๅทฒ็ผ่ฏ็ๆจกๅ๏ผๅนถไฝฟ็จๆจไปฅๅ ๅตๆนๅผๅฎไน็่ถ ๅๆฐๅฏนๆจกๅ่ฟ่ก่ถ ่ฐใ
def model_builder(hp):
model = keras.Sequential()
model.add(keras.layers.Flatten())
# Tune the number of units in the first Dense layer
# Choose an optimal value between 32-512
hp_units = hp.Int('units', min_value=32, max_value=512, step=32)
model.add(keras.layers.Dense(units=hp_units, activation='relu'))
model.add(keras.layers.Dense(10))
# Tune the learning rate for the optimizer
# Choose an optimal value from 0.01, 0.001, or 0.0001
hp_learning_rate = hp.Choice('learning_rate', values=[1e-2, 1e-3, 1e-4])
model.compile(optimizer=keras.optimizers.Adam(learning_rate=hp_learning_rate),
loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
return model
ๅฎไพๅ่ฐ่ๅจๅนถๆง่ก่ถ ่ฐ#
ๅฎไพๅ่ฐ่ๅจไปฅๆง่ก่ถ
่ฐใKeras Tuner ๆไพไบๅ็ง่ฐ่ๅจ๏ผRandomSearch
ใHyperband
ใBayesianOptimization
ๅ Sklearn
ใๅจๆฌๆ็จไธญ๏ผๆจๅฐไฝฟ็จ Hyperband ่ฐ่ๅจใ
่ฆๅฎไพๅ Hyperband ่ฐ่ๅจ๏ผๅฟ
้กปๆๅฎ่ถ
ๆจกๅใ่ฆไผๅ็ objective
ๅ่ฆ่ฎญ็ป็ๆๅคงๅจๆๆฐ (max_epochs
)ใ
tuner = kt.Hyperband(model_builder,
objective='val_accuracy',
max_epochs=10,
factor=3,
directory=temp_dir/'my_dir',
project_name='intro_to_kt')
Hyperband ่ฐ่็ฎๆณไฝฟ็จ่ช้ๅบ่ตๆบๅ้
ๅๆฉๅๆณๆฅๅฟซ้ๆถๆๅฐ้ซๆง่ฝๆจกๅใ่ฏฅ่ฟ็จ้็จไบไฝ่ฒ็ซๆไบๅ ๆจกๅผ็ๆ้คๆณใ็ฎๆณไผๅฐๅคง้ๆจกๅ่ฎญ็ปๅคไธชๅจๆ๏ผๅนถไป
ๅฐๆง่ฝๆ้ซ็ไธๅๆจกๅ้ๅ
ฅไธไธ่ฝฎ่ฎญ็ปใHyperband ้่ฟ่ฎก็ฎ 1 + logfactor
(max_epochs
) ๅนถๅฐๅ
ถๅไธ่ๅ
ฅๅฐๆๆฅ่ฟ็ๆดๆฐๆฅ็กฎๅฎ่ฆ่ฎญ็ป็ๆจกๅ็ๆฐ้ใ
ๅๅปบๅ่ฐไปฅๅจ้ช่ฏๆๅคฑ่พพๅฐ็นๅฎๅผๅๆๅๅๆญข่ฎญ็ปใ
stop_early = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=5)
่ฟ่ก่ถ
ๅๆฐๆ็ดขใ้คไบไธ้ข็ๅ่ฐๅค๏ผๆ็ดขๆนๆณ็ๅๆฐไนไธ tf.keras.model.fit
ๆ็จๅๆฐ็ธๅใ
tuner.search(img_train, label_train, epochs=50, validation_split=0.2, callbacks=[stop_early])
# Get the optimal hyperparameters
best_hps=tuner.get_best_hyperparameters(num_trials=1)[0]
print(f"""
The hyperparameter search is complete. The optimal number of units in the first densely-connected
layer is {best_hps.get('units')} and the optimal learning rate for the optimizer
is {best_hps.get('learning_rate')}.
""")
Trial 30 Complete [00h 00m 40s]
val_accuracy: 0.8653333187103271
Best val_accuracy So Far: 0.8915833234786987
Total elapsed time: 00h 09m 06s
The hyperparameter search is complete. The optimal number of units in the first densely-connected
layer is 480 and the optimal learning rate for the optimizer
is 0.001.
่ฎญ็ปๆจกๅ#
ไฝฟ็จไปๆ็ดขไธญ่ทๅพ็่ถ ๅๆฐๆพๅฐ่ฎญ็ปๆจกๅ็ๆไฝณๅจๆๆฐใ
# Build the model with the optimal hyperparameters and train it on the data for 50 epochs
model = tuner.hypermodel.build(best_hps)
history = model.fit(img_train, label_train, epochs=50, validation_split=0.2)
val_acc_per_epoch = history.history['val_accuracy']
best_epoch = val_acc_per_epoch.index(max(val_acc_per_epoch)) + 1
print('Best epoch: %d' % (best_epoch,))
Epoch 1/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 6s 3ms/step - accuracy: 0.7844 - loss: 0.6154 - val_accuracy: 0.8453 - val_loss: 0.4136
Epoch 2/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.8609 - loss: 0.3789 - val_accuracy: 0.8729 - val_loss: 0.3500
Epoch 3/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.8794 - loss: 0.3273 - val_accuracy: 0.8728 - val_loss: 0.3514
Epoch 4/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.8872 - loss: 0.3048 - val_accuracy: 0.8827 - val_loss: 0.3235
Epoch 5/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 3s 2ms/step - accuracy: 0.8939 - loss: 0.2821 - val_accuracy: 0.8809 - val_loss: 0.3286
Epoch 6/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 3ms/step - accuracy: 0.9030 - loss: 0.2598 - val_accuracy: 0.8760 - val_loss: 0.3422
Epoch 7/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9061 - loss: 0.2545 - val_accuracy: 0.8867 - val_loss: 0.3147
Epoch 8/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9094 - loss: 0.2420 - val_accuracy: 0.8893 - val_loss: 0.3141
Epoch 9/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9122 - loss: 0.2288 - val_accuracy: 0.8780 - val_loss: 0.3494
Epoch 10/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9165 - loss: 0.2218 - val_accuracy: 0.8899 - val_loss: 0.3222
Epoch 11/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9201 - loss: 0.2132 - val_accuracy: 0.8898 - val_loss: 0.3182
Epoch 12/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 3s 2ms/step - accuracy: 0.9235 - loss: 0.2020 - val_accuracy: 0.8924 - val_loss: 0.3073
Epoch 13/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9247 - loss: 0.1993 - val_accuracy: 0.8898 - val_loss: 0.3306
Epoch 14/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9291 - loss: 0.1879 - val_accuracy: 0.8894 - val_loss: 0.3475
Epoch 15/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9332 - loss: 0.1792 - val_accuracy: 0.8904 - val_loss: 0.3315
Epoch 16/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9332 - loss: 0.1797 - val_accuracy: 0.8928 - val_loss: 0.3508
Epoch 17/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9358 - loss: 0.1720 - val_accuracy: 0.8895 - val_loss: 0.3469
Epoch 18/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 3s 2ms/step - accuracy: 0.9390 - loss: 0.1633 - val_accuracy: 0.8905 - val_loss: 0.3497
Epoch 19/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9394 - loss: 0.1599 - val_accuracy: 0.8880 - val_loss: 0.3483
Epoch 20/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9436 - loss: 0.1496 - val_accuracy: 0.8885 - val_loss: 0.3815
Epoch 21/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9437 - loss: 0.1494 - val_accuracy: 0.8947 - val_loss: 0.3472
Epoch 22/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9457 - loss: 0.1457 - val_accuracy: 0.8883 - val_loss: 0.3934
Epoch 23/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9466 - loss: 0.1400 - val_accuracy: 0.8943 - val_loss: 0.3530
Epoch 24/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9487 - loss: 0.1352 - val_accuracy: 0.8901 - val_loss: 0.3810
Epoch 25/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9512 - loss: 0.1296 - val_accuracy: 0.8928 - val_loss: 0.3857
Epoch 26/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9515 - loss: 0.1283 - val_accuracy: 0.8956 - val_loss: 0.3769
Epoch 27/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9552 - loss: 0.1199 - val_accuracy: 0.8915 - val_loss: 0.3791
Epoch 28/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9553 - loss: 0.1173 - val_accuracy: 0.8946 - val_loss: 0.3851
Epoch 29/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9537 - loss: 0.1231 - val_accuracy: 0.8941 - val_loss: 0.4013
Epoch 30/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9576 - loss: 0.1152 - val_accuracy: 0.8942 - val_loss: 0.4023
Epoch 31/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9605 - loss: 0.1080 - val_accuracy: 0.8950 - val_loss: 0.4240
Epoch 32/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9596 - loss: 0.1069 - val_accuracy: 0.8918 - val_loss: 0.4392
Epoch 33/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9597 - loss: 0.1055 - val_accuracy: 0.8918 - val_loss: 0.4087
Epoch 34/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 3ms/step - accuracy: 0.9605 - loss: 0.1034 - val_accuracy: 0.8744 - val_loss: 0.5429
Epoch 35/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9623 - loss: 0.1027 - val_accuracy: 0.8938 - val_loss: 0.4789
Epoch 36/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9618 - loss: 0.0986 - val_accuracy: 0.8942 - val_loss: 0.4359
Epoch 37/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9657 - loss: 0.0934 - val_accuracy: 0.8948 - val_loss: 0.4627
Epoch 38/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9629 - loss: 0.0959 - val_accuracy: 0.8932 - val_loss: 0.4700
Epoch 39/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9639 - loss: 0.0953 - val_accuracy: 0.8938 - val_loss: 0.4628
Epoch 40/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9677 - loss: 0.0863 - val_accuracy: 0.8943 - val_loss: 0.4916
Epoch 41/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9695 - loss: 0.0828 - val_accuracy: 0.8948 - val_loss: 0.4793
Epoch 42/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9702 - loss: 0.0814 - val_accuracy: 0.8954 - val_loss: 0.4605
Epoch 43/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9699 - loss: 0.0805 - val_accuracy: 0.8959 - val_loss: 0.4710
Epoch 44/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 3s 2ms/step - accuracy: 0.9714 - loss: 0.0769 - val_accuracy: 0.8903 - val_loss: 0.4923
Epoch 45/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 3s 2ms/step - accuracy: 0.9699 - loss: 0.0777 - val_accuracy: 0.8861 - val_loss: 0.5372
Epoch 46/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9692 - loss: 0.0820 - val_accuracy: 0.8960 - val_loss: 0.5028
Epoch 47/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 3s 2ms/step - accuracy: 0.9710 - loss: 0.0748 - val_accuracy: 0.8913 - val_loss: 0.5318
Epoch 48/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 3s 2ms/step - accuracy: 0.9717 - loss: 0.0758 - val_accuracy: 0.8902 - val_loss: 0.5180
Epoch 49/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9728 - loss: 0.0718 - val_accuracy: 0.8907 - val_loss: 0.5315
Epoch 50/50
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9744 - loss: 0.0671 - val_accuracy: 0.8940 - val_loss: 0.5327
Best epoch: 46
้ๆฐๅฎไพๅ่ถ ๆจกๅๅนถไฝฟ็จไธ้ข็ๆไฝณๅจๆๆฐๅฏนๅ ถ่ฟ่ก่ฎญ็ปใ
hypermodel = tuner.hypermodel.build(best_hps)
# Retrain the model
hypermodel.fit(img_train, label_train, epochs=best_epoch, validation_split=0.2)
Epoch 1/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 6s 3ms/step - accuracy: 0.7809 - loss: 0.6163 - val_accuracy: 0.8484 - val_loss: 0.4384
Epoch 2/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.8677 - loss: 0.3708 - val_accuracy: 0.8735 - val_loss: 0.3508
Epoch 3/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.8762 - loss: 0.3344 - val_accuracy: 0.8788 - val_loss: 0.3403
Epoch 4/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.8859 - loss: 0.3046 - val_accuracy: 0.8776 - val_loss: 0.3412
Epoch 5/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.8953 - loss: 0.2834 - val_accuracy: 0.8808 - val_loss: 0.3291
Epoch 6/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 3s 2ms/step - accuracy: 0.8992 - loss: 0.2724 - val_accuracy: 0.8758 - val_loss: 0.3492
Epoch 7/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9066 - loss: 0.2501 - val_accuracy: 0.8848 - val_loss: 0.3247
Epoch 8/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9102 - loss: 0.2437 - val_accuracy: 0.8839 - val_loss: 0.3256
Epoch 9/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9117 - loss: 0.2329 - val_accuracy: 0.8885 - val_loss: 0.3255
Epoch 10/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 3s 2ms/step - accuracy: 0.9188 - loss: 0.2199 - val_accuracy: 0.8921 - val_loss: 0.3090
Epoch 11/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9197 - loss: 0.2120 - val_accuracy: 0.8873 - val_loss: 0.3218
Epoch 12/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9239 - loss: 0.2056 - val_accuracy: 0.8924 - val_loss: 0.3150
Epoch 13/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 3ms/step - accuracy: 0.9273 - loss: 0.1980 - val_accuracy: 0.8956 - val_loss: 0.3158
Epoch 14/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9293 - loss: 0.1931 - val_accuracy: 0.8917 - val_loss: 0.3301
Epoch 15/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9323 - loss: 0.1786 - val_accuracy: 0.8976 - val_loss: 0.3212
Epoch 16/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 3ms/step - accuracy: 0.9353 - loss: 0.1746 - val_accuracy: 0.8898 - val_loss: 0.3441
Epoch 17/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9347 - loss: 0.1709 - val_accuracy: 0.8947 - val_loss: 0.3288
Epoch 18/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9386 - loss: 0.1641 - val_accuracy: 0.8929 - val_loss: 0.3327
Epoch 19/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9424 - loss: 0.1533 - val_accuracy: 0.8949 - val_loss: 0.3435
Epoch 20/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9421 - loss: 0.1555 - val_accuracy: 0.8934 - val_loss: 0.3547
Epoch 21/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 3s 2ms/step - accuracy: 0.9448 - loss: 0.1469 - val_accuracy: 0.8953 - val_loss: 0.3412
Epoch 22/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9452 - loss: 0.1449 - val_accuracy: 0.8937 - val_loss: 0.3451
Epoch 23/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9477 - loss: 0.1407 - val_accuracy: 0.8945 - val_loss: 0.3516
Epoch 24/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 3s 2ms/step - accuracy: 0.9472 - loss: 0.1392 - val_accuracy: 0.8927 - val_loss: 0.3789
Epoch 25/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9506 - loss: 0.1318 - val_accuracy: 0.8898 - val_loss: 0.3972
Epoch 26/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9517 - loss: 0.1303 - val_accuracy: 0.8828 - val_loss: 0.4100
Epoch 27/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9533 - loss: 0.1262 - val_accuracy: 0.8924 - val_loss: 0.3892
Epoch 28/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9553 - loss: 0.1200 - val_accuracy: 0.8952 - val_loss: 0.3770
Epoch 29/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9571 - loss: 0.1156 - val_accuracy: 0.8959 - val_loss: 0.4118
Epoch 30/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9559 - loss: 0.1157 - val_accuracy: 0.8954 - val_loss: 0.3937
Epoch 31/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9579 - loss: 0.1112 - val_accuracy: 0.8932 - val_loss: 0.4362
Epoch 32/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9582 - loss: 0.1114 - val_accuracy: 0.8940 - val_loss: 0.4085
Epoch 33/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9594 - loss: 0.1066 - val_accuracy: 0.8959 - val_loss: 0.4060
Epoch 34/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 3ms/step - accuracy: 0.9607 - loss: 0.1041 - val_accuracy: 0.8966 - val_loss: 0.4171
Epoch 35/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9609 - loss: 0.1024 - val_accuracy: 0.8908 - val_loss: 0.4622
Epoch 36/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9613 - loss: 0.1018 - val_accuracy: 0.8754 - val_loss: 0.4987
Epoch 37/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9633 - loss: 0.0964 - val_accuracy: 0.8890 - val_loss: 0.4426
Epoch 38/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9644 - loss: 0.0931 - val_accuracy: 0.8934 - val_loss: 0.4596
Epoch 39/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9656 - loss: 0.0923 - val_accuracy: 0.8958 - val_loss: 0.4529
Epoch 40/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 3s 2ms/step - accuracy: 0.9687 - loss: 0.0821 - val_accuracy: 0.8915 - val_loss: 0.4697
Epoch 41/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 3s 2ms/step - accuracy: 0.9685 - loss: 0.0824 - val_accuracy: 0.8928 - val_loss: 0.4751
Epoch 42/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9662 - loss: 0.0861 - val_accuracy: 0.8842 - val_loss: 0.5023
Epoch 43/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9690 - loss: 0.0812 - val_accuracy: 0.8896 - val_loss: 0.4934
Epoch 44/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9684 - loss: 0.0836 - val_accuracy: 0.8953 - val_loss: 0.4849
Epoch 45/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9703 - loss: 0.0785 - val_accuracy: 0.8932 - val_loss: 0.5106
Epoch 46/46
1500/1500 โโโโโโโโโโโโโโโโโโโโ 4s 2ms/step - accuracy: 0.9717 - loss: 0.0782 - val_accuracy: 0.8932 - val_loss: 0.4991
<keras.src.callbacks.history.History at 0x7fb85c1195e0>
่ฆๅฎๆๆฌๆ็จ๏ผ่ฏทๅจๆต่ฏๆฐๆฎไธ่ฏไผฐ่ถ ๆจกๅใ
eval_result = hypermodel.evaluate(img_test, label_test)
print("[test loss, test accuracy]:", eval_result)
313/313 โโโโโโโโโโโโโโโโโโโโ 2s 6ms/step - accuracy: 0.8867 - loss: 0.5731
[test loss, test accuracy]: [0.5481381416320801, 0.8877999782562256]
my_dir/intro_to_kt
็ฎๅฝไธญๅ
ๅซไบๅจ่ถ
ๅๆฐๆ็ดขๆ้ดๆฏๆฌก่ฏ้ช๏ผๆจกๅ้
็ฝฎ๏ผ่ฟ่ก็่ฏฆ็ปๆฅๅฟๅๆฃๆฅ็นใๅฆๆ้ๆฐ่ฟ่ก่ถ
ๅๆฐๆ็ดข๏ผKeras Tuner ๅฐไฝฟ็จ่ฟไบๆฅๅฟไธญ่ฎฐๅฝ็็ฐๆ็ถๆๆฅ็ปง็ปญๆ็ดขใ่ฆๅ็จๆญค่กไธบ๏ผ่ฏทๅจๅฎไพๅ่ฐ่ๅจๆถไผ ้ไธไธช้ๅ ็ overwrite = True
ๅๆฐใ
ๆป็ป#
ๅจๆฌๆ็จไธญ๏ผๆจๅญฆไน ไบๅฆไฝไฝฟ็จ Keras Tuner ่ฐ่ๆจกๅ็่ถ ๅๆฐใ่ฆ่ฏฆ็ปไบ่งฃ Keras Tuner๏ผ่ฏทๆฅ็ไปฅไธๅ ถไป่ตๆบ๏ผ
ๅฆ่ฏทๆฅ็ TensorBoard ไธญ็ HParams Dashboard๏ผไปฅไบคไบๆนๅผ่ฐ่ๆจกๅ่ถ ๅๆฐใ