Lesson Supervised Learning for Image Analysis - Artificial Intelligence - ثالث ثانوي

Lesson 1 Supervised Learning for Image Analysis

Image Recognition

Learning Objectives

Tools > Jupyter Notebook

Lesson 1 Supervised Learning for Image Analysis

Supervised Learning for Computer Vision

Lesson 1 Supervised Learning for Image Analysis

In constrast, supervised learning involves training algorithms on labeled datasets,

Table 4.1: Challenges of visual data classification

Lesson 1 Supervised Learning for Image Analysis

Analyzing the data to extract informative patterns and features.

Loading and Preprocessing Images

Lesson 1 Supervised Learning for Image Analysis

The imread() function creates an "RGB" format of the image.

Lesson 1 Supervised Learning for Image Analysis

Resizing has the effect of converting RGB images to a float-based format:

Lesson 1 Supervised Learning for Image Analysis

The first image has a shape of (100, 100, 4). The "4" reveals

Lesson 1 Supervised Learning for Image Analysis

Grayscale images have only one channel (rather than the 3 RGB channels).

Lesson 1 Supervised Learning for Image Analysis

The next step is to convert the resized_images and labels lists to numpy arrays, which is expected

Prediction without Feature Engineering

Lesson 1 Supervised Learning for Image Analysis

The following code can be used to "flatten" each image into a one-dimensional vector.

Lesson 1 Supervised Learning for Image Analysis

Figure 4.7: Confusion matrix of MultinomialNB algorithm performance

The MultinomialNB algorithm achieves an accuracy around 30%.

MultinomialNB

SGDClassifier

Lesson 1 Supervised Learning for Image Analysis

Standard scaling

The following code uses the StandardScaler tool from the sklearn library to scale the data:

Lesson 1 Supervised Learning for Image Analysis

Prediction with Feature Selection

Lesson 1 Supervised Learning for Image Analysis

The next step is to create the HOG features for each image in the data.

Lesson 1 Supervised Learning for Image Analysis

A new SGDClassifier can now be trained on this new representation:

Lesson 1 Supervised Learning for Image Analysis

Prediction Using Neural Networks

Lesson 1 Supervised Learning for Image Analysis

The Sequential tool from the Keras library can now be used to build a neural network as a sequence of layers.

Lesson 1 Supervised Learning for Image Analysis

Given that the output layer has 16 neurons that are fully connected

Table 4.2: The arguments of the "compile" method

Lesson 1 Supervised Learning for Image Analysis

The fit() method is used to train a model on a given set of input data and labels.

Table 4.3: The arguments of the "fit" method

Lesson 1 Supervised Learning for Image Analysis

The trained model can now be used to predict the labels of the images in the testing set:

Prediction Using Convolutional Neural Networks

Lesson 1 Supervised Learning for Image Analysis

Despite the benefits of complex neural networks like CNNs, it is important to note that:

One of the key advantages of CNNs is that they are very good

Lesson 1 Supervised Learning for Image Analysis

Figure 4.14: Convolutional neural network without manual feature engineering

Transfer Learning

Lesson 1 Supervised Learning for Image Analysis

What are the challenges of visual data classification?

You are given two numpy arrays X_train and y_train. Each row in X_train has a shape

Descibe briefly how CNNs work and one of their key advantages.

Lesson 1 Supervised Learning for Image Analysis

You are given two numpy arrays X_train and y_train. Each row in X_train has a shape

Name some challenges of CNNs.