模型测试test.py出现错误KeyError:“val“如何解决?

在运行test.py时遇到KeyError,用户在数据集已分训练集、验证集和测试集,且yaml文件配置路径正确的情况下,寻求如何修正.py文件以消除报错的指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

运行测试test.py时,遇到KeyError:"val"的报错提示,不知道怎么解决,数据集划分为训练集,验证集和测试集,yaml文件配置路径正确,请问该怎么修改.py文件?

# -*- coding: utf-8 -*- import pandas as pd import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl from scipy import stats import sys import os # ===== 中文字体支持 ===== plt.rcParams['font.sans-serif'] = ['SimHei', 'Microsoft YaHei'] # 解决中文显示问题 plt.rcParams['axes.unicode_minus'] = False # 修复负号显示 # ===== 数据预处理 ===== def preprocess_data(data): """ 预处理近6年月度水沙通量数据 输入:DataFrame格式原始数据(需包含日期、月均流量、月均含沙量) 输出:处理后的月度时间序列(月流量均值、月排沙量均值) """ # 修复链式赋值警告(直接赋值替代inplace) data = data.copy() data['月均流量'] = data['月均流量'].fillna(data['月均流量'].mean()) data['月均含沙量'] = data['月均含沙量'].fillna(data['月均含沙量'].mean()) # 计算月排沙量(亿吨)[1](@ref) data['日期'] = pd.to_datetime(data['日期']) # 确保日期格式正确 days_in_month = data['日期'].dt.days_in_month data['月排沙量'] = data['月均流量'] * data['月均含沙量'] * days_in_month * 86400 * 1e-9 # 按月聚合(使用'ME'替代弃用的'M')[1,9](@ref) monthly_data = data.groupby(pd.Grouper(key='日期', freq='ME')).agg({ '月均流量': 'mean', '月排沙量': 'sum' }).reset_index() return monthly_data # ===== 累积距平法 ===== def cumulative_anomaly(series): """ 计算累积距平序列 输入:时间序列(月流量均值或月排沙量) 输出:累积距平序列、突变点索引 """ try: if series.size == 0 or series.isnull().all(): raise ValueError("输入序列为空或全为NaN值") mean_val = series.mean() anomalies = series - mean_val cum_anomaly = anomalies.cumsum() # 检测突变点(累积距平曲线一阶差分变号点)[5](@ref) diff_sign = np.sign(np.diff(cum_anomaly)) turning_points = np.where(np.diff(diff_sign) != 0)[0] + 1 return cum_anomaly, turning_points except Exception as e: print(f"累积距平计算错误: {str(e)}") return pd.Series(dtype=float), np.array([]) # ===== Mann-Kendall突变检验 ===== def mk_test(series, alpha=0.05): """ Mann-Kendall突变检验 输入:时间序列、显著性水平alpha 输出:UF统计量序列、UB统计量序列、突变点位置 """ n = len(series) UF = np.zeros(n) s = 0 # 计算UF统计量(修正索引范围)[1,9](@ref) for i in range(1, n): for j in range(i): if series[i] > series[j]: s += 1 elif series[i] < series[j]: s -= 1 E = i * (i - 1) / 4 Var = i * (i - 1) * (2 * i + 5) / 72 UF[i] = (s - E) / np.sqrt(Var) if Var > 0 else 0 # 计算UB统计量(确保与UF等长)[5](@ref) UB = -UF[::-1] # 关键修复:直接反向取负 # 检测显著突变点(UF与UB在置信区间内的交点)[1](@ref) critical_value = stats.norm.ppf(1 - alpha / 2) cross_points = [] for i in range(1, n): if (UF[i] * UB[i] < 0) and (abs(UF[i]) > critical_value): cross_points.append(i) return UF, UB, np.array(cross_points) # ===== 主程序 ===== if __name__ == "__main__": try: print("=" * 60) print("水沙通量突变性分析程序启动...") print("=" * 60) # 1. 数据加载(替换为实际数据路径)[1](@ref) # 模拟数据(实际使用时替换此部分) dates = pd.date_range('2016-01-01', '2021-12-31', freq='ME') np.random.seed(42) flow = np.random.normal(loc=1000, scale=200, size=len(dates)) sand = np.random.normal(loc=2.5, scale=0.8, size=len(dates)) raw_data = pd.DataFrame({ '日期': dates, '月均流量': flow, '月均含沙量': sand }) print("✅ 模拟数据生成完成(共{}条记录)".format(len(raw_data))) # 2. 数据预处理 processed_data = preprocess_data(raw_data) print("✅ 数据预处理完成(含排沙量计算)") # 3. 突变性分析(以月流量为例) flow_series = processed_data['月均流量'].dropna() if flow_series.size == 0: raise ValueError("流量序列为空,请检查数据!") # 3.1 累积距平法 cum_anomaly, turning_points = cumulative_anomaly(flow_series) print("📊 累积距平法检测到{}个突变点".format(len(turning_points))) # 3.2 M-K检验 UF, UB, cross_points = mk_test(flow_series.values) print("📈 MK检验检测到{}个显著突变点".format(len(cross_points))) # 4. 可视化 fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 10), dpi=100) # 4.1 累积距平曲线 ax1.set_title('月流量累积距平曲线', fontsize=14) ax1.plot(processed_data['日期'], cum_anomaly, 'b-', label='累积距平') ax1.set_ylabel('累积距平值', fontsize=12) ax1.grid(True, linestyle='--', alpha=0.7) # 标记突变点 if len(turning_points) > 0: ax1.scatter( processed_data['日期'].iloc[turning_points], cum_anomaly.iloc[turning_points], c='red', s=80, label='突变点' ) for idx in turning_points: ax1.annotate( processed_data['日期'].dt.strftime('%Y-%m').iloc[idx], (processed_data['日期'].iloc[idx], cum_anomaly.iloc[idx]), xytext=(0, 15), textcoords='offset points', ha='center', fontsize=9 ) ax1.legend() # 4.2 M-K检验曲线 ax2.set_title('Mann-Kendall突变检验', fontsize=14) ax2.plot(processed_data['日期'], UF, 'r-', label='UF统计量') ax2.plot(processed_data['日期'], UB, 'b--', label='UB统计量') ax2.axhline(y=1.96, color='gray', linestyle='--', label='95%置信区间') ax2.axhline(y=-1.96, color='gray', linestyle='--') ax2.axhline(y=0, color='black', linewidth=0.8) ax2.set_ylabel('统计量值', fontsize=12) ax2.set_xlabel('日期', fontsize=12) ax2.grid(True, linestyle='--', alpha=0.7) # 标记显著突变点 if len(cross_points) > 0: ax2.scatter( processed_data['日期'].iloc[cross_points], UF[cross_points], c='black', s=100, label='显著突变点' ) for idx in cross_points: ax2.annotate( processed_data['日期'].dt.strftime('%Y-%m').iloc[idx], (processed_data['日期'].iloc[idx], UF[idx]), xytext=(0, 10), textcoords='offset points', ha='center', fontsize=9 ) ax2.legend() plt.tight_layout() # 5. 保存结果 output_path = os.path.join(os.getcwd(), '水沙通量突变性分析结果.png') plt.savefig(output_path, dpi=300, bbox_inches='tight') print("=" * 60) print(f"✅ 分析结果已保存至: {output_path}") print("=" * 60) # 6. 结果显示 plt.show() except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() print("❌" * 60) print(f"程序异常终止 (行:{exc_tb.tb_lineno}): {str(e)}") print("❌" * 60) 报错内容·如下E:\Anaconda\python.exe C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py 生成模拟数据... 开始数据预处理... 数据预处理完成 E:\Anaconda\Lib\site-packages\statsmodels\tsa\seasonal.py:360: UserWarning: Glyph 27969 (\N{CJK UNIFIED IDEOGRAPH-6D41}) missing from font(s) DejaVu Sans. fig.tight_layout() E:\Anaconda\Lib\site-packages\statsmodels\tsa\seasonal.py:360: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) DejaVu Sans. fig.tight_layout() E:\Anaconda\Lib\site-packages\statsmodels\tsa\seasonal.py:360: UserWarning: Glyph 21547 (\N{CJK UNIFIED IDEOGRAPH-542B}) missing from font(s) DejaVu Sans. fig.tight_layout() E:\Anaconda\Lib\site-packages\statsmodels\tsa\seasonal.py:360: UserWarning: Glyph 27801 (\N{CJK UNIFIED IDEOGRAPH-6C99}) missing from font(s) DejaVu Sans. fig.tight_layout() E:\Anaconda\Lib\site-packages\statsmodels\tsa\seasonal.py:360: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) DejaVu Sans. fig.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:149: UserWarning: Glyph 21547 (\N{CJK UNIFIED IDEOGRAPH-542B}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:149: UserWarning: Glyph 27801 (\N{CJK UNIFIED IDEOGRAPH-6C99}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:149: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:149: UserWarning: Glyph 23395 (\N{CJK UNIFIED IDEOGRAPH-5B63}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:149: UserWarning: Glyph 33410 (\N{CJK UNIFIED IDEOGRAPH-8282}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:149: UserWarning: Glyph 24615 (\N{CJK UNIFIED IDEOGRAPH-6027}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:149: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:149: UserWarning: Glyph 35299 (\N{CJK UNIFIED IDEOGRAPH-89E3}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:150: UserWarning: Glyph 21547 (\N{CJK UNIFIED IDEOGRAPH-542B}) missing from font(s) DejaVu Sans. plt.savefig('季节性分解.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:150: UserWarning: Glyph 27801 (\N{CJK UNIFIED IDEOGRAPH-6C99}) missing from font(s) DejaVu Sans. plt.savefig('季节性分解.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:150: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) DejaVu Sans. plt.savefig('季节性分解.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:150: UserWarning: Glyph 23395 (\N{CJK UNIFIED IDEOGRAPH-5B63}) missing from font(s) DejaVu Sans. plt.savefig('季节性分解.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:150: UserWarning: Glyph 33410 (\N{CJK UNIFIED IDEOGRAPH-8282}) missing from font(s) DejaVu Sans. plt.savefig('季节性分解.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:150: UserWarning: Glyph 24615 (\N{CJK UNIFIED IDEOGRAPH-6027}) missing from font(s) DejaVu Sans. plt.savefig('季节性分解.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:150: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) DejaVu Sans. plt.savefig('季节性分解.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:150: UserWarning: Glyph 35299 (\N{CJK UNIFIED IDEOGRAPH-89E3}) missing from font(s) DejaVu Sans. plt.savefig('季节性分解.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:151: UserWarning: Glyph 27969 (\N{CJK UNIFIED IDEOGRAPH-6D41}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:151: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:151: UserWarning: Glyph 23395 (\N{CJK UNIFIED IDEOGRAPH-5B63}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:151: UserWarning: Glyph 33410 (\N{CJK UNIFIED IDEOGRAPH-8282}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:151: UserWarning: Glyph 24615 (\N{CJK UNIFIED IDEOGRAPH-6027}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:151: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:151: UserWarning: Glyph 35299 (\N{CJK UNIFIED IDEOGRAPH-89E3}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:151: UserWarning: Glyph 21547 (\N{CJK UNIFIED IDEOGRAPH-542B}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:151: UserWarning: Glyph 27801 (\N{CJK UNIFIED IDEOGRAPH-6C99}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 26085 (\N{CJK UNIFIED IDEOGRAPH-65E5}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 26399 (\N{CJK UNIFIED IDEOGRAPH-671F}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 20540 (\N{CJK UNIFIED IDEOGRAPH-503C}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 27969 (\N{CJK UNIFIED IDEOGRAPH-6D41}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 21407 (\N{CJK UNIFIED IDEOGRAPH-539F}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 22987 (\N{CJK UNIFIED IDEOGRAPH-59CB}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 26102 (\N{CJK UNIFIED IDEOGRAPH-65F6}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 38388 (\N{CJK UNIFIED IDEOGRAPH-95F4}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 24207 (\N{CJK UNIFIED IDEOGRAPH-5E8F}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 21015 (\N{CJK UNIFIED IDEOGRAPH-5217}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 23610 (\N{CJK UNIFIED IDEOGRAPH-5C3A}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 24230 (\N{CJK UNIFIED IDEOGRAPH-5EA6}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 22825 (\N{CJK UNIFIED IDEOGRAPH-5929}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 23567 (\N{CJK UNIFIED IDEOGRAPH-5C0F}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 27874 (\N{CJK UNIFIED IDEOGRAPH-6CE2}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 31995 (\N{CJK UNIFIED IDEOGRAPH-7CFB}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 23454 (\N{CJK UNIFIED IDEOGRAPH-5B9E}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 37096 (\N{CJK UNIFIED IDEOGRAPH-90E8}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 31561 (\N{CJK UNIFIED IDEOGRAPH-7B49}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 32447 (\N{CJK UNIFIED IDEOGRAPH-7EBF}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 22270 (\N{CJK UNIFIED IDEOGRAPH-56FE}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 26041 (\N{CJK UNIFIED IDEOGRAPH-65B9}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 24046 (\N{CJK UNIFIED IDEOGRAPH-5DEE}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 26512 (\N{CJK UNIFIED IDEOGRAPH-6790}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 20027 (\N{CJK UNIFIED IDEOGRAPH-4E3B}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:129: UserWarning: Glyph 21608 (\N{CJK UNIFIED IDEOGRAPH-5468}) missing from font(s) DejaVu Sans. plt.tight_layout() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 20540 (\N{CJK UNIFIED IDEOGRAPH-503C}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 27969 (\N{CJK UNIFIED IDEOGRAPH-6D41}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 21407 (\N{CJK UNIFIED IDEOGRAPH-539F}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 22987 (\N{CJK UNIFIED IDEOGRAPH-59CB}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 26102 (\N{CJK UNIFIED IDEOGRAPH-65F6}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 38388 (\N{CJK UNIFIED IDEOGRAPH-95F4}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 24207 (\N{CJK UNIFIED IDEOGRAPH-5E8F}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 21015 (\N{CJK UNIFIED IDEOGRAPH-5217}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 26085 (\N{CJK UNIFIED IDEOGRAPH-65E5}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 26399 (\N{CJK UNIFIED IDEOGRAPH-671F}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 23610 (\N{CJK UNIFIED IDEOGRAPH-5C3A}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 24230 (\N{CJK UNIFIED IDEOGRAPH-5EA6}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 22825 (\N{CJK UNIFIED IDEOGRAPH-5929}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 23567 (\N{CJK UNIFIED IDEOGRAPH-5C0F}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 27874 (\N{CJK UNIFIED IDEOGRAPH-6CE2}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 31995 (\N{CJK UNIFIED IDEOGRAPH-7CFB}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 23454 (\N{CJK UNIFIED IDEOGRAPH-5B9E}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 37096 (\N{CJK UNIFIED IDEOGRAPH-90E8}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 31561 (\N{CJK UNIFIED IDEOGRAPH-7B49}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 32447 (\N{CJK UNIFIED IDEOGRAPH-7EBF}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 22270 (\N{CJK UNIFIED IDEOGRAPH-56FE}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 26041 (\N{CJK UNIFIED IDEOGRAPH-65B9}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 24046 (\N{CJK UNIFIED IDEOGRAPH-5DEE}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 26512 (\N{CJK UNIFIED IDEOGRAPH-6790}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 20027 (\N{CJK UNIFIED IDEOGRAPH-4E3B}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:130: UserWarning: Glyph 21608 (\N{CJK UNIFIED IDEOGRAPH-5468}) missing from font(s) DejaVu Sans. plt.savefig(f'{title}_小波分析.png', dpi=300) C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 25968 (\N{CJK UNIFIED IDEOGRAPH-6570}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 20540 (\N{CJK UNIFIED IDEOGRAPH-503C}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 27969 (\N{CJK UNIFIED IDEOGRAPH-6D41}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 37327 (\N{CJK UNIFIED IDEOGRAPH-91CF}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 21407 (\N{CJK UNIFIED IDEOGRAPH-539F}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 22987 (\N{CJK UNIFIED IDEOGRAPH-59CB}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 26102 (\N{CJK UNIFIED IDEOGRAPH-65F6}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 38388 (\N{CJK UNIFIED IDEOGRAPH-95F4}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 24207 (\N{CJK UNIFIED IDEOGRAPH-5E8F}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 21015 (\N{CJK UNIFIED IDEOGRAPH-5217}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 26085 (\N{CJK UNIFIED IDEOGRAPH-65E5}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 26399 (\N{CJK UNIFIED IDEOGRAPH-671F}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 23610 (\N{CJK UNIFIED IDEOGRAPH-5C3A}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 24230 (\N{CJK UNIFIED IDEOGRAPH-5EA6}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 22825 (\N{CJK UNIFIED IDEOGRAPH-5929}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 23567 (\N{CJK UNIFIED IDEOGRAPH-5C0F}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 27874 (\N{CJK UNIFIED IDEOGRAPH-6CE2}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 31995 (\N{CJK UNIFIED IDEOGRAPH-7CFB}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 23454 (\N{CJK UNIFIED IDEOGRAPH-5B9E}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 37096 (\N{CJK UNIFIED IDEOGRAPH-90E8}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 31561 (\N{CJK UNIFIED IDEOGRAPH-7B49}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 32447 (\N{CJK UNIFIED IDEOGRAPH-7EBF}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 22270 (\N{CJK UNIFIED IDEOGRAPH-56FE}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 26041 (\N{CJK UNIFIED IDEOGRAPH-65B9}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 24046 (\N{CJK UNIFIED IDEOGRAPH-5DEE}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 20998 (\N{CJK UNIFIED IDEOGRAPH-5206}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 26512 (\N{CJK UNIFIED IDEOGRAPH-6790}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 20027 (\N{CJK UNIFIED IDEOGRAPH-4E3B}) missing from font(s) DejaVu Sans. plt.show() C:\Users\cheny\Desktop\PythonProject2\水沙通量周期性模型.py:131: UserWarning: Glyph 21608 (\N{CJK UNIFIED IDEOGRAPH-5468}) missing from font(s) DejaVu Sans. plt.show()
07-20
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
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值