Skip to content

Commit 0dba1e7

Browse files
committed
added L.E.P.A.U.T.E.
1 parent 66cb890 commit 0dba1e7

File tree

8 files changed

+850
-0
lines changed

8 files changed

+850
-0
lines changed

Computer Vision/L.E.P.A.U.T.E./LEPAUTE.py

Lines changed: 649 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# LEPAUTE
2+
3+
A Python package for processing webcam images with a Lie group-based Transformer model and accessing the resulting data.
4+
5+
## Installation
6+
7+
```
8+
pip install lepaute
9+
```
10+
11+
12+
## Usage
13+
14+
Run the [example_pip.py](example_pip.py) file.
15+
16+
## Requirements
17+
18+
- Python >= 3.8
19+
- torch >= 1.12.0
20+
- kornia == 0.7.0
21+
- opencv-python
22+
- numpy
23+
24+
## Notes
25+
26+
- Ensure webcam access for real-time data collection.
27+
- In Pyodide, data is stored in memory only.
28+
- Debug logs can be enabled by setting `logging.basicConfig(level=logging.DEBUG)`.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .LEPAUTE import get_collected_data, main
2+
from .data_access import load_data
3+
4+
__all__ = ["get_collected_data", "main", "load_data"]
9.14 MB
Binary file not shown.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import json
2+
import platform
3+
from typing import List, Dict
4+
from LEPAUTE import get_collected_data
5+
6+
def load_data(file_path: str = None) -> List[Dict]:
7+
"""
8+
Load collected data from memory or file.
9+
10+
Args:
11+
file_path (str, optional): Path to JSON file containing data (non-Pyodide environments).
12+
13+
Returns:
14+
List[Dict]: List of dictionaries containing pipeline data (images, lie_params, output, etc.).
15+
"""
16+
try:
17+
# Try loading from memory first
18+
data = get_collected_data()
19+
if data:
20+
return data
21+
22+
# If file_path provided and not in Pyodide, try loading from file
23+
if file_path and platform.system() != "Emscripten":
24+
with open(file_path, "r") as f:
25+
return json.load(f)
26+
27+
return []
28+
except Exception as e:
29+
print(f"Error loading data: {e}")
30+
return []
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import asyncio
2+
import os
3+
import cv2
4+
import numpy as np
5+
from LEPAUTE import main, get_collected_data
6+
from data_access import load_data
7+
import multiprocessing
8+
9+
async def display_all_data_window():
10+
"""Display all collected data in a single GUI window in real-time."""
11+
window_name = "All Collected Data"
12+
cv2.namedWindow(window_name, cv2.WINDOW_NORMAL)
13+
font = cv2.FONT_HERSHEY_SIMPLEX
14+
font_scale = 0.5
15+
color = (0, 255, 0) # Green text
16+
thickness = 1
17+
line_spacing = 20
18+
19+
while True:
20+
data = get_collected_data()
21+
height = max(100, 40 + len(data) * line_spacing * 8)
22+
img = np.zeros((height, 800, 3), dtype=np.uint8) # Black background
23+
24+
cv2.putText(img, "Collected Data Summary", (10, 20), font, font_scale, color, thickness)
25+
26+
if len(data) == 0:
27+
cv2.putText(img, "No data collected yet.", (10, 40), font, font_scale, color, thickness)
28+
else:
29+
for i, item in enumerate(data):
30+
y = 40 + i * line_spacing * 8
31+
cv2.putText(img, f"Entry {i + 1}:", (10, y), font, font_scale, color, thickness)
32+
cv2.putText(img, f" Image1 shape: {len(item['image1'])}, {len(item['image1'][0])}, {len(item['image1'][0][0])}",
33+
(10, y + line_spacing), font, font_scale, color, thickness)
34+
cv2.putText(img, f" Image2 shape: {len(item['image2'])}, {len(item['image2'][0])}, {len(item['image2'][0][0])}",
35+
(10, y + 2 * line_spacing), font, font_scale, color, thickness)
36+
cv2.putText(img, f" SO(2) theta: {item['lie_params'][0][0]:.4f}",
37+
(10, y + 3 * line_spacing), font, font_scale, color, thickness)
38+
cv2.putText(img, f" SE(2) params (tx, ty): ({item['lie_params'][0][1]:.2f}, {item['lie_params'][0][2]:.2f})",
39+
(10, y + 4 * line_spacing), font, font_scale, color, thickness)
40+
cv2.putText(img, f" Model output: {[f'{x:.2f}' for x in item['output'][0][:3]]}...",
41+
(10, y + 5 * line_spacing), font, font_scale, color, thickness)
42+
cv2.putText(img, f" Loss: {item['loss']:.4f}",
43+
(10, y + 6 * line_spacing), font, font_scale, color, thickness)
44+
cv2.putText(img, f" Label: {item['label']}",
45+
(10, y + 7 * line_spacing), font, font_scale, color, thickness)
46+
47+
cv2.imshow(window_name, img)
48+
if cv2.waitKey(1) & 0xFF == ord('q'): # Press 'q' to exit
49+
break
50+
await asyncio.sleep(0.1) # Update every 100ms to reduce CPU load
51+
52+
cv2.destroyWindow(window_name)
53+
54+
async def run_pipeline_and_access_data(display_mode: str = "json", frames_dir: str = "frames", save_json: bool = False, save_image: bool = False):
55+
print(f"Resource usage: Dynamic adjustment to maintain 10 FPS, targeting ~50% CPU ({multiprocessing.cpu_count()//2} threads initially) and ~50% GPU.")
56+
print("Monitor usage in Activity Monitor (macOS) under CPU and GPU tabs.")
57+
print(f"\nStarting the LEPAUTE pipeline in {display_mode} mode...")
58+
if save_image:
59+
print(f"Saving frames to {frames_dir}...")
60+
61+
if display_mode in ["gui", "realtime"]:
62+
asyncio.create_task(display_all_data_window())
63+
64+
await main(display_mode=display_mode, frames_dir=frames_dir, unlimited=True, save_json=save_json, save_image=save_image)
65+
66+
print("\nAccessing collected data from memory...")
67+
data = get_collected_data()
68+
69+
print(f"Total data entries: {len(data)}")
70+
if len(data) == 0:
71+
print("No data collected. Check webcam, feature extraction, or image texture.")
72+
for i, item in enumerate(data):
73+
print(f"\nData entry {i + 1}:")
74+
print(f" Image1 shape: {len(item['image1'])}, {len(item['image1'][0])}, {len(item['image1'][0][0])}")
75+
print(f" Image2 shape: {len(item['image2'])}, {len(item['image2'][0])}, {len(item['image2'][0][0])}")
76+
print(f" SO(2) theta: {item['lie_params'][0][0]:.4f}")
77+
print(f" SE(2) params (tx, ty): ({item['lie_params'][0][1]:.2f}, {item['lie_params'][0][2]:.2f})")
78+
print(f" Model output: {item['output']}")
79+
print(f" Loss: {item['loss']}")
80+
print(f" Label: {item['label']}")
81+
82+
if display_mode == "json" and save_json:
83+
print("\nAccessing data from file...")
84+
file_data = load_data("lepaute_data.json")
85+
print(f"Total file data entries: {len(file_data)}")
86+
if len(file_data) == 0:
87+
print("No data in file. Ensure pipeline ran successfully in json mode.")
88+
89+
if __name__ == "__main__":
90+
frames_dir = "frames"
91+
os.makedirs(frames_dir, exist_ok=True)
92+
93+
# Choose mode here: 'json', 'gui', or 'realtime'
94+
mode = "realtime" # Change to 'json' or 'gui' as needed
95+
save_json = False # Set to True to save JSON in json mode
96+
save_image = False # Set to True to save frames in json or gui mode
97+
98+
print(f"Running in {mode.upper()} mode...")
99+
print(f"Save JSON: {save_json}, Save Image: {save_image}")
100+
asyncio.run(run_pipeline_and_access_data(display_mode=mode, frames_dir=frames_dir, save_json=save_json, save_image=save_image))
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from lepaute import main, load_data
2+
import asyncio
3+
import logging
4+
5+
# Enable debug logging
6+
logging.basicConfig(level=logging.DEBUG)
7+
8+
# Run the pipeline
9+
asyncio.run(main())
10+
11+
# Access data
12+
data = load_data()
13+
for item in data:
14+
print(f"Lie params: {item['lie_params']}, Loss: {item['loss']}")
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name="lepaute",
5+
version="1.0.0",
6+
packages=find_packages(),
7+
install_requires=[
8+
"torch>=1.12.0",
9+
"kornia>=0.7.0",
10+
"opencv-python",
11+
"numpy"
12+
],
13+
author="Carson Wu",
14+
author_email="carson.developer1125@gmail.com",
15+
description="A package for accessing L.E.P.A.U.T.E. (Lie Equivariant Perception Algebraic Unified Transform Embedding Framework)",
16+
long_description=open("README.md").read(),
17+
long_description_content_type="text/markdown",
18+
url="https://github.com/dev1virtuoso/Machine-Learning/tree/main/Computer%20Vision/L.E.P.A.U.T.E.",
19+
classifiers=[
20+
"Programming Language :: Python :: 3",
21+
"License :: OSI Approved :: MIT License",
22+
"Operating System :: OS Independent",
23+
],
24+
python_requires=">=3.8",
25+
)

0 commit comments

Comments
 (0)