64 lines
1.7 KiB
Python
64 lines
1.7 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
创建测试模型文件来验证前端集成
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import torch
|
|
sys.path.append('server')
|
|
|
|
def create_test_model():
|
|
"""创建一个简单的测试模型文件"""
|
|
from utils.model_manager import model_manager
|
|
|
|
# 创建简单的测试模型数据
|
|
model_data = {
|
|
'model_state_dict': {'test': 'data'}, # 简化的模型状态
|
|
'config': {
|
|
'model_type': 'tcn',
|
|
'input_dim': 8,
|
|
'output_dim': 7,
|
|
'sequence_length': 30,
|
|
'forecast_horizon': 7
|
|
},
|
|
'metrics': {
|
|
'mse': 150.0,
|
|
'rmse': 12.25,
|
|
'mae': 9.5,
|
|
'r2': 0.85,
|
|
'mape': 15.2
|
|
}
|
|
}
|
|
|
|
try:
|
|
# 使用ASCII字符避免编码问题
|
|
model_path = model_manager.save_model(
|
|
model_data=model_data,
|
|
product_id='P001',
|
|
model_type='tcn',
|
|
version='v1',
|
|
training_mode='product',
|
|
product_name='Test Product' # 使用英文名称避免编码问题
|
|
)
|
|
|
|
print(f"Test model saved: {model_path}")
|
|
|
|
# 验证模型列表
|
|
models = model_manager.list_models()
|
|
print(f"Found {len(models)} models")
|
|
|
|
if models:
|
|
model = models[0]
|
|
print(f"Model filename: {model.get('filename')}")
|
|
print(f"Product: {model.get('product_name')}")
|
|
print(f"Type: {model.get('model_type')}")
|
|
|
|
return True
|
|
|
|
except Exception as e:
|
|
print(f"Error creating test model: {e}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
create_test_model() |