Skip to content

Commit

Permalink
python 2.7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
soumith committed Aug 24, 2016
1 parent 23933fc commit 3de8643
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
16 changes: 11 additions & 5 deletions mnist/data.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import os
import torch
import json
import errno
import codecs
from tqdm import tqdm

if not os.path.exists('data/raw/train-images-idx3-ubyte'):
try:
os.makedirs(os.path.join('data', 'raw'))
os.makedirs(os.path.join('data', 'processed'))
except FileExistsError:
pass
import urllib.request
except OSError as e:
if e.errno == errno.EEXIST:
pass
else:
raise
from six.moves import urllib
import gzip
urls = [
'http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz',
Expand All @@ -30,7 +35,7 @@
os.unlink(file_path)

def get_int(b):
return int.from_bytes(b, 'big')
return int(codecs.encode(b, 'hex'), 16)

def read_label_file(path):
with open(path, 'rb') as f:
Expand Down Expand Up @@ -60,7 +65,8 @@ def read_image_file(path):
row.append(data[idx])
idx += 1
assert len(images) == length
return torch.FloatTensor(images)
out = torch.FloatTensor(images)
return out

print("Loading training set")
training_set = (
Expand Down
1 change: 1 addition & 0 deletions mnist/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import torch
import torch.nn as nn
import torch.nn.cuda
Expand Down
3 changes: 3 additions & 0 deletions mnist/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
torch
tqdm
six

0 comments on commit 3de8643

Please sign in to comment.