Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ The exact speedup you get depends on how much error you can tolerate--higher spe
## Installation
To run this script, you will need [PyTorch](http://pytorch.org) and a CUDA-capable GPU. If you wish to run it on CPU, just remove all the .cuda() calls.

Install ```path``` by
```sh
pip install path.py
```

## Running
Create a folder named ```logs``` by

```sh
mkdir logs
```

To run with default parameters, simply call

```sh
Expand Down
2 changes: 1 addition & 1 deletion densenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,5 +240,5 @@ def forward(self, x):
out = self.trans2(self.dense2(out))
out = self.dense3(out)
out = torch.squeeze(F.avg_pool2d(F.relu(self.bn1(out)), 8))
out = F.log_softmax(self.fc(out))
out = F.log_softmax(self.fc(out), dim=-1)
return out
18 changes: 9 additions & 9 deletions train.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.autograd import Variable as V
import torchvision.datasets as dset
import torchvision.transforms as transforms
from torch.utils.data import DataLoader
Expand Down Expand Up @@ -174,22 +173,23 @@ def train_test(depth, growth_rate, dropout, augment,
# y: target labels
def train_fn(x, y):
net.optim.zero_grad()
output = net(V(x.cuda()))
loss = F.nll_loss(output, V(y.cuda()))
output = net(x.cuda())
loss = F.nll_loss(output, y.cuda())
loss.backward()
net.optim.step()
return loss.data[0]
return loss.item()

# Testing function, returns test loss and test error for a batch
# x: input data
# y: target labels
def test_fn(x, y):
output = net(V(x.cuda(), volatile=True))
test_loss = F.nll_loss(output, V(y.cuda(), volatile=True)).data[0]
with torch.no_grad():
output = net(x.cuda())
test_loss = F.nll_loss(output, y.cuda()).item()

# Get the index of the max log-probability as the prediction.
pred = output.data.max(1)[1].cpu()
test_error = pred.ne(y).sum()
# Get the index of the max log-probability as the prediction.
pred = output.data.max(1)[1].cpu()
test_error = pred.ne(y).sum()

return test_loss, test_error

Expand Down
1 change: 0 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
Expand Down