initialize inside function :(
Browse files- main_noweb.py +13 -14
main_noweb.py
CHANGED
@@ -33,7 +33,6 @@ os.system("nvidia-smi")
|
|
33 |
print("[INFO]: Imported modules!")
|
34 |
human = MMPoseInferencer("simcc_mobilenetv2_wo-deconv-8xb64-210e_coco-256x192") # simcc_mobilenetv2_wo-deconv-8xb64-210e_coco-256x192 dekr_hrnet-w32_8xb10-140e_coco-512x512
|
35 |
hand = MMPoseInferencer("hand")
|
36 |
-
human3d = MMPoseInferencer(pose3d="human3d")
|
37 |
|
38 |
#"https://github.com/open-mmlab/mmpose/blob/main/configs/body_3d_keypoint/pose_lift/h36m/pose-lift_simplebaseline3d_8xb64-200e_h36m.py",
|
39 |
#"https://download.openmmlab.com/mmpose/body3d/simple_baseline/simple3Dbaseline_h36m-f0ad73a4_20210419.pth") # pose3d="human3d"
|
@@ -47,7 +46,7 @@ def check_fps(video):
|
|
47 |
return nframes, fps
|
48 |
|
49 |
|
50 |
-
def get_frames(video, fps=
|
51 |
# extract the file name and extension
|
52 |
split_tup = os.path.splitext(video)
|
53 |
|
@@ -61,14 +60,14 @@ def get_frames(video, fps=15, height=512, width=512):
|
|
61 |
clip = moviepy.VideoFileClip(video)
|
62 |
|
63 |
#check fps
|
64 |
-
if clip.fps >
|
65 |
print("vide rate is over 15, resetting to 15")
|
66 |
#clip_resized = moviepy.clip.resize(height=height)
|
67 |
clip.write_videofile(video, fps=fps)
|
68 |
else:
|
69 |
print("video rate is OK")
|
70 |
#clip_resized = clip.resize(height=height)
|
71 |
-
|
72 |
|
73 |
print("video resized to 512 height")
|
74 |
|
@@ -93,7 +92,8 @@ def check_extension(video):
|
|
93 |
def pose3d(video, kpt_threshold):
|
94 |
video = check_extension(video)
|
95 |
print(device)
|
96 |
-
|
|
|
97 |
|
98 |
# Define new unique folder
|
99 |
add_dir = str(uuid.uuid4())
|
@@ -101,9 +101,8 @@ def pose3d(video, kpt_threshold):
|
|
101 |
|
102 |
os.makedirs(add_dir)
|
103 |
print(check_fps(video))
|
104 |
-
result_generator =
|
105 |
vis_out_dir = add_dir,
|
106 |
-
#return_vis=True,
|
107 |
radius = 5,
|
108 |
thickness=4,
|
109 |
rebase_keypoint_height=True,
|
@@ -117,7 +116,7 @@ def pose3d(video, kpt_threshold):
|
|
117 |
out_file = glob.glob(os.path.join(add_dir, "*.mp4")) #+ glob.glob(os.path.join(vis_out_dir, "*.webm"))
|
118 |
kpoints = glob.glob(os.path.join(add_dir, "*.json"))
|
119 |
print(kpoints)
|
120 |
-
|
121 |
# Reinitialize
|
122 |
return "".join(out_file)
|
123 |
|
@@ -185,19 +184,19 @@ def UI():
|
|
185 |
with gr.Column():
|
186 |
with gr.Row():
|
187 |
with gr.Column():
|
188 |
-
|
189 |
-
|
190 |
-
|
|
|
191 |
with gr.Row():
|
192 |
submit_pose_file = gr.Button("Make 2d pose estimation")
|
193 |
submit_pose3d_file = gr.Button("Make 3d pose estimation")
|
194 |
submit_hand_file = gr.Button("Make 2d hand estimation")
|
195 |
-
submit_detect_file = gr.Button("Detect and track objects")
|
196 |
|
197 |
with gr.Row():
|
198 |
-
video_output1 = gr.
|
199 |
video_output2 = gr.Video(height=512, label = "Estimate human 3d poses", show_label=True)
|
200 |
-
video_output3 = gr.
|
201 |
|
202 |
gr.Markdown("Download the .json file that contains the keypoint positions for each frame in the video.")
|
203 |
jsonoutput = gr.File(file_types=[".json"])
|
|
|
33 |
print("[INFO]: Imported modules!")
|
34 |
human = MMPoseInferencer("simcc_mobilenetv2_wo-deconv-8xb64-210e_coco-256x192") # simcc_mobilenetv2_wo-deconv-8xb64-210e_coco-256x192 dekr_hrnet-w32_8xb10-140e_coco-512x512
|
35 |
hand = MMPoseInferencer("hand")
|
|
|
36 |
|
37 |
#"https://github.com/open-mmlab/mmpose/blob/main/configs/body_3d_keypoint/pose_lift/h36m/pose-lift_simplebaseline3d_8xb64-200e_h36m.py",
|
38 |
#"https://download.openmmlab.com/mmpose/body3d/simple_baseline/simple3Dbaseline_h36m-f0ad73a4_20210419.pth") # pose3d="human3d"
|
|
|
46 |
return nframes, fps
|
47 |
|
48 |
|
49 |
+
def get_frames(video, fps=30, height=512, width=512):
|
50 |
# extract the file name and extension
|
51 |
split_tup = os.path.splitext(video)
|
52 |
|
|
|
60 |
clip = moviepy.VideoFileClip(video)
|
61 |
|
62 |
#check fps
|
63 |
+
if clip.fps > fps:
|
64 |
print("vide rate is over 15, resetting to 15")
|
65 |
#clip_resized = moviepy.clip.resize(height=height)
|
66 |
clip.write_videofile(video, fps=fps)
|
67 |
else:
|
68 |
print("video rate is OK")
|
69 |
#clip_resized = clip.resize(height=height)
|
70 |
+
clip.write_videofile(video, fps=clip.fps)
|
71 |
|
72 |
print("video resized to 512 height")
|
73 |
|
|
|
92 |
def pose3d(video, kpt_threshold):
|
93 |
video = check_extension(video)
|
94 |
print(device)
|
95 |
+
|
96 |
+
human3d = MMPoseInferencer(pose3d="human3d")
|
97 |
|
98 |
# Define new unique folder
|
99 |
add_dir = str(uuid.uuid4())
|
|
|
101 |
|
102 |
os.makedirs(add_dir)
|
103 |
print(check_fps(video))
|
104 |
+
result_generator = human3d(video,
|
105 |
vis_out_dir = add_dir,
|
|
|
106 |
radius = 5,
|
107 |
thickness=4,
|
108 |
rebase_keypoint_height=True,
|
|
|
116 |
out_file = glob.glob(os.path.join(add_dir, "*.mp4")) #+ glob.glob(os.path.join(vis_out_dir, "*.webm"))
|
117 |
kpoints = glob.glob(os.path.join(add_dir, "*.json"))
|
118 |
print(kpoints)
|
119 |
+
|
120 |
# Reinitialize
|
121 |
return "".join(out_file)
|
122 |
|
|
|
184 |
with gr.Column():
|
185 |
with gr.Row():
|
186 |
with gr.Column():
|
187 |
+
with gr.Row():
|
188 |
+
video_input = gr.Video(source="upload", type="filepath", height=512, width=512)
|
189 |
+
# Insert slider with kpt_thr
|
190 |
+
file_kpthr = gr.Slider(0, 1, value=0.3, label='Keypoint threshold')
|
191 |
with gr.Row():
|
192 |
submit_pose_file = gr.Button("Make 2d pose estimation")
|
193 |
submit_pose3d_file = gr.Button("Make 3d pose estimation")
|
194 |
submit_hand_file = gr.Button("Make 2d hand estimation")
|
|
|
195 |
|
196 |
with gr.Row():
|
197 |
+
video_output1 = gr.Video(height=512, label = "Estimate human 2d poses", show_label=True)
|
198 |
video_output2 = gr.Video(height=512, label = "Estimate human 3d poses", show_label=True)
|
199 |
+
video_output3 = gr.Video(height=512, label = "Estimate human hand poses", show_label=True)
|
200 |
|
201 |
gr.Markdown("Download the .json file that contains the keypoint positions for each frame in the video.")
|
202 |
jsonoutput = gr.File(file_types=[".json"])
|