(dirname="cifar-100-python", one_hot=False)
| 17 | |
| 18 | |
| 19 | def load_data(dirname="cifar-100-python", one_hot=False): |
| 20 | tarpath = maybe_download("cifar-100-python.tar.gz", |
| 21 | "http://www.cs.toronto.edu/~kriz/", |
| 22 | dirname) |
| 23 | X_train = [] |
| 24 | Y_train = [] |
| 25 | |
| 26 | for i in ["train"]: |
| 27 | fpath = os.path.join(dirname, i) |
| 28 | data, labels = load_batch(fpath) |
| 29 | if i == "train": |
| 30 | X_train = data |
| 31 | Y_train = labels |
| 32 | else: |
| 33 | X_train = np.concatenate([X_train, data], axis=0) |
| 34 | Y_train = np.concatenate([Y_train, labels], axis=0) |
| 35 | |
| 36 | fpath = os.path.join(dirname, 'test') |
| 37 | X_test, Y_test = load_batch(fpath) |
| 38 | |
| 39 | X_train = np.dstack((X_train[:, :1024], X_train[:, 1024:2048], |
| 40 | X_train[:, 2048:])) / 255. |
| 41 | X_train = np.reshape(X_train, [-1, 32, 32, 3]) |
| 42 | X_test = np.dstack((X_test[:, :1024], X_test[:, 1024:2048], |
| 43 | X_test[:, 2048:])) / 255. |
| 44 | X_test = np.reshape(X_test, [-1, 32, 32, 3]) |
| 45 | |
| 46 | if one_hot: |
| 47 | Y_train = to_categorical(Y_train, 100) |
| 48 | Y_test = to_categorical(Y_test, 100) |
| 49 | |
| 50 | return (X_train, Y_train), (X_test, Y_test) |
| 51 | |
| 52 | |
| 53 | def load_batch(fpath): |
nothing calls this directly
no test coverage detected
searching dependent graphs…