Spaces:
Sleeping
Sleeping
Update inference.py
Browse files- inference.py +26 -47
inference.py
CHANGED
|
@@ -129,50 +129,29 @@ def evaluate_performance(args, model, scaler, device):
|
|
| 129 |
|
| 130 |
# --- 5. 메인 로직 ---
|
| 131 |
if __name__ == '__main__':
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
pred_path = os.path.join(output_dir, 'evaluation_preds.npy')
|
| 159 |
-
true_path = os.path.join(output_dir, 'evaluation_trues.npy')
|
| 160 |
-
np.save(pred_path, eval_preds)
|
| 161 |
-
np.save(true_path, eval_trues)
|
| 162 |
-
print(f"Evaluation results saved to {output_dir}", file=sys.stderr)
|
| 163 |
-
|
| 164 |
-
mae, mse, _, _, _ = metric(eval_preds, eval_trues)
|
| 165 |
-
final_output = {
|
| 166 |
-
"status": "success",
|
| 167 |
-
"mode": "rolling_evaluation",
|
| 168 |
-
"mse": mse,
|
| 169 |
-
"mae": mae,
|
| 170 |
-
"files": [pred_path, true_path] # 👈 파일 경로들 추가
|
| 171 |
-
}
|
| 172 |
-
else:
|
| 173 |
-
final_output = {"status": "error", "message": "No mode selected."}
|
| 174 |
-
|
| 175 |
-
except Exception as e:
|
| 176 |
-
final_output = {"status": "error", "message": traceback.format_exc()}
|
| 177 |
-
|
| 178 |
-
print(json.dumps(final_output, indent=2))
|
|
|
|
| 129 |
|
| 130 |
# --- 5. 메인 로직 ---
|
| 131 |
if __name__ == '__main__':
|
| 132 |
+
# 결과 저장 폴더 생성
|
| 133 |
+
output_dir = 'pred_results'
|
| 134 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 135 |
+
|
| 136 |
+
model, scaler, device = load_model_and_scaler(args)
|
| 137 |
+
|
| 138 |
+
if args.predict_input_file:
|
| 139 |
+
print("\n--- Running in Single Prediction Mode ---")
|
| 140 |
+
prediction = predict_future(args, model, scaler, device)
|
| 141 |
+
output_path = os.path.join(output_dir, 'prediction_future.npy')
|
| 142 |
+
np.save(output_path, prediction)
|
| 143 |
+
print(f"\n✅ Future prediction saved to {output_path}")
|
| 144 |
+
|
| 145 |
+
elif args.evaluate_file:
|
| 146 |
+
print("\n--- Running in Rolling Evaluation Mode ---")
|
| 147 |
+
eval_preds, eval_trues = evaluate_performance(args, model, scaler, device)
|
| 148 |
+
pred_path = os.path.join(output_dir, 'evaluation_preds.npy')
|
| 149 |
+
true_path = os.path.join(output_dir, 'evaluation_trues.npy')
|
| 150 |
+
np.save(pred_path, eval_preds)
|
| 151 |
+
np.save(true_path, eval_trues)
|
| 152 |
+
print(f"\n✅ Evaluation results saved to {output_dir}")
|
| 153 |
+
print(f" - Predictions shape: {eval_preds.shape}")
|
| 154 |
+
print(f" - Truths shape: {eval_trues.shape}")
|
| 155 |
+
|
| 156 |
+
else:
|
| 157 |
+
print("오류: --predict_input_file 또는 --evaluate_file 중 하나의 모드를 선택해야 합니다.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|