deep learning notes with matlab

[Learning notes from matlab deep learing Onramp]

 

1 image dataset

one can use imageDatastore function to create the dataset

imds = imageDatastore(location,Name,Value)

by using imageread function ,you can read the specific file, which is similar to imread, but more powerful

Read image from graphics file

img=readimage(imds,7)
imshow(img)

2 deep learning Onramp in matlab

Create a Datastore

Instructions are in the task pane to the left. Complete and submit each task one at a time.

 

This code displays the images in the current folder and imports AlexNet.

ls *.jpg

net = alexnet;

 

Task 1

Create datastore

imds=imageDatastore('file*.jpg')

 

Task 2

Extract file names

fname=imds.Files

 

Task 3

Read an image

img=readimage(imds,7)

imshow(img)

 

Task 4

Classify images

preds=classify(net,imds)

[preds, scores]=classify(net,imds)

max(scores,[],2)

M = max(A,[],dim) returns the maximum element along dimension dim. For example, if A is a matrix, then max(A,[],2) is a column vector containing the maximum value of each row.

3.2 Preparing Images to Use as Input:

Task 1

View image size

sz=size(img) %1096*822*3

 

Task 2

Load network and view input size

net=alexnet

insz=net.Layers(1).InputSize  %% 227*277*3

Task 3

Resize image and display

img=imresize(img,[227, 227])

imshow(img)

 The main reson is that the pretrained networks have defined their inputsize, if you want to use transfer learing, you should resize your image to match the input size.

3.3 Processing Images in a Datastore:

  

Preprocessing images with a datastore

To classify images with a convolutional neural network, each image needs to have the size specified by the network's input layer.

Images usually require simple preprocessing before they can be classified. You can preprocess your images individually, but it is common to perform the same preprocessing steps on the entire data set. It is more efficient to apply these steps to the entire datastore.

Preprocess by hand

Preprocess with a datastore

It can be time consuming to process each image individually. If you want to use an image datastore, you also need to save the processed images to a folder. For large data sets, saving a duplicate of your files can take up a lot of space.

You can perform basic preprocessing with the augmentedImageDatastore function, which takes an image datastore and an image size as an input. The datastore can be passed to the classify function.

auimds = augmentedImageDatastore(outputSize,imds) creates an augmented image datastore for classification problems using images from image datastore imds, and sets the OutputSize property.

 

Task 1

Create datastore

imds=imageDatastore('*.jpg')

 

Task 2

An augmented image datastore can perform simple preprocessing on an entire collection images. To create this datastore, use the augmentedImageDatastore function using your network's image input size as input.

auds = augmentedImageDatastore([r c],imds)

 

Create augmentedImageDatastore

Create an augmented image datastore from imds that will resize the images to 227-by-227. Name the new datastore auds.

auds=augmentedImageDatastore([227,227],imds)

Task 3

Classify datastore

You can use the augmented image datastore as input to the classify function. Before each image is classified, it will be preprocessed using the methods that you specified when you created the datastore. 

Task

Classify the images in auds using the classify function using the network stored in the variable net. Store the predictions in a variable preds.

preds=classify(net,auds)

Complete!
Resizing is one of the most common preprocessing steps when classifying images.

Augmented image datastores can perform a variety of other preprocessing methods. You'll use the augmentedImageDatastore function to convert grayscale images to RGB images in the next section.

3.3 Processing Images in a Datastore: (3/3) Color preprocessing with augmented image datastores

Preprocess Color Using a Datastore

Instructions are in the task pane to the left. Complete and submit each task one at a time.

 

This code displays the images in the current folder and imports AlexNet.

ls *.jpg

net = alexnet

This code creates an image datastore of these images.

imds = imageDatastore('file*.jpg')

 

Task 1

Display images in imds

montage(imds)

Task 2

Create augmentedImageDatastore

auds=augmentedImageDatastore([227 227],imds,'ColorPreprocessing','gray2rgb')

Task 3

Classify datastore

preds=classify(net,auds)

montage(auds.Files)  % display the image data

Complete! Images are required to be the size specified by a network's image input layer. Once your images are the correct size, you are ready to use pretrained networks to classify your data!

There are other methods, such as image augmentation, that are useful when you train networks. Check out the documentation to see what else you can do with augmented image datastores:
Preprocess Images for Deep Learning

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

做一个码农都是奢望

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值