I am currently doing some experiment for my research. And I want to change the labeling of the MNIST data --- to have number 0 labeled as 1, and all the other numbers labeled as -1.
I found in the mnist.py file how the labels are extracted.
def extract_labels(f, one_hot=False, num_classes=10 ,zero=True):
print('Extracting', f.name)
with gzip.GzipFile(fileobj=f) as bytestream:
magic = _read32(bytestream)
if magic != 2049:
raise ValueError('Invalid magic number %d in MNIST
label file: %s' % (magic, f.name))
num_items = _read32(bytestream)
buf = bytestream.read(num_items)
labels = numpy.frombuffer(buf, dtype=numpy.uint8)
if zero:
labels[labels != 0] = -1
labels[labels == 0 ] = 1
if one_hot:
return dense_to_one_hot(labels, num_classes)
return labels
My modification is adding the if zero statement.
However, it says that
ValueError: assignment destination is read-only
Could anyone help with this?