https://github.com/altescy/sagemaker-example
Example of training and deploying your own machine learning model with AWS SageMaker
https://github.com/altescy/sagemaker-example
fastapi machine-learning python sagemaker
Last synced: 3 months ago
JSON representation
Example of training and deploying your own machine learning model with AWS SageMaker
- Host: GitHub
- URL: https://github.com/altescy/sagemaker-example
- Owner: altescy
- License: mit
- Created: 2021-11-03T10:19:52.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-02-08T02:20:21.000Z (over 3 years ago)
- Last Synced: 2025-03-21T16:21:23.008Z (over 1 year ago)
- Topics: fastapi, machine-learning, python, sagemaker
- Language: Python
- Homepage:
- Size: 422 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sagemaker-example
This repository provides a simple example of training and deploying your own machine learning model with AWS SageMaker.
## Usage
1. Upload dataset files to S3
```
aws s3 cp ./data/iris.csv s3://your-bucket/path/to/dataset/iris.csv
```
2. Build and push the docker image to ECR
```
./scripts/build_and_push_ecr.sh your-image-name
```
3. Train a model with SageMaker
```
poetry run python scripts/train.py \
--dataset-path s3://your-bucket/path/to/dataset \
--artifact-path s3://your-bucket/path/to/artifacts \
--image-uri xxxxxxxxxxxx.dkr.ecr.ap-northeast-1.amazonaws.com/your-image-name \
--execution-role arn:aws:iam::xxxxxxxxxxxx:role/SageMakerExecutionRole
```
4. Deploy the trained model
```
poetry run python scripts/deploy.py \
--endpoint-name your-endpoint-name \
--training-job training-job-name
```
5. Invoke the endpoint
```
poetry run python scripts/predict.py -n your-endpoint-name data/test.json
```
6. Delete the endpoint
```
aws sagemaker delete-endpoint --endpoint-name your-endpoint-name
```
## Local mode
1. Train a model on your local machie
```
poetry run python -m sagemaker_example train --local
```
2. Serve the endpoint on your local machine
```
poetry run python -m sagemaker_example serve --local --port 8080
```
3. Train a model with local mode
```
poetry run python scripts/train.py \
--local \
--dataset-path file://`pwd`/data \
--artifact-path file://`pwd`/data \
--image-uri xxxxxxxxxxxx.dkr.ecr.ap-northeast-1.amazonaws.com/your-image-name \
--execution-role dummy/dummy
```