Daniel Voigt Godoy - Deep Learning with PyTorch Step-by-Step A Beginner’s Guide-leanpub

peiying410632
from peiying410632 More from this publisher
22.02.2024 Views

Data GenerationOur images are quite simple: They have black backgrounds and white lines drawnon top of them. The lines can be drawn either in a diagonal or in a parallel (to one ofthe edges, so they could be either horizontal or vertical) way. So, our classificationproblem can be simply stated as: Is the line diagonal?If the line is diagonal, then we assume it belongs to the positive class. If it is notdiagonal, it belongs to the negative class. We have our labels (y), which we cansummarize like this:Line Value ClassNot Diagonal 0 NegativeDiagonal 1 PositiveLet’s generate 300 random images, each one five-by-five pixels in size:Data Generation1 images, labels = generate_dataset(2 img_size=5, n_images=300, binary=True, seed=133 )And then let’s visualize the first 30 images:fig = plot_images(images, labels, n_plot=30)Classifying Images | 267

Figure 4.1 - Image datasetSince our images are quite small, there aren’t that many possibilities for drawinglines on top of them. There are actually 18 different configurations for diagonallines (nine to the left, nine to the right), and 10 different configurations forhorizontal and vertical lines (five each). That’s a total of 28 possibilities in a 300-image dataset. So, there will be lots of duplicates (like images #1 and #2, or #6 and#7, for example), but that’s fine.268 | Chapter 4: Classifying Images

Figure 4.1 - Image dataset

Since our images are quite small, there aren’t that many possibilities for drawing

lines on top of them. There are actually 18 different configurations for diagonal

lines (nine to the left, nine to the right), and 10 different configurations for

horizontal and vertical lines (five each). That’s a total of 28 possibilities in a 300-

image dataset. So, there will be lots of duplicates (like images #1 and #2, or #6 and

#7, for example), but that’s fine.

268 | Chapter 4: Classifying Images

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!