keras和tensorflow 报错解决:UserWarning: Method on_batch_end() is slow compared to the batch update Check

在使用Keras进行训练时遇到UserWarning警告,提示on_batch_end()方法执行速度慢于批量更新。该警告可忽略,但若希望消除,可通过修改代码实现。

早上在使用keras时报错如下:

C:\Users\peter\Anaconda3\lib\site-packages\keras\callbacks.py:122: UserWarning: Method on_batch_end() is slow compared to the batch update (0.115551). Check your callbacks.

这是一个警告,可以不用理会,如果想要取消这个警告,修改代码如下:

model.fit(verbose=2)
2025-06-22 18:56:53.192710: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 2025-06-22 18:56:54.136866: I tensorflow/core/util/port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`. 2025-06-22 18:56:56,467 - INFO - 加载并增强数据集: augmented_data 2025-06-22 18:56:56,560 - INFO - 原始数据集: 150 张图片, 5 个类别 2025-06-22 18:56:56,565 - INFO - 类别 book: 30 张原始图像 2025-06-22 18:56:56,989 - INFO - 类别 cup: 30 张原始图像 2025-06-22 18:56:57,403 - INFO - 类别 glasses: 30 张原始图像 2025-06-22 18:56:57,820 - INFO - 类别 phone: 30 张原始图像 2025-06-22 18:56:58,248 - INFO - 类别 shoe: 30 张原始图像 2025-06-22 18:56:58,859 - INFO - 增强后数据集: 450 张图片 2025-06-22 18:56:58,954 - INFO - 构建优化的迁移学习模型... 2025-06-22 18:56:58.959007: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: SSE3 SSE4.1 SSE4.2 AVX AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. Model: "functional" ┌─────────────────────┬───────────────────┬────────────┬───────────────────┐ │ Layer (type) │ Output Shape │ Param # │ Connected to │ ├─────────────────────┼───────────────────┼────────────┼───────────────────┤ │ input_layer_1 │ (None, 224, 224, │ 0 │ - │ │ (InputLayer) │ 3) │ │ │ ├─────────────────────┼───────────────────┼────────────┼───────────────────┤ │ efficientnetb0 │ (None, 7, 7, │ 4,049,571 │ input_layer_1[0]… │ │ (Functional) │ 1280) │ │ │ ├─────────────────────┼───────────────────┼────────────┼───────────────────┤ │ global_average_poo… │ (None, 1280) │ 0 │ efficientnetb0[0… │ │ (GlobalAveragePool… │ │ │ │ ├─────────────────────┼───────────────────┼────────────┼───────────────────┤ │ dense (Dense) │ (None, 512) │ 655,872 │ global_average_p… │ ├─────────────────────┼───────────────────┼────────────┼───────────────────┤ │ dense_1 (Dense) │ (None, 1280) │ 656,640 │ dense[0][0] │ ├─────────────────────┼───────────────────┼────────────┼───────────────────┤ │ multiply (Multiply) │ (None, 1280) │ 0 │ global_average_p… │ │ │ │ │ dense_1[0][0] │ ├─────────────────────┼───────────────────┼────────────┼───────────────────┤ │ dense_2 (Dense) │ (None, 512) │ 655,872 │ multiply[0][0] │ ├─────────────────────┼───────────────────┼────────────┼───────────────────┤ │ batch_normalization │ (None, 512) │ 2,048 │ dense_2[0][0] │ │ (BatchNormalizatio… │ │ │ │ ├─────────────────────┼───────────────────┼────────────┼───────────────────┤ │ dropout (Dropout) │ (None, 512) │ 0 │ batch_normalizat… │ ├─────────────────────┼───────────────────┼────────────┼───────────────────┤ │ dense_3 (Dense) │ (None, 5) │ 2,565 │ dropout[0][0] │ └─────────────────────┴───────────────────┴────────────┴───────────────────┘ Total params: 6,022,568 (22.97 MB) Trainable params: 1,971,973 (7.52 MB) Non-trainable params: 4,050,595 (15.45 MB) 2025-06-22 18:56:59,882 - INFO - 开始高级训练策略... 2025-06-22 18:56:59,882 - INFO - 阶段1: 冻结基础模型训练 Epoch 1/50 23/23 ━━━━━━━━━━━━━━━━━━━━ 16s 442ms/step - accuracy: 0.2001 - loss: 1.7270 - val_accuracy: 0.2000 - val_loss: 1.6104 - learning_rate: 1.0000e-04 Epoch 2/50 23/23 ━━━━━━━━━━━━━━━━━━━━ 8s 335ms/step - accuracy: 0.1486 - loss: 1.7114 - val_accuracy: 0.2000 - val_loss: 1.6100 - learning_rate: 1.0000e-04 Epoch 3/50 23/23 ━━━━━━━━━━━━━━━━━━━━ 8s 332ms/step - accuracy: 0.2337 - loss: 1.7239 - val_accuracy: 0.2000 - val_loss: 1.6117 - learning_rate: 1.0000e-04 Epoch 4/50 23/23 ━━━━━━━━━━━━━━━━━━━━ 8s 335ms/step - accuracy: 0.2558 - loss: 1.6466 - val_accuracy: 0.2000 - val_loss: 1.6104 - learning_rate: 1.0000e-04 Epoch 5/50 23/23 ━━━━━━━━━━━━━━━━━━━━ 0s 270ms/step - accuracy: 0.2281 - loss: 1.6503 Epoch 5: ReduceLROnPlateau reducing learning rate to 4.999999873689376e-05. 23/23 ━━━━━━━━━━━━━━━━━━━━ 8s 367ms/step - accuracy: 0.2271 - loss: 1.6513 - val_accuracy: 0.2111 - val_loss: 1.6118 - learning_rate: 1.0000e-04 Epoch 6/50 23/23 ━━━━━━━━━━━━━━━━━━━━ 8s 333ms/step - accuracy: 0.1899 - loss: 1.6756 - val_accuracy: 0.2000 - val_loss: 1.6112 - learning_rate: 5.0000e-05 Epoch 7/50 23/23 ━━━━━━━━━━━━━━━━━━━━ 8s 333ms/step - accuracy: 0.2394 - loss: 1.6269 - val_accuracy: 0.2000 - val_loss: 1.6128 - learning_rate: 5.0000e-05 Epoch 8/50 23/23 ━━━━━━━━━━━━━━━━━━━━ 0s 266ms/step - accuracy: 0.2041 - loss: 1.7332 Epoch 8: ReduceLROnPlateau reducing learning rate to 2.499999936844688e-05. 23/23 ━━━━━━━━━━━━━━━━━━━━ 8s 333ms/step - accuracy: 0.2042 - loss: 1.7319 - val_accuracy: 0.2000 - val_loss: 1.6103 - learning_rate: 5.0000e-05 Epoch 9/50 23/23 ━━━━━━━━━━━━━━━━━━━━ 8s 355ms/step - accuracy: 0.1765 - loss: 1.6814 - val_accuracy: 0.3333 - val_loss: 1.6107 - learning_rate: 2.5000e-05 2025-06-22 18:58:18,867 - INFO - 阶段2: 微调部分层 Epoch 1/25 23/23 ━━━━━━━━━━━━━━━━━━━━ 18s 460ms/step - accuracy: 0.2374 - loss: 2.4082 - val_accuracy: 0.2000 - val_loss: 1.6107 - learning_rate: 1.0000e-05 Epoch 2/25 23/23 ━━━━━━━━━━━━━━━━━━━━ 9s 390ms/step - accuracy: 0.2021 - loss: 2.2585 - val_accuracy: 0.2000 - val_loss: 1.6112 - learning_rate: 1.0000e-05 Epoch 3/25 23/23 ━━━━━━━━━━━━━━━━━━━━ 9s 375ms/step - accuracy: 0.2259 - loss: 2.3548 - val_accuracy: 0.2111 - val_loss: 1.6121 - learning_rate: 1.0000e-05 Epoch 4/25 23/23 ━━━━━━━━━━━━━━━━━━━━ 0s 307ms/step - accuracy: 0.2416 - loss: 2.0942 Epoch 4: ReduceLROnPlateau reducing learning rate to 4.999999873689376e-06. 23/23 ━━━━━━━━━━━━━━━━━━━━ 9s 374ms/step - accuracy: 0.2405 - loss: 2.1006 - val_accuracy: 0.2000 - val_loss: 1.6127 - learning_rate: 1.0000e-05 Epoch 5/25 23/23 ━━━━━━━━━━━━━━━━━━━━ 9s 377ms/step - accuracy: 0.2053 - loss: 2.1248 - val_accuracy: 0.2000 - val_loss: 1.6136 - learning_rate: 5.0000e-06 Epoch 6/25 23/23 ━━━━━━━━━━━━━━━━━━━━ 9s 382ms/step - accuracy: 0.1995 - loss: 2.2549 - val_accuracy: 0.2000 - val_loss: 1.6150 - learning_rate: 5.0000e-06 Epoch 7/25 23/23 ━━━━━━━━━━━━━━━━━━━━ 0s 305ms/step - accuracy: 0.1949 - loss: 2.1615 Epoch 7: ReduceLROnPlateau reducing learning rate to 2.499999936844688e-06. 23/23 ━━━━━━━━━━━━━━━━━━━━ 9s 373ms/step - accuracy: 0.1962 - loss: 2.1615 - val_accuracy: 0.2000 - val_loss: 1.6165 - learning_rate: 5.0000e-06 Epoch 8/25 23/23 ━━━━━━━━━━━━━━━━━━━━ 9s 375ms/step - accuracy: 0.2320 - loss: 2.1199 - val_accuracy: 0.2000 - val_loss: 1.6186 - learning_rate: 2.5000e-06 Epoch 9/25 23/23 ━━━━━━━━━━━━━━━━━━━━ 9s 378ms/step - accuracy: 0.2379 - loss: 2.1694 - val_accuracy: 0.2000 - val_loss: 1.6204 - learning_rate: 2.5000e-06 2025-06-22 18:59:46,920 - INFO - 训练完成 2025-06-22 18:59:46,920 - INFO - 评估模型... 2025-06-22 18:59:48,600 - INFO - 测试准确率: 20.00% E:\pycharm\study\计算机视觉\物品识别系统.py:313: UserWarning: Glyph 20934 (\N{CJK UNIFIED IDEOGRAPH-51C6}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:313: UserWarning: Glyph 30830 (\N{CJK UNIFIED IDEOGRAPH-786E}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:313: UserWarning: Glyph 29575 (\N{CJK UNIFIED IDEOGRAPH-7387}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:313: UserWarning: Glyph 35757 (\N{CJK UNIFIED IDEOGRAPH-8BAD}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:313: UserWarning: Glyph 32451 (\N{CJK UNIFIED IDEOGRAPH-7EC3}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:313: UserWarning: Glyph 21644 (\N{CJK UNIFIED IDEOGRAPH-548C}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:313: UserWarning: Glyph 39564 (\N{CJK UNIFIED IDEOGRAPH-9A8C}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:313: UserWarning: Glyph 35777 (\N{CJK UNIFIED IDEOGRAPH-8BC1}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:313: UserWarning: Glyph 25439 (\N{CJK UNIFIED IDEOGRAPH-635F}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:313: UserWarning: Glyph 22833 (\N{CJK UNIFIED IDEOGRAPH-5931}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:314: UserWarning: Glyph 20934 (\N{CJK UNIFIED IDEOGRAPH-51C6}) missing from font(s) DejaVu Sans. plt.savefig('training_history.png') E:\pycharm\study\计算机视觉\物品识别系统.py:314: UserWarning: Glyph 30830 (\N{CJK UNIFIED IDEOGRAPH-786E}) missing from font(s) DejaVu Sans. plt.savefig('training_history.png') E:\pycharm\study\计算机视觉\物品识别系统.py:314: UserWarning: Glyph 29575 (\N{CJK UNIFIED IDEOGRAPH-7387}) missing from font(s) DejaVu Sans. plt.savefig('training_history.png') E:\pycharm\study\计算机视觉\物品识别系统.py:314: UserWarning: Glyph 35757 (\N{CJK UNIFIED IDEOGRAPH-8BAD}) missing from font(s) DejaVu Sans. plt.savefig('training_history.png') E:\pycharm\study\计算机视觉\物品识别系统.py:314: UserWarning: Glyph 32451 (\N{CJK UNIFIED IDEOGRAPH-7EC3}) missing from font(s) DejaVu Sans. plt.savefig('training_history.png') E:\pycharm\study\计算机视觉\物品识别系统.py:314: UserWarning: Glyph 21644 (\N{CJK UNIFIED IDEOGRAPH-548C}) missing from font(s) DejaVu Sans. plt.savefig('training_history.png') E:\pycharm\study\计算机视觉\物品识别系统.py:314: UserWarning: Glyph 39564 (\N{CJK UNIFIED IDEOGRAPH-9A8C}) missing from font(s) DejaVu Sans. plt.savefig('training_history.png') E:\pycharm\study\计算机视觉\物品识别系统.py:314: UserWarning: Glyph 35777 (\N{CJK UNIFIED IDEOGRAPH-8BC1}) missing from font(s) DejaVu Sans. plt.savefig('training_history.png') E:\pycharm\study\计算机视觉\物品识别系统.py:314: UserWarning: Glyph 25439 (\N{CJK UNIFIED IDEOGRAPH-635F}) missing from font(s) DejaVu Sans. plt.savefig('training_history.png') E:\pycharm\study\计算机视觉\物品识别系统.py:314: UserWarning: Glyph 22833 (\N{CJK UNIFIED IDEOGRAPH-5931}) missing from font(s) DejaVu Sans. plt.savefig('training_history.png') 2025-06-22 18:59:48,905 - INFO - 训练历史图表已保存到 training_history.png 2025-06-22 18:59:49,390 - INFO - 模型已保存到: optimized_model.keras 2025-06-22 18:59:49,390 - INFO - 执行内存清理... WARNING:tensorflow:From E:\python3.9.13\lib\site-packages\keras\src\backend\common\global_state.py:82: The name tf.reset_default_graph is deprecated. Please use tf.compat.v1.reset_default_graph instead. 2025-06-22 18:59:50,195 - WARNING - From E:\python3.9.13\lib\site-packages\keras\src\backend\common\global_state.py:82: The name tf.reset_default_graph is deprecated. Please use tf.compat.v1.reset_default_graph instead. 2025-06-22 18:59:50,743 - INFO - 内存清理完成 E:\pycharm\study\计算机视觉\物品识别系统.py:355: UserWarning: set_ticklabels() should only be used with a fixed number of ticks, i.e. after set_ticks() or using a FixedLocator. ax2.set_xticklabels(self.class_labels, rotation=45) E:\pycharm\study\计算机视觉\物品识别系统.py:364: UserWarning: Glyph 39044 (\N{CJK UNIFIED IDEOGRAPH-9884}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:364: UserWarning: Glyph 27979 (\N{CJK UNIFIED IDEOGRAPH-6D4B}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:364: UserWarning: Glyph 27010 (\N{CJK UNIFIED IDEOGRAPH-6982}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:364: UserWarning: Glyph 29575 (\N{CJK UNIFIED IDEOGRAPH-7387}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:364: UserWarning: Glyph 31867 (\N{CJK UNIFIED IDEOGRAPH-7C7B}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:364: UserWarning: Glyph 21035 (\N{CJK UNIFIED IDEOGRAPH-522B}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:364: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:364: UserWarning: Glyph 24067 (\N{CJK UNIFIED IDEOGRAPH-5E03}) missing from font(s) DejaVu Sans. plt.tight_layout() E:\pycharm\study\计算机视觉\物品识别系统.py:365: UserWarning: Glyph 39044 (\N{CJK UNIFIED IDEOGRAPH-9884}) missing from font(s) DejaVu Sans. plt.savefig(output_path) E:\pycharm\study\计算机视觉\物品识别系统.py:365: UserWarning: Glyph 27979 (\N{CJK UNIFIED IDEOGRAPH-6D4B}) missing from font(s) DejaVu Sans. plt.savefig(output_path) E:\pycharm\study\计算机视觉\物品识别系统.py:365: UserWarning: Glyph 27010 (\N{CJK UNIFIED IDEOGRAPH-6982}) missing from font(s) DejaVu Sans. plt.savefig(output_path) E:\pycharm\study\计算机视觉\物品识别系统.py:365: UserWarning: Glyph 29575 (\N{CJK UNIFIED IDEOGRAPH-7387}) missing from font(s) DejaVu Sans. plt.savefig(output_path) E:\pycharm\study\计算机视觉\物品识别系统.py:365: UserWarning: Glyph 31867 (\N{CJK UNIFIED IDEOGRAPH-7C7B}) missing from font(s) DejaVu Sans. plt.savefig(output_path) E:\pycharm\study\计算机视觉\物品识别系统.py:365: UserWarning: Glyph 21035 (\N{CJK UNIFIED IDEOGRAPH-522B}) missing from font(s) DejaVu Sans. plt.savefig(output_path) E:\pycharm\study\计算机视觉\物品识别系统.py:365: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) DejaVu Sans. plt.savefig(output_path) E:\pycharm\study\计算机视觉\物品识别系统.py:365: UserWarning: Glyph 24067 (\N{CJK UNIFIED IDEOGRAPH-5E03}) missing from font(s) DejaVu Sans. plt.savefig(output_path) 2025-06-22 18:59:52,251 - INFO - 预测结果已保存到 prediction_result.png 2025-06-22 18:59:52,252 - INFO - 真实类别: cup
06-23
2025-07-27 06:34:49.050571: E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc:477] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered WARNING: All log messages before absl::InitializeLog() is called are written to STDERR E0000 00:00:1753598089.235406 36 cuda_dnn.cc:8310] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered E0000 00:00:1753598089.287919 36 cuda_blas.cc:1418] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/imdb.npz 17464789/17464789 ━━━━━━━━━━━━━━━━━━━━ 0s 0us/step 数据集形状: 训练集: (20000, 128) (20000,) 验证集: (5000, 128) (5000,) 测试集: (25000, 128) (25000,) I0000 00:00:1753598105.743405 36 gpu_device.cc:2022] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 15513 MB memory: -> device: 0, name: Tesla P100-PCIE-16GB, pci bus id: 0000:00:04.0, compute capability: 6.0 Model: "functional_1" ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓ ┃ Layer (type) ┃ Output Shape ┃ Param # ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩ │ input_layer (InputLayer) │ (None, 128) │ 0 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ embedding (Embedding) │ (None, 128, 64) │ 640,000 │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ lite_transformer │ (None, 128, 64) │ 33,472 │ │ (LiteTransformer) │ │ │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ global_average_pooling1d │ (None, 64) │ 0 │ │ (GlobalAveragePooling1D) │ │ │ ├─────────────────────────────────┼────────────────────────┼───────────────┤ │ dense_2 (Dense) │ (None, 1) │ 65 │ └─────────────────────────────────┴────────────────────────┴───────────────┘ Total params: 673,537 (2.57 MB) Trainable params: 673,537 (2.57 MB) Non-trainable params: 0 (0.00 B) Epoch 1/15 WARNING: All log messages before absl::InitializeLog() is called are written to STDERR I0000 00:00:1753598112.016146 94 service.cc:148] XLA service 0x7ef2ec012540 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices: I0000 00:00:1753598112.016592 94 service.cc:156] StreamExecutor device (0): Tesla P100-PCIE-16GB, Compute Capability 6.0 I0000 00:00:1753598112.533355 94 cuda_dnn.cc:529] Loaded cuDNN version 90300 36/313 ━━━━━━━━━━━━━━━━━━━━ 1s 5ms/step - accuracy: 0.5287 - loss: 0.6993 I0000 00:00:1753598116.120238 94 device_compiler.h:188] Compiled cluster using XLA! This line is logged at most once for the lifetime of the process. 313/313 ━━━━━━━━━━━━━━━━━━━━ 15s 21ms/step - accuracy: 0.6466 - loss: 0.6406 - val_accuracy: 0.8130 - val_loss: 0.4329 - learning_rate: 1.0000e-04 Epoch 2/15 313/313 ━━━━━━━━━━━━━━━━━━━━ 2s 5ms/step - accuracy: 0.8495 - loss: 0.3622 - val_accuracy: 0.8554 - val_loss: 0.3257 - learning_rate: 1.0000e-04 Epoch 3/15 313/313 ━━━━━━━━━━━━━━━━━━━━ 2s 5ms/step - accuracy: 0.9026 - loss: 0.2480 - val_accuracy: 0.8598 - val_loss: 0.3216 - learning_rate: 1.0000e-04 Epoch 4/15 313/313 ━━━━━━━━━━━━━━━━━━━━ 2s 5ms/step - accuracy: 0.9239 - loss: 0.2061 - val_accuracy: 0.8616 - val_loss: 0.3358 - learning_rate: 1.0000e-04 Epoch 5/15 313/313 ━━━━━━━━━━━━━━━━━━━━ 2s 5ms/step - accuracy: 0.9342 - loss: 0.1736 - val_accuracy: 0.8578 - val_loss: 0.3611 - learning_rate: 1.0000e-04 Epoch 6/15 313/313 ━━━━━━━━━━━━━━━━━━━━ 2s 5ms/step - accuracy: 0.9529 - loss: 0.1365 - val_accuracy: 0.8586 - val_loss: 0.3935 - learning_rate: 5.0000e-05 测试集准确率: 0.8540, 测试集损失: 0.3377 /tmp/ipykernel_36/130590330.py:135: UserWarning: Glyph 35757 (\N{CJK UNIFIED IDEOGRAPH-8BAD}) missing from current font. plt.tight_layout() /tmp/ipykernel_36/130590330.py:135: UserWarning: Glyph 32451 (\N{CJK UNIFIED IDEOGRAPH-7EC3}) missing from current font. plt.tight_layout() /tmp/ipykernel_36/130590330.py:135: UserWarning: Glyph 36718 (\N{CJK UNIFIED IDEOGRAPH-8F6E}) missing from current font. plt.tight_layout() /tmp/ipykernel_36/130590330.py:135: UserWarning: Glyph 27425 (\N{CJK UNIFIED IDEOGRAPH-6B21}) missing from current font. plt.tight_layout() /tmp/ipykernel_36/130590330.py:135: UserWarning: Glyph 25439 (\N{CJK UNIFIED IDEOGRAPH-635F}) missing from current font. plt.tight_layout() /tmp/ipykernel_36/130590330.py:135: UserWarning: Glyph 22833 (\N{CJK UNIFIED IDEOGRAPH-5931}) missing from current font. plt.tight_layout() /tmp/ipykernel_36/130590330.py:135: UserWarning: Glyph 26354 (\N{CJK UNIFIED IDEOGRAPH-66F2}) missing from current font. plt.tight_layout() /tmp/ipykernel_36/130590330.py:135: UserWarning: Glyph 32447 (\N{CJK UNIFIED IDEOGRAPH-7EBF}) missing from current font. plt.tight_layout() /tmp/ipykernel_36/130590330.py:135: UserWarning: Glyph 39564 (\N{CJK UNIFIED IDEOGRAPH-9A8C}) missing from current font. plt.tight_layout() /tmp/ipykernel_36/130590330.py:135: UserWarning: Glyph 35777 (\N{CJK UNIFIED IDEOGRAPH-8BC1}) missing from current font. plt.tight_layout() /tmp/ipykernel_36/130590330.py:135: UserWarning: Glyph 20934 (\N{CJK UNIFIED IDEOGRAPH-51C6}) missing from current font. plt.tight_layout() /tmp/ipykernel_36/130590330.py:135: UserWarning: Glyph 30830 (\N{CJK UNIFIED IDEOGRAPH-786E}) missing from current font. plt.tight_layout() /tmp/ipykernel_36/130590330.py:135: UserWarning: Glyph 29575 (\N{CJK UNIFIED IDEOGRAPH-7387}) missing from current font. plt.tight_layout() /tmp/ipykernel_36/130590330.py:136: UserWarning: Glyph 35757 (\N{CJK UNIFIED IDEOGRAPH-8BAD}) missing from current font. plt.savefig('training_history.png') /tmp/ipykernel_36/130590330.py:136: UserWarning: Glyph 32451 (\N{CJK UNIFIED IDEOGRAPH-7EC3}) missing from current font. plt.savefig('training_history.png') /tmp/ipykernel_36/130590330.py:136: UserWarning: Glyph 36718 (\N{CJK UNIFIED IDEOGRAPH-8F6E}) missing from current font. plt.savefig('training_history.png') /tmp/ipykernel_36/130590330.py:136: UserWarning: Glyph 27425 (\N{CJK UNIFIED IDEOGRAPH-6B21}) missing from current font. plt.savefig('training_history.png') /tmp/ipykernel_36/130590330.py:136: UserWarning: Glyph 25439 (\N{CJK UNIFIED IDEOGRAPH-635F}) missing from current font. plt.savefig('training_history.png') /tmp/ipykernel_36/130590330.py:136: UserWarning: Glyph 22833 (\N{CJK UNIFIED IDEOGRAPH-5931}) missing from current font. plt.savefig('training_history.png') /tmp/ipykernel_36/130590330.py:136: UserWarning: Glyph 26354 (\N{CJK UNIFIED IDEOGRAPH-66F2}) missing from current font. plt.savefig('training_history.png') /tmp/ipykernel_36/130590330.py:136: UserWarning: Glyph 32447 (\N{CJK UNIFIED IDEOGRAPH-7EBF}) missing from current font. plt.savefig('training_history.png') /tmp/ipykernel_36/130590330.py:136: UserWarning: Glyph 39564 (\N{CJK UNIFIED IDEOGRAPH-9A8C}) missing from current font. plt.savefig('training_history.png') /tmp/ipykernel_36/130590330.py:136: UserWarning: Glyph 35777 (\N{CJK UNIFIED IDEOGRAPH-8BC1}) missing from current font. plt.savefig('training_history.png') /tmp/ipykernel_36/130590330.py:136: UserWarning: Glyph 20934 (\N{CJK UNIFIED IDEOGRAPH-51C6}) missing from current font. plt.savefig('training_history.png') /tmp/ipykernel_36/130590330.py:136: UserWarning: Glyph 30830 (\N{CJK UNIFIED IDEOGRAPH-786E}) missing from current font. plt.savefig('training_history.png') /tmp/ipykernel_36/130590330.py:136: UserWarning: Glyph 29575 (\N{CJK UNIFIED IDEOGRAPH-7387}) missing from current font. plt.savefig('training_history.png') /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 25439 (\N{CJK UNIFIED IDEOGRAPH-635F}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 22833 (\N{CJK UNIFIED IDEOGRAPH-5931}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 26354 (\N{CJK UNIFIED IDEOGRAPH-66F2}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 32447 (\N{CJK UNIFIED IDEOGRAPH-7EBF}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 35757 (\N{CJK UNIFIED IDEOGRAPH-8BAD}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 32451 (\N{CJK UNIFIED IDEOGRAPH-7EC3}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 36718 (\N{CJK UNIFIED IDEOGRAPH-8F6E}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 27425 (\N{CJK UNIFIED IDEOGRAPH-6B21}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 39564 (\N{CJK UNIFIED IDEOGRAPH-9A8C}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 35777 (\N{CJK UNIFIED IDEOGRAPH-8BC1}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 20934 (\N{CJK UNIFIED IDEOGRAPH-51C6}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 30830 (\N{CJK UNIFIED IDEOGRAPH-786E}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 29575 (\N{CJK UNIFIED IDEOGRAPH-7387}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) 782/782 ━━━━━━━━━━━━━━━━━━━━ 2s 2ms/step /tmp/ipykernel_36/130590330.py:150: UserWarning: Glyph 36127 (\N{CJK UNIFIED IDEOGRAPH-8D1F}) missing from current font. plt.savefig('confusion_matrix.png') /tmp/ipykernel_36/130590330.py:150: UserWarning: Glyph 38754 (\N{CJK UNIFIED IDEOGRAPH-9762}) missing from current font. plt.savefig('confusion_matrix.png') /tmp/ipykernel_36/130590330.py:150: UserWarning: Glyph 35780 (\N{CJK UNIFIED IDEOGRAPH-8BC4}) missing from current font. plt.savefig('confusion_matrix.png') /tmp/ipykernel_36/130590330.py:150: UserWarning: Glyph 35770 (\N{CJK UNIFIED IDEOGRAPH-8BBA}) missing from current font. plt.savefig('confusion_matrix.png') /tmp/ipykernel_36/130590330.py:150: UserWarning: Glyph 27491 (\N{CJK UNIFIED IDEOGRAPH-6B63}) missing from current font. plt.savefig('confusion_matrix.png') /tmp/ipykernel_36/130590330.py:150: UserWarning: Glyph 28151 (\N{CJK UNIFIED IDEOGRAPH-6DF7}) missing from current font. plt.savefig('confusion_matrix.png') /tmp/ipykernel_36/130590330.py:150: UserWarning: Glyph 28102 (\N{CJK UNIFIED IDEOGRAPH-6DC6}) missing from current font. plt.savefig('confusion_matrix.png') /tmp/ipykernel_36/130590330.py:150: UserWarning: Glyph 30697 (\N{CJK UNIFIED IDEOGRAPH-77E9}) missing from current font. plt.savefig('confusion_matrix.png') /tmp/ipykernel_36/130590330.py:150: UserWarning: Glyph 38453 (\N{CJK UNIFIED IDEOGRAPH-9635}) missing from current font. plt.savefig('confusion_matrix.png') <Figure size 600x600 with 0 Axes> /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 36127 (\N{CJK UNIFIED IDEOGRAPH-8D1F}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 38754 (\N{CJK UNIFIED IDEOGRAPH-9762}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 35780 (\N{CJK UNIFIED IDEOGRAPH-8BC4}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 35770 (\N{CJK UNIFIED IDEOGRAPH-8BBA}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 27491 (\N{CJK UNIFIED IDEOGRAPH-6B63}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 28151 (\N{CJK UNIFIED IDEOGRAPH-6DF7}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 28102 (\N{CJK UNIFIED IDEOGRAPH-6DC6}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 30697 (\N{CJK UNIFIED IDEOGRAPH-77E9}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /usr/local/lib/python3.11/dist-packages/IPython/core/pylabtools.py:151: UserWarning: Glyph 38453 (\N{CJK UNIFIED IDEOGRAPH-9635}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /tmp/ipykernel_36/130590330.py in <cell line: 0>() 205 206 # 可视化一个样本的注意力 --> 207 visualize_attention(model, sample_idx=42) /tmp/ipykernel_36/130590330.py in visualize_attention(model, sample_idx) 154 def visualize_attention(model, sample_idx): 155 # 创建返回注意力权重的模型 --> 156 attention_output = model.layers[2].attn.output[1] # 获取注意力权重 157 attention_model = keras.Model( 158 inputs=model.input, /usr/local/lib/python3.11/dist-packages/keras/src/ops/operation.py in output(self) 264 Output tensor or list of output tensors. 265 """ --> 266 return self._get_node_attribute_at_index(0, "output_tensors", "output") 267 268 def _get_node_attribute_at_index(self, node_index, attr, attr_name): /usr/local/lib/python3.11/dist-packages/keras/src/ops/operation.py in _get_node_attribute_at_index(self, node_index, attr, attr_name) 283 """ 284 if not self._inbound_nodes: --> 285 raise AttributeError( 286 f"The layer {self.name} has never been called " 287 f"and thus has no defined {attr_name}." AttributeError: The layer multi_head_attention has never been called and thus has no defined output.
最新发布
07-28
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值