@@ -30,9 +30,9 @@ class Net(nn.Container):
30
30
def __init__ (self ):
31
31
super (Net , self ).__init__ (
32
32
conv1 = nn .Conv2d (1 , 20 , 5 , 5 ),
33
- pool1 = nn .MaxPooling2d (2 , 2 ),
33
+ pool1 = nn .MaxPool2d (2 , 2 ),
34
34
conv2 = nn .Conv2d (20 , 50 , 5 , 5 ),
35
- pool2 = nn .MaxPooling2d (2 , 2 ),
35
+ pool2 = nn .MaxPool2d (2 , 2 ),
36
36
fc1 = nn .Linear (800 , 500 ),
37
37
fc2 = nn .Linear (500 , 10 ),
38
38
relu = nn .ReLU (),
@@ -73,14 +73,15 @@ def train(epoch):
73
73
74
74
def test (epoch ):
75
75
test_loss = 0
76
- batch_data = Variable (torch .cuda .FloatTensor (TEST_BATCH_SIZE , 1 , 28 , 28 ), requires_grad = False )
77
- batch_targets = Variable (torch .cuda .FloatTensor (TEST_BATCH_SIZE ), requires_grad = False )
76
+ batch_data = Variable (torch .cuda .FloatTensor (TEST_BATCH_SIZE , 1 , 28 , 28 ), volatile = True )
77
+ batch_targets = Variable (torch .cuda .FloatTensor (TEST_BATCH_SIZE ), volatile = True )
78
78
for i in range (0 , test_data .size (0 ), TEST_BATCH_SIZE ):
79
79
print ('Testing model: {}/{}' .format (i , test_data .size (0 )), end = '\r ' )
80
80
batch_data .data [:] = test_data [i :i + TEST_BATCH_SIZE ]
81
81
batch_targets .data [:] = test_labels [i :i + TEST_BATCH_SIZE ]
82
- test_loss += criterion (model (batch_data ), batch_targets ). data [ 0 ]
82
+ test_loss += criterion (model (batch_data ), batch_targets )
83
83
84
+ test_loss = test_loss .data [0 ]
84
85
test_loss /= (test_data .size (0 ) / TEST_BATCH_SIZE ) # criterion averages over batch size
85
86
print ('TEST SET RESULTS:' + ' ' * 20 )
86
87
print ('Average loss: {:.4f}' .format (test_loss ))
0 commit comments