File size: 3,702 Bytes
34a9259
afd2199
 
34a9259
22e7a27
 
 
34a9259
afd2199
34a9259
 
 
 
 
 
 
cd41c0c
a21de06
afd2199
e2522a6
0e929df
 
 
34a9259
0e929df
34a9259
0e929df
e2522a6
3e81a23
08528b3
8db8164
 
22e7a27
 
 
 
 
 
 
 
3e81a23
22e7a27
c76c2fc
3e81a23
 
0e929df
 
0776955
 
 
cafc721
0776955
 
 
0e929df
0776955
 
 
 
 
 
 
fcbfb53
0776955
 
 
 
92499cd
0776955
92499cd
31fdeeb
c76c2fc
22e7a27
 
b28330f
92499cd
0e5fb59
cafc721
613f3b6
0e5fb59
 
 
 
92499cd
 
 
cafc721
3e81a23
92499cd
 
0e929df
92499cd
 
 
 
 
31fdeeb
 
 
 
6b7f67c
22e7a27
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Pose inferencing
import mmpose
from mmpose.apis import MMPoseInferencer

# Ultralytics
#from ultralytics import YOLO

# Gradio
import gradio as gr

# System and files
import os
import glob
import uuid

# Image manipulation
import numpy as np
import cv2

print("[INFO]: Imported modules!")
human = MMPoseInferencer("human")
hand = MMPoseInferencer("hand")
human3d = MMPoseInferencer(pose3d="human3d")
# ultraltics

# Defining inferencer models to lookup in function
inferencers = {"Estimate human 2d poses":human, "Estimate human 2d hand poses":hand, "Estimate human 3d poses":human3d}

#track_model = YOLO('yolov8n.pt')  # Load an official Detect model

print("[INFO]: Downloaded models!")

def tracking(video, model, boxes=True):
    print("[INFO] Loading model...")
    # Load an official or custom model

    # Perform tracking with the model
    print("[INFO] Starting tracking!")
    # https://docs.ultralytics.com/modes/predict/
    annotated_frame = model(video, device="cuda", boxes=boxes)

    return annotated_frame



def poses(photo, check):
    # Selecting the specific inferencer
    out_files=[]
    for i in len(check):
        inferencer = inferencers[check] # 'hand', 'human , device='cuda'

        print("[INFO]: Running inference!")
        # Create out directory
        vis_out_dir = str(uuid.uuid4())

        result_generator = inferencer(photo, 
                                    vis_out_dir = vis_out_dir,
                                    return_vis=True,
                                    thickness=2,
                                    rebase_keypoint_height=True)    
        
        result = [result for result in result_generator] #next(result_generator)    

        out_file = glob.glob(os.path.join(vis_out_dir, "*.mp4"))
        # 00000.mp4
        # 000000.mp4
        out_files.append(out_file)

    return out_files

def run():
    #https://github.com/open-mmlab/mmpose/blob/main/docs/en/user_guides/inference.md
    check_web =  gr.CheckboxGroup(choices = ["Estimate human 2d poses", "Estimate human 2d hand poses", "Estimate human 3d poses"], label="Methods", type="value", info="Select the model(s) you want")
    check_file = gr.CheckboxGroup(choices = ["Estimate human 2d poses", "Estimate human 2d hand poses", "Estimate human 3d poses"], label="Methods", type="value", info="Select the model(s) you want")

    webcam = gr.Interface(
        fn=poses,
        inputs= [gr.Video(source="webcam", height=412), check_web],
        outputs = [gr.PlayableVideo(), gr.PlayableVideo(), gr.PlayableVideo()],
        title = 'Pose estimation', 
        description = 'Pose estimation on video',
        allow_flagging=False
        )

    file = gr.Interface(
        poses,
        inputs = [gr.Video(source="upload", height=412), check_file],
        outputs = [gr.PlayableVideo(),gr.PlayableVideo(),gr.PlayableVideo()],
        allow_flagging=False
    )

    demo = gr.TabbedInterface(
            interface_list=[file, webcam],
            tab_names=["From a File", "From your Webcam"]
        )

    demo.launch(server_name="0.0.0.0", server_port=7860)


if __name__ == "__main__":
    run()

# https://github.com/open-mmlab/mmpose/tree/dev-1.x/configs/body_3d_keypoint/pose_lift
# motionbert_ft_h36m-d80af323_20230531.pth
# simple3Dbaseline_h36m-f0ad73a4_20210419.pth
# videopose_h36m_243frames_fullconv_supervised_cpn_ft-88f5abbb_20210527.pth
# videopose_h36m_81frames_fullconv_supervised-1f2d1104_20210527.pth
# videopose_h36m_27frames_fullconv_supervised-fe8fbba9_20210527.pth
# videopose_h36m_1frame_fullconv_supervised_cpn_ft-5c3afaed_20210527.pth
# https://github.com/open-mmlab/mmpose/blob/main/mmpose/apis/inferencers/pose3d_inferencer.py