Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 40bcdb5

Browse files
Merge pull request MorvanZhou#55 from keineahnung2345/401-cnn
[Bug fix] 401_CNN.py
2 parents 0f4219c + a9ef65e commit 40bcdb5

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎tutorial-contents/401_CNN.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(self):
6565
out_channels=16, # n_filters
6666
kernel_size=5, # filter size
6767
stride=1, # filter movement/step
68-
padding=2, # if want same width and length of this image after con2d, padding=(kernel_size-1)/2 if stride=1
68+
padding=2, # if want same width and length of this image after Conv2d, padding=(kernel_size-1)/2 if stride=1
6969
), # output shape (16, 28, 28)
7070
nn.ReLU(), # activation
7171
nn.MaxPool2d(kernel_size=2), # choose max value in 2x2 area, output shape (16, 14, 14)
@@ -115,7 +115,7 @@ def plot_with_labels(lowDWeights, labels):
115115

116116
if step % 50 == 0:
117117
test_output, last_layer = cnn(test_x)
118-
pred_y = torch.max(test_output, 1)[1].data.squeeze().numpy()
118+
pred_y = torch.max(test_output, 1)[1].data.numpy()
119119
accuracy = float((pred_y == test_y.data.numpy()).astype(int).sum()) / float(test_y.size(0))
120120
print('Epoch: ', epoch, '| train loss: %.4f' % loss.data.numpy(), '| test accuracy: %.2f' % accuracy)
121121
if HAS_SK:
@@ -129,6 +129,6 @@ def plot_with_labels(lowDWeights, labels):
129129

130130
# print 10 predictions from test data
131131
test_output, _ = cnn(test_x[:10])
132-
pred_y = torch.max(test_output, 1)[1].data.numpy().squeeze()
132+
pred_y = torch.max(test_output, 1)[1].data.numpy()
133133
print(pred_y, 'prediction number')
134134
print(test_y[:10].numpy(), 'real number')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /