Spaces:
Sleeping
Sleeping
Update to more accurate model with scaler normalization
Browse files- Updated to new trained model (more accurate)
- Added scaler.bin for feature normalization
- Updated to 10 gesture classes (removed 'hi')
- Increased sequence length from 10 to 30 frames
- Raised confidence threshold from 0.5 to 0.7
- Added joblib dependency for scaler loading
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Files changed (5)
- Dockerfile+1
- app.py+18-3
- requirements.txt+2-1
- scaler.binAdded+3
- trained_model.pth+2-2
20 unmodified lines21222324252620 unmodified linesCOPY model.py .COPY preprocessing.py .COPY trained_model.pth .# Expose port 7860 (Hugging Face Spaces default)EXPOSE 786020 unmodified lines2122232425262720 unmodified linesCOPY model.py .COPY preprocessing.py .COPY trained_model.pth .COPY scaler.bin .# Expose port 7860 (Hugging Face Spaces default)EXPOSE 7860
3 unmodified lines45678923 unmodified lines333435363738391 unmodified line414243444546472 unmodified lines5051525354553 unmodified lines59606162636496 unmodified lines1611621631641651661671683 unmodified linesimport osimport torchimport numpy as npfrom fastapi import FastAPI, HTTPExceptionfrom fastapi.middleware.cors import CORSMiddlewarefrom pydantic import BaseModel23 unmodified lines# Gesture classesGESTURES = ['minum', 'berjalan', 'berlari', 'bola', 'dari','hi', 'jangan', 'mohon', 'pen', 'teh tarik', 'tolong']# Configuration1 unmodified lineHIDDEN_SIZE = 64NUM_CLASSES = len(GESTURES)SEQUENCE_LENGTH = 30CONFIDENCE_THRESHOLD = 0.5# Device configurationdevice = torch.device("cuda" if torch.cuda.is_available() else "cpu")2 unmodified lines# Load modelmodel = CustomLSTM(INPUT_SIZE, HIDDEN_SIZE, NUM_CLASSES).to(device)model_path = "trained_model.pth"try:model.load_state_dict(torch.load(model_path, map_location=device))3 unmodified linesprint(f"Error loading model: {e}")raise# Initialize MediaPipemp_holistic = mp.solutions.holisticholistic = mp_holistic.Holistic(96 unmodified lines# Make predictionsequence = sequences[request.session_id][-SEQUENCE_LENGTH:]input_tensor = torch.tensor(np.expand_dims(sequence, axis=0),dtype=torch.float32).to(device)3 unmodified lines4567891023 unmodified lines343536373839401 unmodified line424344454647482 unmodified lines515253545556573 unmodified lines616263646566676869707172737496 unmodified lines1711721731741751761771781791801811821833 unmodified linesimport osimport torchimport numpy as npimport joblibfrom fastapi import FastAPI, HTTPExceptionfrom fastapi.middleware.cors import CORSMiddlewarefrom pydantic import BaseModel23 unmodified lines# Gesture classesGESTURES = ['minum', 'berjalan', 'berlari', 'bola', 'dari','jangan', 'mohon', 'pen', 'teh tarik', 'tolong']# Configuration1 unmodified lineHIDDEN_SIZE = 64NUM_CLASSES = len(GESTURES)SEQUENCE_LENGTH = 30CONFIDENCE_THRESHOLD = 0.7# Device configurationdevice = torch.device("cuda" if torch.cuda.is_available() else "cpu")2 unmodified lines# Load modelmodel = CustomLSTM(INPUT_SIZE, HIDDEN_SIZE, NUM_CLASSES).to(device)model_path = "trained_model.pth"scaler_path = "scaler.bin"try:model.load_state_dict(torch.load(model_path, map_location=device))3 unmodified linesprint(f"Error loading model: {e}")raise# Load scalertry:scaler = joblib.load(scaler_path)print(f"Scaler loaded successfully from {scaler_path}")except Exception as e:print(f"Error loading scaler: {e}")raise# Initialize MediaPipemp_holistic = mp.solutions.holisticholistic = mp_holistic.Holistic(96 unmodified lines# Make predictionsequence = sequences[request.session_id][-SEQUENCE_LENGTH:]sequence_array = np.array(sequence)# Apply scaler transformationsequence_scaled = scaler.transform(sequence_array)input_tensor = torch.tensor(np.expand_dims(sequence_scaled, axis=0),dtype=torch.float32).to(device)
7 unmodified lines89101112133 unmodified lines171819207 unmodified linestorch==2.1.0torchvision==0.16.0numpy==1.26.4# Computer Vision & MediaPipeopencv-python-headless==4.10.0.843 unmodified linesPillow==10.1.0# CORS support# FastAPI includes CORS middleware via Starlette; no extra package needed.7 unmodified lines8910111213143 unmodified lines181920217 unmodified linestorch==2.1.0torchvision==0.16.0numpy==1.26.4joblib==1.3.2# Computer Vision & MediaPipeopencv-python-headless==4.10.0.843 unmodified linesPillow==10.1.0# CORS supportpython-cors==1.0.0
123version https://git-lfs.github.com/spec/v1oid sha256:b7c9eeb95ab696a19b0a68a4c04f8b892f95dc527a3ac2284ea6fd2530f9c29csize 6807123version https://git-lfs.github.com/spec/v1oid sha256:c7d97b7dcaea6c08b904d37264641b699af89b8e4347042668b9805371dd06a5size 489131123version https://git-lfs.github.com/spec/v1oid sha256:91c78878580fd5637c8e3d9314ccdd97a150074234453d9f0d10e54d7651ac62size 487643
Dockerfile+1
app.py+18-3
requirements.txt+2-1
scaler.binAdded+3
trained_model.pth+2-2