Code Monkey home page Code Monkey logo

dog-breed-classification's Introduction

Image Classification using AWS SageMaker

Use AWS Sagemaker to train a pretrained model that can perform image classification by using the Sagemaker profiling, debugger, hyperparameter tuning and other good ML engineering practices. This can be done on either the provided dog breed classication data set or one of your choice.

Project Set Up and Installation

Enter AWS through the gateway in the course and open SageMaker Studio. Download the starter files. Download/Make the dataset available.

Dataset

The provided dataset is the dogbreed classification dataset which can be found in the classroom. The project is designed to be dataset independent so if there is a dataset that is more interesting or relevant to your work, you are welcome to use it to complete the project.

Access

Upload the data to an S3 bucket through the AWS Gateway so that SageMaker has access to the data.

Hyperparameter Tuning

I used ResNet18 for this project as it's basically designed for image identification

The three hyperparamters that I tuned over my training job were:

  • batch_size
  • epochs
  • lr

Here you can see a screenshot including all of the training jobs: Training Running

And this a screenshot of hyperparameter tuning jobs that were done in this project: hpo Running

The best model we obtain was built using these hyperparameters:

  • batch_size : 128
  • epochs : 4
  • lr : 0.005200376250895876

Debugging and Profiling

Debugging and profiling was performed according to the the following rules:

    ProfilerRule.sagemaker(rule_configs.LowGPUUtilization()),
    ProfilerRule.sagemaker(rule_configs.ProfilerReport()),
    Rule.sagemaker(rule_configs.vanishing_gradient()),
    Rule.sagemaker(rule_configs.overfit()),

To allow for debugging; the train_model.py has been created based on the hpo.py and setting up hooks inside functions of training and testing.

Results

The results of the debugging/profiling session arose the following output:

VanishingGradient: NoIssuesFound Overfit: NoIssuesFound LowGPUUtilization: NoIssuesFound ProfilerReport: NoIssuesFound

You can also read the profiler report html file in case of finding any issues in one of the above

Model Deployment

To deploy the model, it was required to create a python script called inference.py which loads the model and transforms the input image.

To call the model, you execute inference.py replacing IMAGE_PATH by the path where your image is stored and ENDPOINT by the name of your endpoint.

import io
import sagemaker
from PIL import Image
from sagemaker.serializers import IdentitySerializer
from sagemaker.pytorch.model import PyTorchPredictor

serializer = IdentitySerializer("image/jpeg")
predictor = PyTorchPredictor(ENDPOINT, serializer=serializer, sagemaker_session=sagemaker.Session())

buffer = io.BytesIO()
Image.open(IMAGE_PATH).save(buffer, format="JPEG")
response = predictor.predict(buffer.getvalue())

And as we can in this screenshot, the endpoint is deployed and in service: Endpoint Running

dog-breed-classification's People

Contributors

abed221 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.