We will be using an image classifier I trained with Yolov8. The model was trained using this dataset and following this step by step tutorial on how to train an image classifier with Yolov8 on your custom data. The model is available here.
The model was successfully trained for 30 epochs achieving a ~96% accuracy.
Model performance. Validation and training loss during the training process
and validation accuracy. Accuracy is around 96%.
Log into your AWS account and launch a t2.xlarge EC2 instance, using the latest stable Ubuntu image.
SSH into the instance and run these commands to update the software repository and install the dependencies.
sudo apt-get update
sudo apt install -y python3-pip nginx
sudo nano /etc/nginx/sites-enabled/fastapi_nginx
And put this config into the file (replace the IP address with your EC2 instance's public IP):
server {
listen 80;
server_name <YOUR_EC2_IP>;
location / {
proxy_pass http://127.0.0.1:8000;
}
}
sudo service nginx restart
Update EC2 security-group settings for your instance to allow HTTP traffic to port 80.
Install dependencies:
pip install ultralytics fastapi uvicorn
Launch API:
python3 -m uvicorn main:app