update samples from Release-74 as a part of 1.25.0 SDK stable release

This commit is contained in:
amlrelsa-ms
2021-03-24 14:42:54 +00:00
parent 54a065c698
commit 6a26f250f2
45 changed files with 2970 additions and 1419 deletions

View File

@@ -0,0 +1,24 @@
import gzip
import numpy as np
import struct
# load compressed MNIST gz files and return numpy arrays
def load_data(filename, label=False):
with gzip.open(filename) as gz:
struct.unpack("I", gz.read(4))
n_items = struct.unpack(">I", gz.read(4))
if not label:
n_rows = struct.unpack(">I", gz.read(4))[0]
n_cols = struct.unpack(">I", gz.read(4))[0]
res = np.frombuffer(gz.read(n_items[0] * n_rows * n_cols), dtype=np.uint8)
res = res.reshape(n_items[0], n_rows * n_cols)
else:
res = np.frombuffer(gz.read(n_items[0]), dtype=np.uint8)
res = res.reshape(n_items[0], 1)
return res
# one-hot encode a 1-D array
def one_hot_encode(array, num_of_classes):
return np.eye(num_of_classes)[array.reshape(-1)]