alwaysgood commited on
Commit
bd6bbcc
·
verified ·
1 Parent(s): 53efa2f

Update inference.py

Browse files
Files changed (1) hide show
  1. 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
- final_output = {}
133
- try:
134
- model, scaler, device = load_model_and_scaler(args)
135
- output_dir = 'pred_results'
136
- os.makedirs(output_dir, exist_ok=True)
137
-
138
- if args.predict_input_file:
139
- print("--- Running in Single Prediction Mode ---", file=sys.stderr)
140
- prediction = predict_future(args, model, scaler, device)
141
-
142
- # ⭐️ 결과 파일을 저장하고, 그 경로를 final_output에 추가
143
- output_path = os.path.join(output_dir, 'prediction_future.npy')
144
- np.save(output_path, prediction)
145
- print(f"Future prediction saved to {output_path}", file=sys.stderr)
146
-
147
- final_output = {
148
- "status": "success",
149
- "mode": "single_prediction",
150
- "files": [output_path] # 👈 파일 경로 추가
151
- }
152
-
153
- elif args.evaluate_file:
154
- print("--- Running in Rolling Evaluation Mode ---", file=sys.stderr)
155
- eval_preds, eval_trues = evaluate_performance(args, model, scaler, device)
156
-
157
- # ⭐️ 결과 파일들을 저장고, 경로들을 final_output에 추가
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 나의 모드를 선택해야 합니다.")