<jupyter_start><jupyter_text>重载模型并训练<jupyter_code>cd ..<jupyter_output>D:\kaggle\books\tensorflow-crack<jupyter_text>载入数据<jupyter_code>from utils.loader import load_data
from utils.toml import load_option

options = load_option('options/dataset.toml')
train_gen, val_gen, test_gen = load_data(**options)<jupyter_output>Found 600 images belonging to 2 classes.
Found 200 images belonging to 2 classes.
Found 200 images belonging to 2 classes.<jupyter_text>载入模型<jupyter_code>import tensorflow as tf
from utils.log import log_model


def reload_model(model_name, model_root):
    model_name = f'{model_root}/{model_name}.h5'
    model = tf.keras.models.load_model(model_name)
    return model
train_options = load_option('options/train.toml')
model = reload_model('resnet152', train_options.model_root)
model.summary()<jupyter_output>Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
resnet152 (Functional)       (None, 7, 7, 2048)        58370944  
_________________________________________________________________
global_average_pooling2d (Gl (None, 2048)              0         
_________________________________________________________________
dense (Dense)                (None, 512)               1049088   
_________________________________________________________________
dense_1 (Dense)              (None, 1)                 513       
=================================================================
Total params: 59,420,545
Trainable params: 1,049,601
Non-trainable params: 58,370,944
_________________________________________________________________<jupyter_text>训练模型<jupyter_code># 儲存模型
model_name = 'resnet152A-reload'
log_model(model, model_name,
          train_gen, val_gen,
          **train_options)<jupyter_output>Epoch 1/10
75/75 [==============================] - 33s 271ms/step - loss: 0.0957 - accuracy: 0.9650 - val_loss: 0.0453 - val_accuracy: 0.9900
Epoch 2/10
75/75 [==============================] - 15s 196ms/step - loss: 0.1279 - accuracy: 0.9633 - val_loss: 0.0200 - val_accuracy: 0.9950
Epoch 3/10
75/75 [==============================] - 15s 197ms/step - loss: 0.0482 - accuracy: 0.9833 - val_loss: 0.0780 - val_accuracy: 0.9650
Epoch 4/10
75/75 [==============================] - 15s 195ms/step - loss: 0.0461 - accuracy: 0.9850 - val_loss: 0.1395 - val_accuracy: 0.9350
Epoch 5/10
75/75 [==============================] - 15s 195ms/step - loss: 0.0678 - accuracy: 0.9783 - val_loss: 0.0725 - val_accuracy: 0.9750
Epoch 6/10
75/75 [==============================] - 15s 195ms/step - loss: 0.0253 - accuracy: 0.9883 - val_loss: 0.0461 - val_accuracy: 0.9900
Epoch 7/10
75/75 [==============================] - 15s 195ms/step - loss: 0.0455 - accuracy: 0.9850 - val_loss: 0.0658 - val_accuracy: 0.9800[...]<jupyter_text>测试模型<jupyter_code>def test_result(model, test_generator, batch_size):
    results = model.evaluate(x=test_generator,
                             batch_size=batch_size,
                             return_dict=True)
    return results
results = test_result(model, test_gen, batch_size=8)<jupyter_output>25/25 [==============================] - 3s 104ms/step - loss: 0.0060 - accuracy: 1.0000
{'fraction_non_alphanumeric': 0.20446994865599516, 'fraction_numerical': 0.09755360918151616, 'mean_word_length': 4.2405063291139244, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '589983', 'license': 'Apache-2.0', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1024, 'n_words': 212, 'path': 'start/01_main-reload.ipynb', 'repo_name': 'chengconvnet/tensorflow-crack', 'size': '3311'}