Spaces:
Runtime error
Runtime error
Update 1.py
Browse files
1.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
#%cd /workspace/
|
2 |
import os
|
3 |
from typing import Tuple, Optional
|
4 |
import shutil
|
@@ -13,8 +13,8 @@ from tqdm import tqdm
|
|
13 |
import sys
|
14 |
import json
|
15 |
import pickle
|
16 |
-
os.chdir("/workspace/florence-sam
|
17 |
-
sys.path.append('/workspace/florence-sam
|
18 |
from utils.video import generate_unique_name, create_directory, delete_directory
|
19 |
from utils.florence import load_florence_model, run_florence_inference, \
|
20 |
FLORENCE_DETAILED_CAPTION_TASK, \
|
@@ -34,46 +34,33 @@ if torch.cuda.get_device_properties(0).major >= 8:
|
|
34 |
FLORENCE_MODEL, FLORENCE_PROCESSOR = load_florence_model(device=DEVICE)
|
35 |
SAM_IMAGE_MODEL = load_sam_image_model(device=DEVICE)
|
36 |
|
37 |
-
with open('/workspace/
|
38 |
texts = pickle.load(file)
|
39 |
print(texts)
|
40 |
|
41 |
-
with open('/workspace/
|
42 |
output_video = pickle.load(file)
|
43 |
print(output_video)
|
44 |
|
45 |
VIDEO_SCALE_FACTOR = 1
|
46 |
-
VIDEO_TARGET_DIRECTORY = "/workspace/
|
47 |
create_directory(directory_path=VIDEO_TARGET_DIRECTORY)
|
48 |
|
49 |
|
50 |
video_input= output_video
|
51 |
-
texts = ['
|
52 |
-
#
|
|
|
53 |
if not video_input:
|
54 |
print("Please upload a video.")
|
55 |
-
|
56 |
frame_generator = sv.get_video_frames_generator(video_input)
|
57 |
frame = next(frame_generator)
|
58 |
frame = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
59 |
-
'''
|
60 |
-
|
61 |
|
62 |
-
frame_generator = sv.get_video_frames_generator(video_input)
|
63 |
|
64 |
-
# 获取视频的总帧数
|
65 |
-
total_frames = int(sv.get_total_frames(video_input))
|
66 |
|
67 |
-
# 计算中间帧的位置
|
68 |
-
middle_frame_index = total_frames // 2
|
69 |
-
with open('/workspace/tem//middle_frame_index.pkl', 'wb') as file:
|
70 |
-
pickle.dump(middle_frame_index, file)
|
71 |
-
# 读取到中间帧
|
72 |
-
for _ in range(middle_frame_index):
|
73 |
-
frame = next(frame_generator)
|
74 |
|
75 |
-
# 将帧从 BGR 转换为 RGB 并保存到 PIL 图像对象
|
76 |
-
frame = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
77 |
|
78 |
detections_list = []
|
79 |
width, height = frame.size
|
@@ -130,7 +117,7 @@ for text in texts:
|
|
130 |
ok_result.append(new_result)
|
131 |
|
132 |
print(ok_result)
|
133 |
-
with open('/workspace/
|
134 |
pickle.dump(all_ok_bboxes, file)
|
135 |
|
136 |
for xyxy in ok_result:
|
@@ -143,6 +130,6 @@ for xyxy in ok_result:
|
|
143 |
detections = run_sam_inference(SAM_IMAGE_MODEL, frame, detections)
|
144 |
print(detections)
|
145 |
detections_list.append(detections)
|
146 |
-
with open('/workspace/
|
147 |
pickle.dump(detections_list, file)
|
148 |
print(detections_list)
|
|
|
1 |
+
#%cd /workspace/florence-samflorence-sam
|
2 |
import os
|
3 |
from typing import Tuple, Optional
|
4 |
import shutil
|
|
|
13 |
import sys
|
14 |
import json
|
15 |
import pickle
|
16 |
+
os.chdir("/workspace/florence-sam")
|
17 |
+
sys.path.append('/workspace/florence-sam')
|
18 |
from utils.video import generate_unique_name, create_directory, delete_directory
|
19 |
from utils.florence import load_florence_model, run_florence_inference, \
|
20 |
FLORENCE_DETAILED_CAPTION_TASK, \
|
|
|
34 |
FLORENCE_MODEL, FLORENCE_PROCESSOR = load_florence_model(device=DEVICE)
|
35 |
SAM_IMAGE_MODEL = load_sam_image_model(device=DEVICE)
|
36 |
|
37 |
+
with open('/workspace/florence-sam/texts.pkl', 'rb') as file:
|
38 |
texts = pickle.load(file)
|
39 |
print(texts)
|
40 |
|
41 |
+
with open('/workspace/florence-sam/output_video.pkl', 'rb') as file:
|
42 |
output_video = pickle.load(file)
|
43 |
print(output_video)
|
44 |
|
45 |
VIDEO_SCALE_FACTOR = 1
|
46 |
+
VIDEO_TARGET_DIRECTORY = "/workspace/florence-sam"
|
47 |
create_directory(directory_path=VIDEO_TARGET_DIRECTORY)
|
48 |
|
49 |
|
50 |
video_input= output_video
|
51 |
+
texts = ['men','the table']
|
52 |
+
#texts = ['men']
|
53 |
+
#VIDEO_TARGET_DIRECTORY = "/workspace/florence-sam"
|
54 |
if not video_input:
|
55 |
print("Please upload a video.")
|
56 |
+
|
57 |
frame_generator = sv.get_video_frames_generator(video_input)
|
58 |
frame = next(frame_generator)
|
59 |
frame = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
|
|
|
|
60 |
|
|
|
61 |
|
|
|
|
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
|
|
|
|
64 |
|
65 |
detections_list = []
|
66 |
width, height = frame.size
|
|
|
117 |
ok_result.append(new_result)
|
118 |
|
119 |
print(ok_result)
|
120 |
+
with open('/workspace/florence-sam/all_ok_bboxes.pkl', 'wb') as file:
|
121 |
pickle.dump(all_ok_bboxes, file)
|
122 |
|
123 |
for xyxy in ok_result:
|
|
|
130 |
detections = run_sam_inference(SAM_IMAGE_MODEL, frame, detections)
|
131 |
print(detections)
|
132 |
detections_list.append(detections)
|
133 |
+
with open('/workspace/florence-sam/detections_list.pkl', 'wb') as file:
|
134 |
pickle.dump(detections_list, file)
|
135 |
print(detections_list)
|