This is a FastAPI application that predicts badminton shuttlecock speed based on sensor data using a pre-trained TensorFlow model.
.AIOT-Badminton-Speed-API/
├── app/
│ ├── __init__.py
│ ├── core/ # Core configurations and utilities
│ │ ├── __init__.py
│ │ └── config.py # Model loading and lifespan management
│ ├── models/ # Data models (Pydantic schemas)
│ │ ├── __init__.py
│ │ └── schemas.py # Defines SensorFrame, PredictionRequest, etc.
│ ├── services/ # Business logic and helper functions
│ │ ├── __init__.py
│ │ └── prediction_service.py # Data preprocessing and validation
│ └── main.py # Main FastAPI application
├── ml_model/ # Machine learning models and scalers
│ ├── __init__.py
│ ├── badminton_speed_predictor.h5
│ ├── feature_scaler.pkl
│ └── target_scaler.pkl
├── data/ # Data files (e.g., CSV, JSON)
├── requirements.txt # Python dependencies
├── api_test.py # API testing script
├── train.py # Model training script
└── README.md # Project README
-
Clone the repository (if you haven't already):
git clone <repository_url> cd AIOT-Badminton-Speed-API
-
Install
uv(if you haven't already):pip install uv
-
Create a virtual environment and install dependencies using
uv:uv sync
To start the FastAPI application, run the following command from the project root directory:
uv run ./app/main.pyThe API will be accessible at http://localhost:8000.
-
Root:
/GET: Returns a welcome message and available endpoints.
-
Health Check:
/healthGET: Checks the health of the service and model loading status.
-
Predict Speed:
/predict_speedPOST: Predicts badminton shuttlecock speed based on provided sensor data.- Request Body: A JSON object containing a
sensor_datafield, which is a list of 30SensorFrameobjects. - Response Body: A JSON object with
predicted_speed(in km/h) andconfidence_info.
- Request Body: A JSON object containing a
-
Predict Speed Batch:
/predict_speed_batchPOST: Predicts badminton shuttlecock speed for multiple sensor data inputs in a single request.- Request Body: A JSON object containing a
sensor_data_batchfield, which is a list ofPredictionRequestobjects. - Response Body: A JSON object with a list of
PredictionResponseobjects.
- Request Body: A JSON object containing a
You can use the api_test.py script to test the prediction endpoint. Make sure the FastAPI application is running before executing the test script.
uv run api_test.py- The pre-trained TensorFlow model (
badminton_speed_predictor.h5) and scikit-learn scalers (feature_scaler.pkl,target_scaler.pkl) are located in theml_model/directory. - Raw and processed data files are stored in the
data/directory.
train.py: Script used for training the speed prediction model.label_pseudo_speed.py: Script for pseudo-labeling data.label_real_speed.py: Script for real-labeling data.correlation.py: Script for analyzing data correlations.descibe.py: Script for describing data.
Feel free to explore the code and contribute!