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.
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.
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.
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.
- Go to CV Studio
- Click on
My Projects
in the top right corner. - Click
Sign into IBM Cloud
at the top right corner.
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.
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.
- Click on Launch App.
- Sign in with your created credentials if prompted.
- Select the template for this project.
Unzip
the files, then drag and drop the folders into theUpload
section in CV Studio.- Make sure to wait between each folder to ensure that it has loaded properly.
- Confirm that images have been loaded.
- 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.
Create your own Train
run:
- Click on
Train Model
on the side panel. - Create a
New training run
, enter aName
, chooseJupyter notebook
as a "Training tool", and selectConvolutional Neural Networks (CNN) with PyTorch
.
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.
- Click on
Use Model
andNew Application
.
- When you click
New Application
, enter an app name, chooseModels in this project
, use the saved train model, and choose theTest-1-click Deploy your Model to Cloud (Code Engine)
and create the application.
- Once you are done, it will start deploying and tell you when it is ready.
Tip
By clicking URL you will redirect to the webpage that you can classify your own images on browser.
- Once it is ready, you will see the green READY button:
- 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
.
- 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)
- 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
.
- Then, upload the images to the Skill Network Labs.
![Screen_Shot_2021-04-27_at_3 58 39_PM](https://private-user-images.githubusercontent.com/107745538/344395613-1287b0a7-15a7-4334-a3a0-0e7e73ce528d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU2Nzg0MjQsIm5iZiI6MTcyNTY3ODEyNCwicGF0aCI6Ii8xMDc3NDU1MzgvMzQ0Mzk1NjEzLTEyODdiMGE3LTE1YTctNDMzNC1hM2EwLTBlN2U3M2NlNTI4ZC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTA3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkwN1QwMzAyMDRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0zYmU1NjA2MDFjY2RjY2RlMzkwYTY1ZDkyODI0NzIwMGU0MmU3ZjA4MjY1ZGY3ZGIyNzFlMzViMzExNTNkYjA1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.OQtG9h2xbNyMCO5M_Q5D_Kbq7EfcEwHVoZB8E6NgoEY)
- 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](https://private-user-images.githubusercontent.com/107745538/344395768-f2105751-2a4b-4f45-997b-275c94371a70.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU2Nzg0MjQsIm5iZiI6MTcyNTY3ODEyNCwicGF0aCI6Ii8xMDc3NDU1MzgvMzQ0Mzk1NzY4LWYyMTA1NzUxLTJhNGItNGY0NS05OTdiLTI3NWM5NDM3MWE3MC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwOTA3JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDkwN1QwMzAyMDRaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT03ZWI4NTVjMzBmODVjNjQ0NDc4ZWIyMjEzZTc2MWI1ODQyOWY0ZDEzNWMxMmFjMGNkOWNiYjllODlhNmY3OTFiJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.ALeoO-7zjrfTY65HFGp9lYjlbXnOO67Syq9FVWaGLVM)
Your prediction will show at the top.
You have successfully trained, deployed, and tested your classifier using IBM CV Studio and CNN.
- Introduction to Computer Vision and Image Processing by IBM on Cousera