| | import cv2 |
| | import torch |
| | import numpy as np |
| | import pandas as pd |
| | from .islr.islr_model import DummyISLRModel |
| | from .pose.keypoints_utils import extract_keypoints_from_frame |
| |
|
| | |
| | |
| | |
| |
|
| | LABELS = [f"Clase {i}" for i in range(100)] |
| |
|
| | def predict_from_video(video_path,model=None): |
| | cap = cv2.VideoCapture(video_path) |
| | keypoints = [] |
| |
|
| | while cap.isOpened(): |
| | ret, frame = cap.read() |
| | if not ret: |
| | break |
| | keypoint = extract_keypoints_from_frame(frame) |
| | keypoints.append(keypoint) |
| |
|
| | cap.release() |
| | if not keypoints: |
| | return "No keypoints detected", pd.DataFrame() |
| |
|
| | x = torch.tensor(np.mean(keypoints, axis=0)).float().unsqueeze(0) |
| | |
| | |
| | with torch.no_grad(): |
| | logits = model(x) |
| | probs = torch.softmax(logits, dim=1).numpy()[0] |
| |
|
| | |
| | |
| | top5_idx = probs.argsort()[-5:][::-1] |
| |
|
| | top5_labels = [LABELS[i] for i in top5_idx] |
| | top5_probs = [probs[i] for i in top5_idx] |
| | confidences = {LABELS[i]: float(probs[i]) for i in top5_idx} |
| |
|
| | |
| | |
| | |
| | return top5_labels[0],confidences |
| |
|