Subh775 commited on
Commit
e479bc2
·
verified ·
1 Parent(s): 8d4083c

size config

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  import io
3
  import base64
4
  import time
@@ -11,6 +12,9 @@ import torch
11
  from flask import Flask, request, jsonify, send_from_directory
12
  from PIL import Image
13
 
 
 
 
14
  # Libraries for Models
15
  from ultralytics import YOLO
16
  import supervision as sv
@@ -71,11 +75,17 @@ def init_models():
71
  download_file(RF_WEIGHT_URL, RF_WEIGHT_PATH)
72
  print("[INFO] Loading RF-DETR...")
73
  # Initialize with CPU params
74
- MODEL_RF = RFDETRSegPreview(pretrain_weights=RF_WEIGHT_PATH)
75
- # Attempt optimization if method exists
76
- if hasattr(MODEL_RF, 'optimize_for_inference'):
77
- MODEL_RF.optimize_for_inference()
78
- print("[INFO] RF-DETR Ready.")
 
 
 
 
 
 
79
  except Exception as e:
80
  print(f"[ERROR] RF-DETR Load Failed: {e}")
81
  traceback.print_exc()
 
1
  import os
2
+ import sys
3
  import io
4
  import base64
5
  import time
 
12
  from flask import Flask, request, jsonify, send_from_directory
13
  from PIL import Image
14
 
15
+ # Ensure local modules take precedence (fixes issues if rfdetr is both local and installed)
16
+ sys.path.insert(0, os.getcwd())
17
+
18
  # Libraries for Models
19
  from ultralytics import YOLO
20
  import supervision as sv
 
75
  download_file(RF_WEIGHT_URL, RF_WEIGHT_PATH)
76
  print("[INFO] Loading RF-DETR...")
77
  # Initialize with CPU params
78
+ # Added try-except to catch architecture mismatches (e.g. Nano vs Base)
79
+ try:
80
+ MODEL_RF = RFDETRSegPreview(pretrain_weights=RF_WEIGHT_PATH)
81
+ # Attempt optimization if method exists
82
+ if hasattr(MODEL_RF, 'optimize_for_inference'):
83
+ MODEL_RF.optimize_for_inference()
84
+ print("[INFO] RF-DETR Ready.")
85
+ except RuntimeError as re:
86
+ print(f"[ERROR] RF-DETR Architecture Mismatch: {re}")
87
+ print("[WARN] Skipping RF-DETR loading. App will run with YOLO only.")
88
+ MODEL_RF = None
89
  except Exception as e:
90
  print(f"[ERROR] RF-DETR Load Failed: {e}")
91
  traceback.print_exc()