summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
6bdea63)
Put each image into a column instead of a row, which works much better
with the standard formulation of backpropagation algorithms.
rows = struct.unpack('>I', f.read(4))[0]
cols = struct.unpack('>I', f.read(4))[0]
images = np.frombuffer(f.read(), dtype=np.uint8, count = num * rows * cols)
rows = struct.unpack('>I', f.read(4))[0]
cols = struct.unpack('>I', f.read(4))[0]
images = np.frombuffer(f.read(), dtype=np.uint8, count = num * rows * cols)
- # split them up into an array of flat image vectors, so that first axis corresponds to labels
- images = images.reshape(num, rows * cols)
+ # split them up into an array of flat image column vectors
+ images = images.reshape(num, rows * cols).T
with open(labels_file, 'rb') as f:
# validate magic
with open(labels_file, 'rb') as f:
# validate magic
# show the first bunch of training data
for i in range(10):
print(f'train image #{i}: label {train_labels[i]}')
# show the first bunch of training data
for i in range(10):
print(f'train image #{i}: label {train_labels[i]}')
- plt.imshow(train_images[i].reshape(rows, cols), cmap='gray')
+ plt.imshow(train_images[:, i].reshape(rows, cols), cmap='gray')