Skip to content

Commit 1bea72d

Browse files
authored
Merge pull request #37 from dronefreak/hac-video-ucf
Hac video classificaiton ucf101
2 parents 2e3d2ae + e1dd340 commit 1bea72d

33 files changed

+2286
-23
lines changed

.github/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![🔥 PyTorch 2.0+](https://img.shields.io/badge/PyTorch-2.0+-EE4C2C?logo=pytorch&logoColor=white&style=for-the-badge)](https://pytorch.org/)
55
[![🤗 HuggingFace Models](https://img.shields.io/badge/HuggingFace-Models-FFD21E?logo=huggingface&logoColor=yellow&style=for-the-badge)](https://huggingface.co/dronefreak/human-action-classification-stanford40)
66
[![⚖️ License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-green?logo=open-source-initiative&logoColor=white&style=for-the-badge)](https://opensource.org/licenses/Apache-2.0)
7+
[![⭐ GitHub stars](https://img.shields.io/github/stars/dronefreak/human-action-classification?style=for-the-badge)](https://github.com/dronefreak/human-action-classification/stargazers)
78

89
**The fastest way to classify human actions in images and video.** MediaPipe pose estimation + PyTorch CNNs with **90 FPS real-time performance**. Zero C++ compilation, pure Python.
910

src/hac/__init__.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
"""Human Action Classification v2.0.
2-
3-
Modern action recognition using MediaPipe pose estimation and PyTorch. Completely
4-
rewritten from the TensorFlow 1.13 version.
5-
"""
1+
"""Human Action Classification - Image and Video."""
62

73
__version__ = "2.0.0"
8-
__author__ = "Saumya Kumaar Saksena"
94

10-
from hac.inference.predictor import ActionPredictor
11-
from hac.models.classifier import ActionClassifier
5+
# Common utilities
6+
from .common.metrics import compute_accuracy, compute_metrics
7+
8+
# Image module (backward compatibility)
9+
from .image.inference.predictor import ActionPredictor as ImagePredictor
10+
from .image.models.classifier import ActionClassifier
11+
12+
# Video module
13+
from .video.models.classifier import Video3DCNN
1214

13-
__all__ = ["ActionPredictor", "ActionClassifier"]
15+
__all__ = [
16+
"ImagePredictor",
17+
"ActionClassifier",
18+
"Video3DCNN",
19+
"compute_accuracy",
20+
"compute_metrics",
21+
]

src/hac/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import argparse
44
import sys
55

6-
from hac.inference.predictor import ActionPredictor
6+
from hac.image.inference.predictor import ActionPredictor
77

88

99
def infer():

src/hac/common/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""Common utilities shared between image and video modules."""
2+
3+
from .convert_to_safetensors import convert_checkpoint
4+
from .transforms import (
5+
denormalize_image,
6+
get_inference_transforms,
7+
get_training_transforms,
8+
)
9+
10+
__all__ = [
11+
"convert_checkpoint",
12+
"get_inference_transforms",
13+
"get_training_transforms",
14+
"denormalize_image",
15+
]
File renamed without changes.

src/hac/common/metrics.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""Shared metrics for both image and video classification."""
2+
3+
from sklearn.metrics import (
4+
accuracy_score,
5+
confusion_matrix,
6+
precision_recall_fscore_support,
7+
)
8+
9+
10+
def compute_accuracy(predictions, targets):
11+
"""Compute accuracy.
12+
13+
Args:
14+
predictions: Array of predicted class indices
15+
targets: Array of ground truth class indices
16+
17+
Returns:
18+
Accuracy as float
19+
"""
20+
return accuracy_score(targets, predictions)
21+
22+
23+
def compute_metrics(predictions, targets, average="macro"):
24+
"""Compute comprehensive classification metrics.
25+
26+
Args:
27+
predictions: Array of predicted class indices
28+
targets: Array of ground truth class indices
29+
average: Averaging strategy ('macro', 'weighted', 'micro')
30+
31+
Returns:
32+
Dictionary with accuracy, precision, recall, f1
33+
"""
34+
acc = accuracy_score(targets, predictions)
35+
precision, recall, f1, _ = precision_recall_fscore_support(
36+
targets, predictions, average=average, zero_division=0
37+
)
38+
39+
return {"accuracy": acc, "precision": precision, "recall": recall, "f1": f1}
40+
41+
42+
def compute_confusion_matrix(predictions, targets):
43+
"""Compute confusion matrix.
44+
45+
Args:
46+
predictions: Array of predicted class indices
47+
targets: Array of ground truth class indices
48+
49+
Returns:
50+
Confusion matrix as numpy array
51+
"""
52+
return confusion_matrix(targets, predictions)
File renamed without changes.

src/hac/image/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Image action recognition module."""
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)