Simple Image Classification with ResNet 50 (2024)

Authors: Marie-Louise Christensen, Nina Danielsen, Pernille Franzen og Lisa Bro Nilsen.

Doing cool things with data doesn’t always need to be difficult. By using ResNet-50 you don’t have to start from scratch when it comes to building a classifier model and make a prediction based on it. This article is an beginners guide to ResNet-50. In the following you will get an short overall introduction to ResNet-50 and a simple tutorial on how to use it for image classification with python coding.

ResNet-50 is a pretrained Deep Learning model for image classification of the Convolutional Neural Network(CNN, or ConvNet), which is a class of deep neural networks, most commonly applied to analyzing visual imagery. ResNet-50 is 50 layers deep and is trained on a million images of 1000 categories from the ImageNet database. Furthermore the model has over 23 million trainable parameters, which indicates a deep architecture that makes it better for image recognition. Using a pretrained model is a highly effective approach, compared if you need to build it from scratch, where you need to collect great amounts of data and train it yourself. Of course, there are other pretrained deep models to use such as AlexNet, GoogleNet or VGG19, but the ResNet-50 is noted for excellent generalization performance with fewer error rates on recognition tasks and is therefore a useful tool to know.

Architecture of ResNet-50

ResNet stands for Residual Network and more specifically it is of a Residual Neural Network architecture. What characterizes a residual network is its identity connections. Identity connections takes the input directly to the end of each residual block, as shown below with the curved arrow:

Simple Image Classification with ResNet 50 (2)

Specifically, the ResNet-50 model consists of 5 stages each with a residual block. Each residual block has 3 layers with both 1*1 and 3*3 convolutions. The concept of residual blocks is quite simple. In traditional neural networks, each layer feeds into the next layer. In a network with residual blocks, each layer feeds into the next layer and directly into the layers about 2–3 hops away, called identity connections.

Classification case: Labrador Retriever

In this example we are using Google Colaboratory to do the code. You can use this link to get an introduction to Colab and create your own code in python: https://colab.research.google.com/notebooks/welcome.ipynb

When using colab, first, remember to change the runtime to GPU or else it will take a while when working with these deep learning networks.

Step 1: Importing the necessary libraries

First step is to import the necessary libraries needed to classify the images. In this case you need to use numpy, keras and matplotlib.

Simple Image Classification with ResNet 50 (3)

#Copy the Code HERE!

import numpy as np

from keras.preprocessing.image import image

from keras.preprocessing.image import img_to_array

from keras.applications.resnet50 import preprocess_input

from keras.applications.imagenet_utils import decode_predictions

import matplotlib.pyplot as plt

Step 2: Read and unzip the file

To download the dataset file into Google Colab it is useful to use the !wget command.Then it will be added to your file repository in colab and from there you can create a path way to the image or dataset you want to use.

Next is to unzip the file using the !unzip command and the full name of the file.

There are certainly other ways to load your dataset, but we find this to be the most simple way.

Simple Image Classification with ResNet 50 (4)

#Copy the Code HERE!:

!wget -qq http://sds-datacrunch.aau.dk/public/dataset.zip

!unzip -qq dataset.zip

Step 3: Preprocessing images for ResNet-50

Load a picture from the dataset before starting the preprocessing. When loading the picture remenber to set the right target size which for ResNet is 224*224.

Now the image is readable and it can be plotted.

Simple Image Classification with ResNet 50 (5)

Keras is expecting a list of images which is why we need to turn it into an array and then add another dimension to this. Following this we need to normalize the image using preprocess input method.

Simple Image Classification with ResNet 50 (6)

#Copy the code HERE!

img = image.load_img(‘dataset/single_prediction/cat_or_dog_1.jpg’, target_size = (224, 224))

plt.imshow(img)

img = image.img_to_array(img)

img = np.expand_dims(img, axis=0)

img = preprocess_input(img)

Step 4: Make a prediction using the ResNet-50 model in Keras

After preprocessing the image you can start classifying by simply instantiating the ResNet-50 model.

Simple Image Classification with ResNet 50 (7)

Now use the model.predict function on the preprocessed image which is called ‘img’.

To also print the prediction, use the print function and put the decode_prediction in the print argument and ‘preds’ in the decode_prediction argument.

Simple Image Classification with ResNet 50 (8)

As you see, our ResNet50 model easily classified the picture correct as a Labrador Retriever!

#Copy the code HERE!

model = ResNet50(weights=’imagenet’)

preds = model.predict(img)

print(‘Predicted:’, decode_predictions(preds, top=1)[0])

You can easily do this with other datasets. You can download other image datasets from:

https://towardsdatascience.com/understanding-and-coding-a-resnet-in-keras-446d7ff84d33

https://medium.com/datadriveninvestor/residual-network-architecture-8e478adabfec

https://medium.com/analytics-vidhya/cnns-architectures-lenet-alexnet-vgg-googlenet-resnet-and-more-666091488df5

https://medium.com/@venkinarayanan/tutorial-image-classifier-using-resnet50-deep-learning-model-python-flask-in-azure-4c2b129af6d2

https://www.mathworks.com/help/deeplearning/ref/resnet50.html

https://engmrk.com/kerasapplication-pre-trained-model/?utm_campaign=News&utm_medium=Community&utm_source=DataCamp.com

Simple Image Classification with ResNet 50 (2024)
Top Articles
Super Mario 3D World Stars and Stamps guide: How to get all 380 Green Stars and 85 Stamps
Walkthrough - Super Mario 3D World Guide - IGN
Garrison Blacksmith Bench
13 Easy Ways to Get Level 99 in Every Skill on RuneScape (F2P)
Puretalkusa.com/Amac
Yi Asian Chinese Union
New Day Usa Blonde Spokeswoman 2022
Derpixon Kemono
Conduent Connect Feps Login
The Connecticut Daily Lottery Hub
Koop hier ‘verloren pakketten’, een nieuwe Italiaanse zaak en dit wil je ook even weten - indebuurt Utrecht
Five Day National Weather Forecast
I Touch and Day Spa II
9044906381
Justified Official Series Trailer
Kayky Fifa 22 Potential
Transactions (zipForm Edition) | Lone Wolf | Real Estate Forms Software
Viha Email Login
The Old Way Showtimes Near Regency Theatres Granada Hills
T Mobile Rival Crossword Clue
Walgreens Bunce Rd
Hdmovie2 Sbs
When His Eyes Opened Chapter 3123
Enduring Word John 15
Democrat And Chronicle Obituaries For This Week
Criglist Miami
HP PARTSURFER - spare part search portal
Log in to your MyChart account
Ezstub Cross Country
2487872771
Puretalkusa.com/Amac
Craigslist Neworleans
Arcane Odyssey Stat Reset Potion
Xemu Vs Cxbx
Chuze Fitness La Verne Reviews
“Los nuevos desafíos socioculturales” Identidad, Educación, Mujeres Científicas, Política y Sustentabilidad
Has any non-Muslim here who read the Quran and unironically ENJOYED it?
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Wasmo Link Telegram
The Realreal Temporary Closure
Owa Hilton Email
Portal Pacjenta LUX MED
Oklahoma City Farm & Garden Craigslist
Hampton In And Suites Near Me
Willkommen an der Uni Würzburg | WueStart
Sherwin Source Intranet
Nope 123Movies Full
Meee Ruh
Random Warzone 2 Loadout Generator
Convert Celsius to Kelvin
Yoshidakins
Guidance | GreenStar™ 3 2630 Display
Latest Posts
Article information

Author: Msgr. Benton Quitzon

Last Updated:

Views: 5885

Rating: 4.2 / 5 (43 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Msgr. Benton Quitzon

Birthday: 2001-08-13

Address: 96487 Kris Cliff, Teresiafurt, WI 95201

Phone: +9418513585781

Job: Senior Designer

Hobby: Calligraphy, Rowing, Vacation, Geocaching, Web surfing, Electronics, Electronics

Introduction: My name is Msgr. Benton Quitzon, I am a comfortable, charming, thankful, happy, adventurous, handsome, precious person who loves writing and wants to share my knowledge and understanding with you.