UserWarning: Method on_batch_end() is slow compared to the batch update. Check your callbacks.

Keras训练verbose参数问题解决
博客提到GitHub上Keras相关问题(issue/2603),原因是berbose=1时,训练一个batch打印进度条和结果到控制台的时间比训练模型时间长而出现警告。解决办法是将verbose设为0,不打印训练过程信息;设为2,每个epoch打印一次。

https://github.com/keras-team/keras/issues/2603

history=model.fit(X_train,y_train,epochs=30,batch_size=32,validation_split=0.2,verbose=2)

出现的原因是一开始berbose=1(默认),在一个epoch中训练一个batch就会打印进度条和结果,但是打印到控制台所需时间比训练模型时间更长,所以有了警告。

将verbose=0,使得一点训练过程信息也不打印;verbose=2,每一个epoch打印一次。

 

转载于:https://www.cnblogs.com/BlueBlueSea/p/11063712.html

Code 分享 Notebook 保存成功 Python 3 (ipykernel) import os import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.preprocessing import MinMaxScaler from tensorflow.keras import layers,losses,optimizers, Sequential from tensorflow.keras.layers import InputLayer, Dense, LSTM, Dropout from tensorflow.keras.models import load_model from tensorflow.keras import Model 0秒 + Code + Markdown stock_data = pd.read_csv('IBM_stock_data.csv') 0秒 + Code + Markdown stock_data.head() 0秒 date Open High Low Close Volume Price Change % 0 1999/11/1 98.50 98.81 96.37 96.75 9551800 0.000000 1 1999/11/2 96.75 96.81 93.69 94.81 11105400 -2.005168 2 1999/11/3 95.87 95.94 93.50 94.37 10369100 -0.464086 3 1999/11/4 94.44 94.44 90.00 91.56 16697600 -2.977641 4 1999/11/5 92.75 92.94 90.19 90.25 13737600 -1.430756 + Code + Markdown scaler = MinMaxScaler(feature_range=(0, 1)) scaled_data = scaler.fit_transform(stock_data['Close'].values.reshape(-1, 1)) 0秒 + Code + Markdown scaled_data[0] 0秒 array([0.23131139]) + Code + Markdown len(scaled_data) 0秒 6293 + Code + Markdown training_data_len = int(np.ceil(len(scaled_data) * 0.8)) #向上取整 0秒 + Code + Markdown train_data = scaled_data[0:training_data_len] X_train, y_train = [], [] time_step = 10 # 时间窗口,模型基于前10个时间步长进行预测。可以尝试不同长度(如20、30)并观察效果变化。 0秒 + Code + Markdown for i in range(len(train_data) - time_step - 1): X_train.append(train_data[i:(i + time_step), 0]) y_train.append(train_data[i + time_step, 0]) 0秒 + Code + Markdown X_train, y_train = np.array(X_train), np.array(y_train) X_train = X_train.reshape(X_train.shape[0], X_train.shape[1], 1) 0秒 + Code + Markdown X_train.shape 0秒 (5024, 10, 1) + Code + Markdown X_test, y_test = [], [] test_data = scaled_data[training_data_len - time_step:] ​ for i in range(len(test_data) - time_step): X_test.append(test_data[i:(i + time_step), 0]) y_test.append(test_data[i + time_step, 0]) ​ X_test, y_test = np.array(X_test), np.array(y_test) X_test = X_test.reshape(X_test.shape[0], X_test.shape[1], 1) 0秒 + Code + Markdown model = Sequential() model.add(InputLayer(input_shape=(X_train.shape[1], 1))) model.add(LSTM(units=64, return_sequences=True)) # 调整Dropout: 当前设置为0.3,可以尝试在不同的层上使用不同的Dropout值,例如0.2~0.5之间。Dropout的作用是防止过拟合。 model.add(Dropout(0.3)) model.add(LSTM(units=64, return_sequences=True)) model.add(Dropout(0.3)) model.add(LSTM(units=32)) model.add(Dropout(0.2)) # 增加回归层: 如果希望更高的拟合精度,可以添加多个Dense层,例如在输出前再增加一层Dense。 model.add(Dense(units=1)) 3秒 2025-06-21 16:21:14.205566: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory 2025-06-21 16:21:14.205665: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303) 2025-06-21 16:21:14.205686: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (dsw-1161427-779497c87d-j6j54): /proc/driver/nvidia/version does not exist 2025-06-21 16:21:14.206190: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 AVX512F FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. + Code + Markdown def MyRNN(): model = Sequential([ layers.InputLayer(input_shape=(X_train.shape[1],1)), layers.SimpleRNN(units=64, dropout=0.5, return_sequences=True, unroll=True), layers.SimpleRNN(units=64, dropout=0.5, unroll=True), layers.Dense(1)] ) return model 0秒 + Code + Markdown model = MyRNN() model.compile(optimizer='adam', loss='mean_squared_error') 0秒 + Code + Markdown history = model.fit( X_train, y_train, epochs=2, # 批大小(batch_size): 尝试不同的batch_size,例如16、32、64,以找到训练稳定性和准确性之间的平衡 batch_size=32, #callbacks=[early_stopping, lr_scheduler] ) 12秒 Epoch 1/2 WARNING:tensorflow:AutoGraph could not transform <function Model.make_train_function.<locals>.train_function at 0x7f02c8692040> and will run it as-is. Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: module 'gast' has no attribute 'Constant' To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert WARNING: AutoGraph could not transform <function Model.make_train_function.<locals>.train_function at 0x7f02c8692040> and will run it as-is. Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: module 'gast' has no attribute 'Constant' To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert 157/157 [==============================] - 9s 20ms/step - loss: 0.0396 Epoch 2/2 157/157 [==============================] - 3s 21ms/step - loss: 0.0266 + Code + Markdown model.save('my_model.keras') 0秒 + Code + Markdown train_loss = model.evaluate(X_train, y_train, verbose=0) test_loss = model.evaluate(X_test, y_test, verbose=0) 5秒 WARNING:tensorflow:AutoGraph could not transform <function Model.make_test_function.<locals>.test_function at 0x7f02cc2b5dc0> and will run it as-is. Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: module 'gast' has no attribute 'Constant' To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert WARNING: AutoGraph could not transform <function Model.make_test_function.<locals>.test_function at 0x7f02cc2b5dc0> and will run it as-is. Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: module 'gast' has no attribute 'Constant' To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert + Code + Markdown # 训练集上计算的损失值,数值越小表示模型在训练数据上的拟合效果越好 print(f"Training Loss: {train_loss:.4f}") # 测试集上计算的损失值,反映了模型在未见过的数据上的表现。测试损失略高于训练损失,但差距不大,说明模型在新数据上的表现依然良好。 print(f"Testing Loss: {test_loss:.4f}") 0秒 Training Loss: 0.0412 Testing Loss: 0.0480 + Code + Markdown model = load_model('my_model.keras') predictions = model.predict(X_test) predictions = scaler.inverse_transform(predictions) # 反归一化预测值 2秒 WARNING:tensorflow:AutoGraph could not transform <function Model.make_predict_function.<locals>.predict_function at 0x7f0276f14040> and will run it as-is. Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: module 'gast' has no attribute 'Constant' To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert WARNING: AutoGraph could not transform <function Model.make_predict_function.<locals>.predict_function at 0x7f0276f14040> and will run it as-is. Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, `export AUTOGRAPH_VERBOSITY=10`) and attach the full output. Cause: module 'gast' has no attribute 'Constant' To silence this warning, decorate the function with @tf.autograph.experimental.do_not_convert + Code + Markdown import matplotlib.pyplot as plt plt.rcParams['font.sans-serif'] = ['SimHei'] # 设置中文字体为黑体 plt.rcParams['axes.unicode_minus'] = False # 正确显示负号 0秒 + Code + Markdown %matplotlib inline 0秒 + Code + Markdown Code train = stock_data[:training_data_len] valid = stock_data[training_data_len:] valid.loc[:, 'Predictions'] = predictions ​ ​ # 绘制图像 plt.figure(figsize=(14, 5)) plt.title('股票价格预测', fontsize=20) # 图表标题改为中文 plt.xlabel('日期', fontsize=14) # X 轴标签改为中文 plt.ylabel('收盘价', fontsize=14) # Y 轴标签改为中文 plt.plot(train['date'], train['Close'], label='训练数据', color='blue') # 训练数据标签改为中文 plt.plot(valid['date'], valid['Close'], label='真实价格', color='green') # 真实价格标签改为中文 plt.plot(valid['date'], valid['Predictions'], label='预测价格', color='red') # 预测价格标签改为中文 plt.legend() # 添加图例 # 添加保存图像的代码 plt.savefig('stock_price_predictions.png') # 保存图像 plt.show() ​ # 计算和输出评估指标 rmse = np.sqrt(np.mean(np.square(predictions - y_test))) mae = np.mean(np.abs(predictions - y_test)) print(f'均方根误差 (RMSE): {rmse}, 平均绝对误差 (MAE): {mae}') # 输出信息改为中文 4分钟58秒 /opt/conda/lib/python3.8/site-packages/pandas/core/indexing.py:1667: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy self.obj[key] = value findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans. findfont: Generic family 'sans-serif' not found because none of the following families were found: SimHei /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 32929 (\N{CJK UNIFIED IDEOGRAPH-80A1}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 31080 (\N{CJK UNIFIED IDEOGRAPH-7968}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 20215 (\N{CJK UNIFIED IDEOGRAPH-4EF7}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 26684 (\N{CJK UNIFIED IDEOGRAPH-683C}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 39044 (\N{CJK UNIFIED IDEOGRAPH-9884}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 27979 (\N{CJK UNIFIED IDEOGRAPH-6D4B}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans. findfont: Generic family 'sans-serif' not found because none of the following families were found: SimHei findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans. findfont: Generic family 'sans-serif' not found because none of the following families were found: SimHei /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 26085 (\N{CJK UNIFIED IDEOGRAPH-65E5}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 26399 (\N{CJK UNIFIED IDEOGRAPH-671F}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 25910 (\N{CJK UNIFIED IDEOGRAPH-6536}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 30424 (\N{CJK UNIFIED IDEOGRAPH-76D8}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 35757 (\N{CJK UNIFIED IDEOGRAPH-8BAD}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 32451 (\N{CJK UNIFIED IDEOGRAPH-7EC3}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 25454 (\N{CJK UNIFIED IDEOGRAPH-636E}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 30495 (\N{CJK UNIFIED IDEOGRAPH-771F}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 /tmp/ipykernel_18835/4137420046.py:16: UserWarning: Glyph 23454 (\N{CJK UNIFIED IDEOGRAPH-5B9E}) missing from current font. plt.savefig('stock_price_predictions.png') # 保存图像 /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 26085 (\N{CJK UNIFIED IDEOGRAPH-65E5}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 26399 (\N{CJK UNIFIED IDEOGRAPH-671F}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 25910 (\N{CJK UNIFIED IDEOGRAPH-6536}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 30424 (\N{CJK UNIFIED IDEOGRAPH-76D8}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 20215 (\N{CJK UNIFIED IDEOGRAPH-4EF7}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 32929 (\N{CJK UNIFIED IDEOGRAPH-80A1}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 31080 (\N{CJK UNIFIED IDEOGRAPH-7968}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 26684 (\N{CJK UNIFIED IDEOGRAPH-683C}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 39044 (\N{CJK UNIFIED IDEOGRAPH-9884}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 27979 (\N{CJK UNIFIED IDEOGRAPH-6D4B}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 35757 (\N{CJK UNIFIED IDEOGRAPH-8BAD}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 32451 (\N{CJK UNIFIED IDEOGRAPH-7EC3}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 25454 (\N{CJK UNIFIED IDEOGRAPH-636E}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 30495 (\N{CJK UNIFIED IDEOGRAPH-771F}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) /opt/conda/lib/python3.8/site-packages/IPython/core/pylabtools.py:152: UserWarning: Glyph 23454 (\N{CJK UNIFIED IDEOGRAPH-5B9E}) missing from current font. fig.canvas.print_figure(bytes_io, **kw) 均方根误差 (RMSE): 105.03158114646604, 平均绝对误差 (MAE): 104.21013102460681误差好大,还有中文显示不成功
06-22
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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值