Spaces:
Sleeping
Sleeping
Update api_server.py
Browse files- api_server.py +9 -8
api_server.py
CHANGED
@@ -34,7 +34,7 @@ if load_type == 'local':
|
|
34 |
|
35 |
model = YOLO(model_path)
|
36 |
|
37 |
-
print("=============== YOLO DONE =============")
|
38 |
#model.eval() # 設定模型為推理模式
|
39 |
elif load_type == 'remote_hub_download':
|
40 |
from huggingface_hub import hf_hub_download
|
@@ -93,6 +93,7 @@ def check_memory_usage():
|
|
93 |
|
94 |
# Run the function
|
95 |
check_memory_usage()
|
|
|
96 |
# Initialize the Flask application
|
97 |
app = Flask(__name__)
|
98 |
# Initialize the ClipModel at the start
|
@@ -119,11 +120,11 @@ def predict():
|
|
119 |
except Exception as e:
|
120 |
return jsonify({'error': str(e)}), 400
|
121 |
|
122 |
-
print("
|
123 |
# Make a prediction using YOLO
|
124 |
results = model(image_data)
|
125 |
-
print ("*****result:",results,"********")
|
126 |
-
print("
|
127 |
check_memory_usage()
|
128 |
|
129 |
# 檢查 YOLO 是否返回了有效的結果
|
@@ -154,15 +155,15 @@ def predict():
|
|
154 |
yolo_path = f"{YOLO_DIR}/{message_id}/{element}"
|
155 |
yolo_file = get_jpg_files(yolo_path)
|
156 |
|
157 |
-
print(yolo_path)
|
158 |
|
159 |
element_list.append(element)
|
160 |
|
161 |
for yolo_img in yolo_file: # 每張切圖yolo_img
|
162 |
-
print("
|
163 |
-
|
164 |
#encoded_images.append(image_to_base64(yolo_img))
|
165 |
-
|
166 |
|
167 |
# if element_counts[element] > 1: #某隻角色的數量>1
|
168 |
# yolo_path = f"{YOLO_DIR}/{message_id}/{element}"
|
|
|
34 |
|
35 |
model = YOLO(model_path)
|
36 |
|
37 |
+
print("===============LOAD YOLO MODEL DONE =============")
|
38 |
#model.eval() # 設定模型為推理模式
|
39 |
elif load_type == 'remote_hub_download':
|
40 |
from huggingface_hub import hf_hub_download
|
|
|
93 |
|
94 |
# Run the function
|
95 |
check_memory_usage()
|
96 |
+
|
97 |
# Initialize the Flask application
|
98 |
app = Flask(__name__)
|
99 |
# Initialize the ClipModel at the start
|
|
|
120 |
except Exception as e:
|
121 |
return jsonify({'error': str(e)}), 400
|
122 |
|
123 |
+
print("***** Start YOLO predict *****")
|
124 |
# Make a prediction using YOLO
|
125 |
results = model(image_data)
|
126 |
+
print ("***** YOLO predict result:",results,"********")
|
127 |
+
print("***** YOLO predict DONE *****")
|
128 |
check_memory_usage()
|
129 |
|
130 |
# 檢查 YOLO 是否返回了有效的結果
|
|
|
155 |
yolo_path = f"{YOLO_DIR}/{message_id}/{element}"
|
156 |
yolo_file = get_jpg_files(yolo_path)
|
157 |
|
158 |
+
print(f"======YOLO result:{yolo_path}======")
|
159 |
|
160 |
element_list.append(element)
|
161 |
|
162 |
for yolo_img in yolo_file: # 每張切圖yolo_img
|
163 |
+
print("*****START CLIP *****")
|
164 |
+
top_k_words.append(clip_model.clip_result(yolo_img)) # CLIP預測3個結果(top_k_words)
|
165 |
#encoded_images.append(image_to_base64(yolo_img))
|
166 |
+
print(f"**{yolo_img}:{top_k_words}**\n")
|
167 |
|
168 |
# if element_counts[element] > 1: #某隻角色的數量>1
|
169 |
# yolo_path = f"{YOLO_DIR}/{message_id}/{element}"
|