Skip to content

Commit

Permalink
Change cPickle import pattern in datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois Chollet authored and Francois Chollet committed Sep 3, 2015
1 parent 2c30d50 commit f84fe7c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions keras/datasets/cifar.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import sys
import six.moves.cPickle
from six.moves import cPickle
from six.moves import range

def load_batch(fpath, label_key='labels'):
f = open(fpath, 'rb')
if sys.version_info < (3,):
d = six.moves.cPickle.load(f)
d = cPickle.load(f)
else:
d = six.moves.cPickle.load(f, encoding="bytes")
d = cPickle.load(f, encoding="bytes")
# decode utf8
for k, v in d.items():
del(d[k])
Expand Down
4 changes: 2 additions & 2 deletions keras/datasets/imdb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import absolute_import
import six.moves.cPickle
import cPickle
import gzip
from .data_utils import get_file
import random
Expand All @@ -17,7 +17,7 @@ def load_data(path="imdb.pkl", nb_words=None, skip_top=0, maxlen=None, test_spli
else:
f = open(path, 'rb')

X, labels = six.moves.cPickle.load(f)
X, labels = cPickle.load(f)
f.close()

np.random.seed(seed)
Expand Down
6 changes: 3 additions & 3 deletions keras/datasets/mnist.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import gzip
from .data_utils import get_file
import six.moves.cPickle
from six.moves import cPickle
import sys


Expand All @@ -14,9 +14,9 @@ def load_data(path="mnist.pkl.gz"):
f = open(path, 'rb')

if sys.version_info < (3,):
data = six.moves.cPickle.load(f)
data = cPickle.load(f)
else:
data = six.moves.cPickle.load(f, encoding="bytes")
data = cPickle.load(f, encoding="bytes")

f.close()

Expand Down
10 changes: 5 additions & 5 deletions keras/datasets/reuters.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import string
import random
import os
import six.moves.cPickle
from six.moves import cPickle
from six.moves import zip
import numpy as np

Expand Down Expand Up @@ -78,8 +78,8 @@ def make_reuters_dataset(path=os.path.join('datasets', 'temp', 'reuters21578'),
dataset = (X, labels)
print('-')
print('Saving...')
six.moves.cPickle.dump(dataset, open(os.path.join('datasets', 'data', 'reuters.pkl'), 'w'))
six.moves.cPickle.dump(tokenizer.word_index, open(os.path.join('datasets', 'data', 'reuters_word_index.pkl'), 'w'))
cPickle.dump(dataset, open(os.path.join('datasets', 'data', 'reuters.pkl'), 'w'))
cPickle.dump(tokenizer.word_index, open(os.path.join('datasets', 'data', 'reuters_word_index.pkl'), 'w'))


def load_data(path="reuters.pkl", nb_words=None, skip_top=0, maxlen=None, test_split=0.2, seed=113,
Expand All @@ -88,7 +88,7 @@ def load_data(path="reuters.pkl", nb_words=None, skip_top=0, maxlen=None, test_s
path = get_file(path, origin="https://s3.amazonaws.com/text-datasets/reuters.pkl")
f = open(path, 'rb')

X, labels = six.moves.cPickle.load(f)
X, labels = cPickle.load(f)
f.close()

np.random.seed(seed)
Expand Down Expand Up @@ -140,7 +140,7 @@ def load_data(path="reuters.pkl", nb_words=None, skip_top=0, maxlen=None, test_s
def get_word_index(path="reuters_word_index.pkl"):
path = get_file(path, origin="https://s3.amazonaws.com/text-datasets/reuters_word_index.pkl")
f = open(path, 'rb')
return six.moves.cPickle.load(f)
return cPickle.load(f)


if __name__ == "__main__":
Expand Down

0 comments on commit f84fe7c

Please sign in to comment.