Skip to content

This project trains a simple ML model in Python and serves it via HTTPS in Golang.

License

Notifications You must be signed in to change notification settings

Bagiukstis/go-serving

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sklearn Machine Learning Model Serving with Python and Go

About

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.

Project Structure

  • golang/: Contains Go server for serving the trained model.
  • images/: Test image
  • python/: Contains Python script for training the ML model.

Python

Trained sklearn ML model is converted to ONNX format using skl2onnx converter and stored in the models/ directory.

  1. Create and activate a virtual environment (recommended):
conda create --name [name] python=3.10
conda activate [name]
  1. Navigate to python/ directory and install the requirements
pip install -r requirements.txt
  1. Train and store the model
python3 python/train.py

Go

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:

  1. Navigate to the Go directory
cd golang
  1. Build the server binary:
go build -o go-serving main.go
  1. Run the server:
./go-serving

Alternatively, this can be ran using Docker.

  1. Build the Docker image
docker build -t go-serving:latest .
  1. 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"

Example input/output: alt text

About

This project trains a simple ML model in Python and serves it via HTTPS in Golang.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published