Skip to content

Explore image classification using IBM CV Studio and CNNs with PyTorch. This repository guides you through setting up, training, deploying, and testing a classifier for 'Stop' and 'Not Stop' signs, leveraging cloud infrastructure for seamless development and deployment.

License

Notifications You must be signed in to change notification settings

akhilaprabodha/Classification-using-IBM-CV-Studio-and-CNN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🚦 Classification Using IBM CV Studio and CNN

This repository contains a step-by-step guide to building and deploying a classifier using IBM CV Studio and Convolutional Neural Networks (CNN) with PyTorch.

1. Obtain IBM Cloud Feature Code and Activate Trial Account

If you have already applied your IBM Cloud feature code in another course/lab to create an IBM Cloud account, please skip this item, as the code can only be used once.

Important

While signing up for an IBM Cloud account, or at a later stage, you may be prompted to enter a credit card. Please note that access to paid services or a credit card is NOT required to complete any mandatory labs/projects/assignments here. Those who have a Feature Code can enable trial access to IBM Cloud for a limited duration. Therefore, we strongly recommend that you DO NOT enter a credit card to complete the required course components.

Note

You can get a Feature Code for your academic institute (if it's included) from Cloud for Education or from the course Introduction to Computer Vision and Image Processing.

Warning

If you still choose to enter your Credit Card to use IBM Cloud services, you will be liable to pay any resulting charges billed to your credit card.

2. Set Up Computer Vision Learning Environment

When building Computer Vision applications, we deal with a lot of images, videos, and other assets that require storage. Image processing also requires significant computing power. The ultimate goal of every computer vision project is to have it deployed as part of an application, and every application requires infrastructure to run.

To help you with your learning, IBM is providing storage, compute, and application infrastructure on the cloud. To use these resources, you need to have an IBM Cloud account. This account is free of charge and does not require any commitment. If you already have an account on IBM Cloud, go ahead to the next section; otherwise, follow the steps below to create an IBM Cloud account and associate CV Studio with this account.

Pre-requisites

You will need an IBM Cloud account to do this lab. If you have not created one already, click on this link and follow the instructions to create an IBM Cloud account.

Step 1: Connect CV Studio to Your IBM Cloud Account

  1. Go to CV Studio
  2. Click on My Projects in the top right corner.
  3. Click Sign into IBM Cloud at the top right corner.

Sign into IBM Cloud

You are all set!

Congratulations! Your learning environment is all set with access to storage, compute, and application infrastructure. Please remember your IBM Cloud ID and password. You will need them to log in if prompted.

Task 1: Gather and Upload Your Data

To train your classifier, you will need to download the dataset containing the "Stop" sign images found here and the "not Stop" sign images found here. They are zipped in a folder.

  1. Click on Launch App.
  2. Sign in with your created credentials if prompted.
  3. Select the template for this project.

Project Template

  1. Unzip the files, then drag and drop the folders into the Upload section in CV Studio.
  2. Make sure to wait between each folder to ensure that it has loaded properly.
  3. Confirm that images have been loaded.
  4. In the annotate section, you will see that the images are pre-labeled with the folder name.

Proceed to the next task once you have gathered and uploaded your images and verified that your images are pre-labeled in the Annotation tab of CV Studio.

Task 2: Training Your Classifier

Create your own Train run:

  1. Click on Train Model on the side panel.
  2. Create a New training run, enter a Name, choose Jupyter notebook as a "Training tool", and select Convolutional Neural Networks (CNN) with PyTorch.

Train Model

Tip

You can run the notebook by clicking Open Notebook in the TRAIN column. It will open a Skill Network Labs and run the train-classification-cnn-pytorch.ipynb after uploading it.

Task 3: Deploy to Code Engine

  1. Click on Use Model and New Application.

Use Model

  1. When you click New Application, enter an app name, choose Models in this project, use the saved train model, and choose the Test-1-click Deploy your Model to Cloud (Code Engine) and create the application.

New Application

  1. Once you are done, it will start deploying and tell you when it is ready.

Deployment

Tip

By clicking URL you will redirect to the webpage that you can classify your own images on browser.

  1. Once it is ready, you will see the green READY button:

Ready

Task 4: Test Your Classifier

  1. Click on Open Notebook to open the Jupyter notebook from the Train model phase.

Note

Make sure that the result of the training model is visible under Details of Run.

Details of Run

  1. Add the below-mentioned code by adding a cell to the end of the model training notebook. Note: It's already added to the train-classification-cnn-pytorch.ipynb.
imageNames = ['stop_1.jpeg','stop_2.jpeg','not_stop_1.jpeg']
for imageName in imageNames:
    image = Image.open(imageName)
    transform = composed = transforms.Compose([transforms.Resize((224, 224)), transforms.ToTensor()])
    x = transform(image)
    z = model(x.unsqueeze_(0))
    _, yhat = torch.max(z.data, 1)
    # print(yhat)
    prediction = "Stop"
    if yhat == 1:
        prediction = "Not Stop"
    imshow_(transform(image), imageName + ": Prediction = " + prediction)
  1. Now, download the test images.
  • You will find test images here. Note: if you are using Firefox, please right-click the link and select Save Link As.
  1. Then, upload the images to the Skill Network Labs.
Screen_Shot_2021-04-27_at_3 58 39_PM
  1. After uploading the images, Run the code for testing your classifier.

Take a screenshot of the following image after the prediction. You can find how to take a screenshot for Mac here and Windows here

Screen_Shot_2021-04-27_at_3 58 39_PM

Your prediction will show at the top.

πŸŽ‰ Congratulations!

You have successfully trained, deployed, and tested your classifier using IBM CV Studio and CNN.

🏷️ References

About

Explore image classification using IBM CV Studio and CNNs with PyTorch. This repository guides you through setting up, training, deploying, and testing a classifier for 'Stop' and 'Not Stop' signs, leveraging cloud infrastructure for seamless development and deployment.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published