ShopTRAINING/test/test_model_id_debug.py
2025-07-02 11:05:23 +08:00

59 lines
2.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
专门调试model_id问题
"""
import urllib.request
import json
def debug_model_id():
try:
print("=== 调试model_id为空问题 ===")
url = 'http://localhost:5000/api/models'
with urllib.request.urlopen(url) as response:
data = response.read().decode('utf-8')
result = json.loads(data)
models = result.get('data', [])
print(f"API返回 {len(models)} 个模型")
for i, model in enumerate(models):
print(f"\n=== 模型 {i+1} 完整数据 ===")
# 显示所有字段
for key, value in model.items():
if key == 'metrics' and isinstance(value, dict) and not value:
print(f"{key}: (空字典)")
else:
print(f"{key}: '{value}' ({type(value).__name__})")
# 特别检查filename和model_id的关系
filename = model.get('filename', '')
model_id = model.get('model_id', '')
print(f"\n--- 关键字段分析 ---")
print(f"filename存在: {bool(filename)}")
print(f"filename值: '{filename}'")
print(f"model_id存在: {bool(model_id)}")
print(f"model_id值: '{model_id}'")
if filename:
expected_model_id = filename.replace('.pth', '')
print(f"根据filename生成的期望model_id: '{expected_model_id}'")
print(f"实际model_id是否匹配: {model_id == expected_model_id}")
else:
print("❌ filename为空无法生成model_id")
# 删除URL分析
if model_id:
delete_url = f"/api/models/{model_id}"
print(f"删除URL: {delete_url}")
else:
delete_url = f"/api/models/{model_id}" # 这会是 /api/models/
print(f"❌ 错误的删除URL: {delete_url} (会导致404)")
except Exception as e:
print(f"调试失败: {e}")
if __name__ == "__main__":
debug_model_id()