dataset/MNIST.py
def extract_labels(filename, num_images, use_one_hot: bool = False):
    """Extract the labels into a vector of int64 label IDs."""
    print('Extracting', filename)
    with gzip.open(filename) as bytestream:
        bytestream.read(8)
        buf = bytestream.read(1 * num_images)
        labels = numpy.frombuffer(buf, dtype=numpy.uint8).astype(numpy.int64)
        one_hot_encoding = labels
        if use_one_hot:
            num_labels_data = len(labels)
            one_hot_encoding = numpy.zeros((num_labels_data, NUM_LABELS))
            one_hot_encoding[numpy.arange(num_labels_data), labels] = 1
            one_hot_encoding = numpy.reshape(one_hot_encoding, [-1, NUM_LABELS])
        else:
            one_hot_encoding = numpy.expand_dims(one_hot_encoding, -1)
    return one_hot_encoding
Extract the labels into a vector of int64 label IDs.
Extract the labels into a vector of int64 label IDs.
Extract the labels into a vector of int64 label IDs .
def extract_labels(filename, num_images, use_one_hot: bool = False):
    print('Extracting', filename)
    with gzip.open(filename) as bytestream:
        bytestream.read(8)
        buf = bytestream.read(1 * num_images)
        labels = numpy.frombuffer(buf, dtype=numpy.uint8).astype(numpy.int64)
        one_hot_encoding = labels
        if use_one_hot:
            num_labels_data = len(labels)
            one_hot_encoding = numpy.zeros((num_labels_data, NUM_LABELS))
            one_hot_encoding[numpy.arange(num_labels_data), labels] = 1
            one_hot_encoding = numpy.reshape(one_hot_encoding, [-1, NUM_LABELS])
        else:
            one_hot_encoding = numpy.expand_dims(one_hot_encoding, -1)
    return one_hot_encoding
def extract_labels ( filename , num_images , use_one_hot : bool = False ) : print ( 'Extracting' , filename ) with gzip . open ( filename ) as bytestream : bytestream . read ( 8 ) buf = bytestream . read ( 1 * num_images ) labels = numpy . frombuffer ( buf , dtype = numpy . uint8 ) . astype ( numpy . int64 ) one_hot_encoding = labels if use_one_hot : num_labels_data = len ( labels ) one_hot_encoding = numpy . zeros ( ( num_labels_data , NUM_LABELS ) ) one_hot_encoding [ numpy . arange ( num_labels_data ) , labels ] = 1 one_hot_encoding = numpy . reshape ( one_hot_encoding , [ - 1 , NUM_LABELS ] ) else : one_hot_encoding = numpy . expand_dims ( one_hot_encoding , - 1 ) return one_hot_encoding
Extract the labels into a vector of int64 label IDs.
Extract the labels into a vector of int64 label IDs .
"""Extract the labels into a vector of int64 label IDs."""
filename
num_images
use_one_hot
bool