guohanghui commited on
Commit
8616b68
·
verified ·
1 Parent(s): a471fe9

Update pest/source/src/utils.py

Browse files
Files changed (1) hide show
  1. pest/source/src/utils.py +8 -23
pest/source/src/utils.py CHANGED
@@ -69,13 +69,8 @@ def load_model(model_path: str):
69
  break
70
 
71
  if actual_path is None:
72
- # 如果找不到模型文件,返回一个模拟的模型对象
73
- print(f"Model file not found, using mock model for: {model_path}")
74
- return {
75
- 'model': 'mock_model',
76
- 'model_path': model_path,
77
- 'is_mock': True
78
- }
79
 
80
  # 加载真实的TorchScript模型
81
  model = torch.jit.load(actual_path, map_location='cpu')
@@ -99,13 +94,8 @@ def load_model(model_path: str):
99
  'is_mock': False
100
  }
101
  except Exception as e:
102
- # 如果加载失败,返回模拟版本
103
- print(f"Model loading failed: {str(e)}, using mock model")
104
- return {
105
- 'model': 'mock_model',
106
- 'model_path': model_path,
107
- 'is_mock': True
108
- }
109
 
110
 
111
  def preprocess_image(image_path: str):
@@ -134,12 +124,8 @@ def preprocess_image(image_path: str):
134
  break
135
 
136
  if actual_path is None:
137
- # 如果找不到图像文件,返回模拟图像信息
138
- print(f"Image file not found: {image_path}, using mock image")
139
- return {
140
- 'image_path': image_path,
141
- 'is_mock': True
142
- }
143
 
144
  # 打开真实图像并存储为全局变量
145
  image = Image.open(actual_path).convert('RGB')
@@ -151,9 +137,8 @@ def preprocess_image(image_path: str):
151
  'is_mock': False
152
  }
153
  except Exception as e:
154
- # 如果处理失败,返回简化版本
155
- print(f"Image preprocessing failed: {str(e)}")
156
- return f"Image preprocessed: {image_path} (Error: {str(e)})"
157
 
158
 
159
  def postprocess_results(detection_results):
 
69
  break
70
 
71
  if actual_path is None:
72
+ # 如果找不到模型文件,抛出错误
73
+ raise FileNotFoundError(f"Model file not found: {model_path}")
 
 
 
 
 
74
 
75
  # 加载真实的TorchScript模型
76
  model = torch.jit.load(actual_path, map_location='cpu')
 
94
  'is_mock': False
95
  }
96
  except Exception as e:
97
+ # 如果加载失败,抛出错误
98
+ raise RuntimeError(f"Model loading failed: {str(e)}")
 
 
 
 
 
99
 
100
 
101
  def preprocess_image(image_path: str):
 
124
  break
125
 
126
  if actual_path is None:
127
+ # 如果找不到图像文件,抛出错误
128
+ raise FileNotFoundError(f"Image file not found: {image_path}")
 
 
 
 
129
 
130
  # 打开真实图像并存储为全局变量
131
  image = Image.open(actual_path).convert('RGB')
 
137
  'is_mock': False
138
  }
139
  except Exception as e:
140
+ # 如果处理失败,抛出错误
141
+ raise RuntimeError(f"Image preprocessing failed: {str(e)}")
 
142
 
143
 
144
  def postprocess_results(detection_results):