20.03.2021 Views

Deep-Learning-with-PyTorch

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

230 CHAPTER 8 Using convolutions to generalize

larger image. Creating bounding boxes around objects in an image is something a

model like ours can’t do.

Another hurdle concerns what happens when Fred the cat walks in front of the

camera. Our model will not refrain from giving its opinion about how bird-like the cat

is! It will happily output “airplane” or “bird,” perhaps with 0.99 probability. This issue

of being very confident about samples that are far from the training distribution is

called overgeneralization. It’s one of the main problems when we take a (presumably

good) model to production in those cases where we can’t really trust the input (which,

sadly, is the majority of real-world cases).

In this chapter, we have built reasonable, working models in PyTorch that can

learn from images. We did it in a way that helped us build our intuition around convolutional

networks. We also explored ways in which we can make our models wider and

deeper, while controlling effects like overfitting. Although we still only scratched the

surface, we have taken another significant step ahead from the previous chapter. We

now have a solid basis for facing the challenges we’ll encounter when working on

deep learning projects.

Now that we’re familiar with PyTorch conventions and common features, we’re

ready to tackle something bigger. We’re going to transition from a mode where each

chapter or two presents a small problem, to spending multiple chapters breaking

down a bigger, real-world problem. Part 2 uses automatic detection of lung cancer as

an ongoing example; we will go from being familiar with the PyTorch API to being

able to implement entire projects using PyTorch. We’ll start in the next chapter by

explaining the problem from a high level, and then we’ll get into the details of the

data we’ll be using.

8.7 Exercises

1 Change our model to use a 5 × 5 kernel with kernel_size=5 passed to the

nn.Conv2d constructor.

a What impact does this change have on the number of parameters in the

model?

b Does the change improve or degrade overfitting?

c Read https://pytorch.org/docs/stable/nn.html#conv2d.

d Can you describe what kernel_size=(1,3) will do?

e How does the model behave with such a kernel?

2 Can you find an image that contains neither a bird nor an airplane, but that the

model claims has one or the other with more than 95% confidence?

a Can you manually edit a neutral image to make it more airplane-like?

b Can you manually edit an airplane image to trick the model into reporting a

bird?

c Do these tasks get easier with a network with less capacity? More capacity?

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

Saved successfully!

Ooh no, something went wrong!