tcasl 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tcasl-1.0.0/LICENSE.txt +21 -0
- tcasl-1.0.0/PKG-INFO +42 -0
- tcasl-1.0.0/README.md +25 -0
- tcasl-1.0.0/pyproject.toml +29 -0
- tcasl-1.0.0/setup.cfg +4 -0
- tcasl-1.0.0/src/tcasl/__init__.py +3 -0
- tcasl-1.0.0/src/tcasl/core.py +128 -0
- tcasl-1.0.0/src/tcasl.egg-info/PKG-INFO +42 -0
- tcasl-1.0.0/src/tcasl.egg-info/SOURCES.txt +10 -0
- tcasl-1.0.0/src/tcasl.egg-info/dependency_links.txt +1 -0
- tcasl-1.0.0/src/tcasl.egg-info/requires.txt +5 -0
- tcasl-1.0.0/src/tcasl.egg-info/top_level.txt +1 -0
tcasl-1.0.0/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Keshav Shankar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
tcasl-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tcasl
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python library for temporal contrast American Sign Language classification.
|
|
5
|
+
Author-email: Keshav Shankar <keshavshankar08@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/keshavshankar08/TCASLCore
|
|
7
|
+
Project-URL: Issues, https://github.com/keshavshankar08/TCASLCore/issues
|
|
8
|
+
Requires-Python: >=3.7
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE.txt
|
|
11
|
+
Requires-Dist: opencv-python
|
|
12
|
+
Requires-Dist: numpy
|
|
13
|
+
Requires-Dist: torch
|
|
14
|
+
Requires-Dist: torchvision
|
|
15
|
+
Requires-Dist: pillow
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# TCASL
|
|
19
|
+
|
|
20
|
+
TCASL is a lightweight, pure Python inference engine for predicting American Sign Language (ASL) gestures using Temporal Contrast, simulating a Dynamic Vision Sensor (DVS).
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
* **Zero-Bloat Inference:** A strictly defined PyTorch wrapper built specifically for rapid prediction.
|
|
25
|
+
* **Temporal Contrast Processing:** Built-in methods to convert standard webcam video into DVS-style event frames.
|
|
26
|
+
* **Auto-Formatting:** Automatically center-crops and down-scales raw video arrays to the 128x128 resolution required by the network.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
You can install the latest release of TCASL from PyPI using `pip`:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install TCASL
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage in Python
|
|
37
|
+
|
|
38
|
+
Examples of how the library can be used can be found in [examples/](examples/). You should not edit this code unless you read the documentation thoroughly, which is located at [src/tcasl/core.py](src/tcasl/core.py).
|
|
39
|
+
|
|
40
|
+
## TCASL Project
|
|
41
|
+
|
|
42
|
+
You can find information about TCASL on the [GitHub page](https://github.com/keshavshankar08/TCASLCore).
|
tcasl-1.0.0/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# TCASL
|
|
2
|
+
|
|
3
|
+
TCASL is a lightweight, pure Python inference engine for predicting American Sign Language (ASL) gestures using Temporal Contrast, simulating a Dynamic Vision Sensor (DVS).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
* **Zero-Bloat Inference:** A strictly defined PyTorch wrapper built specifically for rapid prediction.
|
|
8
|
+
* **Temporal Contrast Processing:** Built-in methods to convert standard webcam video into DVS-style event frames.
|
|
9
|
+
* **Auto-Formatting:** Automatically center-crops and down-scales raw video arrays to the 128x128 resolution required by the network.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
You can install the latest release of TCASL from PyPI using `pip`:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install TCASL
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage in Python
|
|
20
|
+
|
|
21
|
+
Examples of how the library can be used can be found in [examples/](examples/). You should not edit this code unless you read the documentation thoroughly, which is located at [src/tcasl/core.py](src/tcasl/core.py).
|
|
22
|
+
|
|
23
|
+
## TCASL Project
|
|
24
|
+
|
|
25
|
+
You can find information about TCASL on the [GitHub page](https://github.com/keshavshankar08/TCASLCore).
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tcasl"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Python library for temporal contrast American Sign Language classification."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Keshav Shankar", email = "keshavshankar08@gmail.com" }
|
|
13
|
+
]
|
|
14
|
+
dependencies = [
|
|
15
|
+
"opencv-python",
|
|
16
|
+
"numpy",
|
|
17
|
+
"torch",
|
|
18
|
+
"torchvision",
|
|
19
|
+
"pillow"
|
|
20
|
+
]
|
|
21
|
+
requires-python = ">=3.7"
|
|
22
|
+
|
|
23
|
+
[tool.setuptools]
|
|
24
|
+
package-dir = {"" = "src"}
|
|
25
|
+
packages = ["tcasl"]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/keshavshankar08/TCASLCore"
|
|
29
|
+
Issues = "https://github.com/keshavshankar08/TCASLCore/issues"
|
tcasl-1.0.0/setup.cfg
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import cv2 as cv
|
|
2
|
+
import numpy as np
|
|
3
|
+
import torch
|
|
4
|
+
import os
|
|
5
|
+
import torch.nn as nn
|
|
6
|
+
from torchvision import transforms
|
|
7
|
+
from PIL import Image
|
|
8
|
+
|
|
9
|
+
class BaseCNN(nn.Module):
|
|
10
|
+
def __init__(self, num_classes: int):
|
|
11
|
+
super(BaseCNN, self).__init__()
|
|
12
|
+
self.conv_layers = nn.Sequential(
|
|
13
|
+
nn.Conv2d(1, 16, kernel_size=3, padding=1), nn.ReLU(), nn.MaxPool2d(2, 2),
|
|
14
|
+
nn.Conv2d(16, 32, kernel_size=3, padding=1), nn.ReLU(), nn.MaxPool2d(2, 2),
|
|
15
|
+
nn.Conv2d(32, 64, kernel_size=3, padding=1), nn.ReLU(), nn.MaxPool2d(2, 2)
|
|
16
|
+
)
|
|
17
|
+
self.fc_layers = nn.Sequential(
|
|
18
|
+
nn.Flatten(),
|
|
19
|
+
nn.Linear(64 * 16 * 16, 128), nn.ReLU(), nn.Dropout(0.5),
|
|
20
|
+
nn.Linear(128, num_classes)
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
|
24
|
+
x = self.conv_layers(x)
|
|
25
|
+
x = self.fc_layers(x)
|
|
26
|
+
return x
|
|
27
|
+
|
|
28
|
+
MODEL_REGISTRY = {
|
|
29
|
+
"cnn_v1": {
|
|
30
|
+
"class": BaseCNN,
|
|
31
|
+
"url": "https://github.com/keshavshankar08/TCASLCore/releases/download/v1.0.0/cnn_v1.pth"
|
|
32
|
+
},
|
|
33
|
+
# "snn_v1": {
|
|
34
|
+
# "class": BaseSNN,
|
|
35
|
+
# "url": "https://github.com/keshavshankar08/TCASLCore/releases/download/v_._._/snn_v1.pth"
|
|
36
|
+
# }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
class TCASL:
|
|
40
|
+
def __init__(self, arch: str = "cnn_v1", model_path: str = None):
|
|
41
|
+
"""
|
|
42
|
+
Initializes the TCASL classifier.
|
|
43
|
+
|
|
44
|
+
:param arch: The architecture tag to use.
|
|
45
|
+
:param model_path: Optional local path to the weights. If None, it auto-downloads.
|
|
46
|
+
"""
|
|
47
|
+
self.classes = [chr(i) for i in range(ord('a'), ord('z') + 1)] + ['none']
|
|
48
|
+
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
49
|
+
|
|
50
|
+
if arch not in MODEL_REGISTRY:
|
|
51
|
+
raise ValueError(f"Architecture '{arch}' not found. Available: {list(MODEL_REGISTRY.keys())}")
|
|
52
|
+
|
|
53
|
+
arch_info = MODEL_REGISTRY[arch]
|
|
54
|
+
ModelClass = arch_info["class"]
|
|
55
|
+
download_url = arch_info["url"]
|
|
56
|
+
|
|
57
|
+
self.model = ModelClass(num_classes=len(self.classes)).to(self.device)
|
|
58
|
+
|
|
59
|
+
self.transform = transforms.Compose([
|
|
60
|
+
transforms.Grayscale(num_output_channels=1),
|
|
61
|
+
transforms.Resize((128, 128)),
|
|
62
|
+
transforms.ToTensor()
|
|
63
|
+
])
|
|
64
|
+
|
|
65
|
+
self._load_model(model_path, download_url)
|
|
66
|
+
|
|
67
|
+
def _load_model(self, path: str, download_url: str) -> None:
|
|
68
|
+
if path and os.path.exists(path):
|
|
69
|
+
state_dict = torch.load(path, map_location=self.device, weights_only=True)
|
|
70
|
+
else:
|
|
71
|
+
state_dict = torch.hub.load_state_dict_from_url(
|
|
72
|
+
download_url,
|
|
73
|
+
map_location=self.device,
|
|
74
|
+
weights_only=True,
|
|
75
|
+
check_hash=False
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
self.model.load_state_dict(state_dict)
|
|
79
|
+
self.model.eval()
|
|
80
|
+
|
|
81
|
+
def preprocess_frame(self, frame: np.ndarray) -> np.ndarray:
|
|
82
|
+
"""
|
|
83
|
+
Center-crops a standard video frame to a square and resizes it to the required 128x128 resolution.
|
|
84
|
+
|
|
85
|
+
:param frame: A raw grayscale image array of any shape.
|
|
86
|
+
|
|
87
|
+
:return: A 128x128 cropped and resized grayscale image array.
|
|
88
|
+
"""
|
|
89
|
+
h, w = frame.shape
|
|
90
|
+
min_dim = min(h, w)
|
|
91
|
+
start_x = (w // 2) - (min_dim // 2)
|
|
92
|
+
start_y = (h // 2) - (min_dim // 2)
|
|
93
|
+
square_img = frame[start_y:start_y+min_dim, start_x:start_x+min_dim]
|
|
94
|
+
return cv.resize(square_img, (128, 128))
|
|
95
|
+
|
|
96
|
+
def compute_temporal_contrast(self, previous_frame: np.ndarray, current_frame: np.ndarray, threshold: int = 20) -> np.ndarray:
|
|
97
|
+
"""
|
|
98
|
+
Computes the temporal contrast between two consecutive frames to emulate a Dynamic Vision Sensor (DVS).
|
|
99
|
+
|
|
100
|
+
:param previous_frame: The previous grayscale frame.
|
|
101
|
+
:param current_frame: The current grayscale frame (must match previous_frame shape).
|
|
102
|
+
:param threshold: The pixel intensity difference required to trigger an event. Defaults to 20.
|
|
103
|
+
|
|
104
|
+
:return: A temporal contrast frame where 127 is neutral, 255 is positive polarity, and 0 is negative polarity.
|
|
105
|
+
"""
|
|
106
|
+
temp_contrast_frame = np.full(previous_frame.shape, 127, dtype=np.uint8)
|
|
107
|
+
diff_frame = current_frame.astype(np.float32) - previous_frame.astype(np.float32)
|
|
108
|
+
temp_contrast_frame[diff_frame > threshold] = 255
|
|
109
|
+
temp_contrast_frame[diff_frame < -threshold] = 0
|
|
110
|
+
return temp_contrast_frame
|
|
111
|
+
|
|
112
|
+
def predict(self, tc_frame: np.ndarray) -> str:
|
|
113
|
+
"""
|
|
114
|
+
Runs neural network inference on a temporal contrast frame to predict the ASL character.
|
|
115
|
+
|
|
116
|
+
:param tc_frame: The temporal contrast frame generated by compute_temporal_contrast.
|
|
117
|
+
|
|
118
|
+
:return: The predicted class label (a single lowercase letter 'a'-'z', or 'none').
|
|
119
|
+
"""
|
|
120
|
+
tc_image = Image.fromarray(tc_frame)
|
|
121
|
+
input_tensor = self.transform(tc_image).unsqueeze(0).to(self.device)
|
|
122
|
+
|
|
123
|
+
with torch.no_grad():
|
|
124
|
+
outputs = self.model(input_tensor)
|
|
125
|
+
_, predicted = torch.max(outputs.data, 1)
|
|
126
|
+
pred_class = self.classes[predicted.item()]
|
|
127
|
+
|
|
128
|
+
return pred_class
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tcasl
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Python library for temporal contrast American Sign Language classification.
|
|
5
|
+
Author-email: Keshav Shankar <keshavshankar08@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/keshavshankar08/TCASLCore
|
|
7
|
+
Project-URL: Issues, https://github.com/keshavshankar08/TCASLCore/issues
|
|
8
|
+
Requires-Python: >=3.7
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE.txt
|
|
11
|
+
Requires-Dist: opencv-python
|
|
12
|
+
Requires-Dist: numpy
|
|
13
|
+
Requires-Dist: torch
|
|
14
|
+
Requires-Dist: torchvision
|
|
15
|
+
Requires-Dist: pillow
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# TCASL
|
|
19
|
+
|
|
20
|
+
TCASL is a lightweight, pure Python inference engine for predicting American Sign Language (ASL) gestures using Temporal Contrast, simulating a Dynamic Vision Sensor (DVS).
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
* **Zero-Bloat Inference:** A strictly defined PyTorch wrapper built specifically for rapid prediction.
|
|
25
|
+
* **Temporal Contrast Processing:** Built-in methods to convert standard webcam video into DVS-style event frames.
|
|
26
|
+
* **Auto-Formatting:** Automatically center-crops and down-scales raw video arrays to the 128x128 resolution required by the network.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
You can install the latest release of TCASL from PyPI using `pip`:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install TCASL
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Usage in Python
|
|
37
|
+
|
|
38
|
+
Examples of how the library can be used can be found in [examples/](examples/). You should not edit this code unless you read the documentation thoroughly, which is located at [src/tcasl/core.py](src/tcasl/core.py).
|
|
39
|
+
|
|
40
|
+
## TCASL Project
|
|
41
|
+
|
|
42
|
+
You can find information about TCASL on the [GitHub page](https://github.com/keshavshankar08/TCASLCore).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tcasl
|