Skip to content

Commit 6029ee2

Browse files
committed
Add comments
1 parent fbf7880 commit 6029ee2

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

pytorch_tutorial/convolutional_neural_network/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ conv2d_kernel_size = 3 # Size of the 2D convolution kernels
5454

5555
We use [Fashion-MNIST](https://github.com/zalandoresearch/fashion-mnist), a classic dataset for image recognition. Each example is a 28x28 grayscale image, associated with a label (fashion category) from 10 possible classes: t-shirt, trouser, pullover...
5656

57-
This dataset is provided by PyTorch through the [FashionMNIST](https://pytorch.org/vision/0.19/generated/torchvision.datasets.FashionMNIST.html) class. In order to evaluate the trained model performance on unseen data, this class lets us download either the training set (60,000 images) or the test set (10,000 images).
57+
No need to download it manually: this dataset is provided by PyTorch through the [FashionMNIST](https://pytorch.org/vision/0.19/generated/torchvision.datasets.FashionMNIST.html) class, which lets us download either the training set (60,000 images) or the test set (10,000 images).
5858

5959
Alongside download, a [transform](https://pytorch.org/vision/main/transforms.html) operation is applied to turn images into PyTorch tensors of shape `(color_depth, height, width)`, with pixel values scaled to the $[0,1]$ range.
6060

@@ -64,7 +64,9 @@ Alongside download, a [transform](https://pytorch.org/vision/main/transforms.htm
6464
# Directory for downloaded files
6565
DATA_DIR = "./_output"
6666

67-
# Download and construct the Fashion-MNIST images dataset
67+
# Download and construct the Fashion-MNIST images dataset.
68+
# ToTensor() converts a PIL Image or NumPy array (H x W x C) in the range [0, 255]
69+
# to a PyTorch tensor of shape (C x H x W) in the range [0.0, 1.0].
6870
# The training set is used to train the model
6971
train_dataset = datasets.FashionMNIST(
7072
root=DATA_DIR,
Loading

pytorch_tutorial/convolutional_neural_network/test_convolutional_neural_network.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ def test_convolutional_neural_network(show_plots=False):
7070
batch_size = 64 # Number of samples used for one gradient descent step
7171
conv2d_kernel_size = 3 # Size of the 2D convolution kernels
7272

73-
# Download and construct the Fashion-MNIST images dataset
73+
# Download and construct the Fashion-MNIST images dataset.
74+
# ToTensor() converts a PIL Image or NumPy array (H x W x C) in the range [0, 255]
75+
# to a PyTorch tensor of shape (C x H x W) in the range [0.0, 1.0].
7476
# The training set is used to train the model
7577
train_dataset = datasets.FashionMNIST(
7678
root=DATA_DIR,

pytorch_tutorial/multilayer_perceptron/test_multilayer_perceptron.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ def test_multilayer_perceptron(show_plots=False):
3030

3131
# Hyperparameters
3232
n_samples = 500 # Number of data samples
33-
hidden_layer_dim = 3 # Number of neurons on the hidden layer of the MLP
3433
n_epochs = 50 # Number of training iterations on the whole dataset
3534
learning_rate = 0.1 # Rate of parameter change during gradient descent
3635
batch_size = 5 # Number of samples used for one gradient descent step
36+
hidden_layer_dim = 3 # Number of neurons on the hidden layer of the MLP
3737

3838
# Generate 2D data (a large circle containing a smaller circle)
3939
inputs, targets = make_circles(n_samples=n_samples, noise=0.1, factor=0.3)

pytorch_tutorial/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ def plot_fashion_images(dataset, device, model=None):
173173
img, label = dataset[sample_idx]
174174
figure.add_subplot(rows, cols, i)
175175
plt.axis("off")
176-
plt.imshow(img.cpu().detach().numpy().squeeze(), cmap="gray")
176+
177+
# The color depth channel is removed to obtain a (H x W) tensor ready for plotting
178+
plt.imshow(img.squeeze(), cmap="binary")
177179

178180
# Title is either the true or predicted fashion item
179181
if model is None:

0 commit comments

Comments
 (0)