<jupyter_start><jupyter_text>PoseNet<jupyter_code>import torch
import cv2
import time
#import argparse

import posenet

#parser = argparse.ArgumentParser()
#parser.add_argument('--model', type=int, default=101)
#parser.add_argument('--cam_id', type=int, default=0)
#parser.add_argument('--cam_width', type=int, default=1280)
#parser.add_argument('--cam_height', type=int, default=720)
#parser.add_argument('--scale_factor', type=float, default=0.7125)
#args = parser.parse_args()


model = posenet.load_model(int(101))#args.model
model = model.cuda()
output_stride = model.output_stride

cap = cv2.VideoCapture(0)#args.cam_id = 0
cap.set(3, 1280)#args.cam_width=1280
cap.set(4, 720)#args.cam_height=720

start = time.time()
frame_count = 0
while True:
    input_image, display_image, output_scale = posenet.read_cap(
        cap, scale_factor= 0.7125, output_stride=output_stride)#args.scale_factor=0.7125

    with torch.no_grad():
        input_image = torch.Tensor(input_image).cuda()

        heatmaps_result, offsets_result, displacement_fwd_result, displacement_bwd_result = model(input_image)

        pose_scores, keypoint_scores, keypoint_coords = posenet.decode_multiple_poses(
            heatmaps_result.squeeze(0),
            offsets_result.squeeze(0),
            displacement_fwd_result.squeeze(0),
            displacement_bwd_result.squeeze(0),
            output_stride=output_stride,
            max_pose_detections=10,
            min_pose_score=0.15)

    keypoint_coords *= output_scale

    # TODO this isn't particularly fast, use GL for drawing and display someday...
    overlay_image = posenet.draw_skel_and_kp(
        display_image, pose_scores, keypoint_scores, keypoint_coords,
        min_pose_score=0.15, min_part_score=0.1)

    cv2.imshow('posenet', overlay_image)
    frame_count += 1
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
    print('Average FPS: ', frame_count / (time.time() - start))<jupyter_output><empty_output><jupyter_text>Convert to TensorRT<jupyter_code>import torch
from torch2trt import torch2trt

model = LSTM(n_joints,n_hidden,n_categories,n_layer)
model.load_state_dict(torch.load('lstm_6_bn.pkl'))
rnn.cuda().eval()
x = torch.ones((1,32,36)).half().cuda()
rnn(x)
import pdb
pdb.pm()
class LSTM(nn.Module):
    
    def __init__(self):
        super(LSTM,self).__init__()
        self.fc = torch.nn.Linear(12,1)
        
    def forward(self,inputs):
        out = self.fc(inputs)
        return out
a = LSTM()
a.cuda().eval()
x = torch.ones((1,12)).cuda()
model_trt = torch2trt(a, [x])
wget https://github.com/xieyulai/LSTM-for-Human-Activity-Recognition-using-2D-Pose_Pytorch/blob/master/lstm.ipynb<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13115968877361986, 'fraction_numerical': 0.031493145609485, 'mean_word_length': 4.2734375, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '4271', 'license': 'MIT', 'n_tokens_mistral': 1051, 'n_tokens_neox': 986, 'n_words': 152, 'path': 'lstm_run_posenet.ipynb', 'repo_name': 'haithienld/har', 'size': '2699'}