This project involves training a simple machine learning (ML) model in Python, converting it to ONNX format, and serving it over HTTPS using a Golang server.
golang/
: Contains Go server for serving the trained model.images/
: Test imagepython/
: Contains Python script for training the ML model.
Trained sklearn ML model is converted to ONNX format using skl2onnx converter and stored in the models/
directory.
- Create and activate a virtual environment (recommended):
conda create --name [name] python=3.10
conda activate [name]
- Navigate to
python/
directory and install the requirements
pip install -r requirements.txt
- Train and store the model
python3 python/train.py
ONNX model is loaded using onnxruntime_go wrapper and served via HTTPS.
For reproducing make sure you have go
installed and run the following commands:
- Navigate to the Go directory
cd golang
- Build the server binary:
go build -o go-serving main.go
- Run the server:
./go-serving
Alternatively, this can be ran using Docker.
- Build the Docker image
docker build -t go-serving:latest .
- Run Docker container
docker run -p 8080:8080 go-serving:latest
Open a new terminal and paste the following request:
curl -X POST https://localhost:8080/inference -d '{"input_data": [5.8, 2.8, 5.1, 2.4]}' -H "Content-Type: application/json"