To get the most out of this book
Software/hardware covered in the book |
OS requirements |
Minimum 128 GB storage Minimum 8 GB RAM Intel i5 processor or better NVIDIA 8+ GB graphics card – GTX1070 or better Minimum 50 Mbps internet speed |
Windows, Linux, and macOS |
Python 3.6 and above |
Windows, Linux, and macOS |
PyTorch 2.1 |
Windows, Linux, and macOS |
Google Colab (can run in any browser) |
Windows, Linux, and macOS |
Do note that almost all the code in the book can be run using Google Colab by clicking the Open Colab button in each of the notebooks for the chapters on GitHub.
If you are using the digital version of this book, we advise you to type the code yourself or access the code via the GitHub repository (link available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
Download the example code files
The code bundle for the book is hosted on GitHub at https://github.com/PacktPublishing/Modern-Computer-Vision-with-PyTorch-2E. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://packt.link/gbp/9781803231334.
Conventions used
There are a number of text conventions used throughout this book.
CodeInText
: Indicates code words in the text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: “We are creating an object of the FMNISTDataset
class named val
, in addition to the train
object that we saw earlier.”
A block of code is set as follows:
# Crop image
img = img[50:250,40:240]
# Convert image to grayscale
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Show image
plt.imshow(img_gray, cmap='gray')
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
def accuracy(x, y, model):
model.eval() # <- let's wait till we get to dropout section
# get the prediction matrix for a tensor of `x` images
prediction = model(x)
# compute if the location of maximum in each row coincides
# with ground truth
max_values, argmaxes = prediction.max(-1)
is_correct = argmaxes == y
return is_correct.cpu().numpy().tolist()
Any command-line input or output is written as follows:
$ python3 -m venv fastapi-venv
$ source fastapi-env/bin/activate
Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: “We will apply gradient descent (after a feedforward pass) using one batch at a time until we exhaust all data points within one epoch of training.”
Warnings or important notes appear like this.
Tips and tricks appear like this.