fix(models): 解决 PyTorch 2.6+ 兼容性问题

- 在 garbage_model.py 和 smoke_model.py 中添加 weights_only=False 参数以允许加载模型类结构
- 修复 HTTP YOLO 检测器中的文件上传和响应解析逻辑- 移除不必要的导入并优化代码结构
- 添加自定义字节数组资源类以支持 RestTemplate 文件上传- 改进错误处理和日志记录机制
This commit is contained in:
2025-10-07 17:53:34 +08:00
parent 5f6058c024
commit aa32f9e9ac
3 changed files with 103 additions and 39 deletions

View File

@@ -45,7 +45,11 @@ class Model:
# 方法3: 通用 PyTorch 加载
print(f"YOLOv5 加载失败: {e}")
print("使用通用 PyTorch 加载")
self.model = torch.load(model_path, map_location=self.device)
self.model = torch.load(
model_path,
map_location=self.device,
weights_only=False # 允许加载模型类结构(解决 PyTorch 2.6+ 兼容性问题)
)
if isinstance(self.model, dict) and 'model' in self.model:
self.model = self.model['model']
self.yolov5_api = False