Jun-13-2020, 04:24 PM
Hello,
I am biginning coding with python and I have 2 errors I could not solve alone :
I have imported files (like MNIST\\train-images-idx3-ubyte.gz), and I try to unpack the file with the code :
May you help me !
Thanks
Roro noa
I am biginning coding with python and I have 2 errors I could not solve alone :
I have imported files (like MNIST\\train-images-idx3-ubyte.gz), and I try to unpack the file with the code :
import numpy as np
import gzip
import struct
def load_images(filename):
# Open and unzip the file of images :
with gzip.open(filename, 'rb') as f:
# read the header, information into a bunch of variables:
_ignored, n_images, image_columns, image_rows = struct.unpack('>IIII', bytearray)
# read all the pixels into a long numpy array :
all_pixels = np.frombuffer(f.read(), dtype=np.uint8)
# reshape the array into a matrix where each line is an image:
images_matrix = all_pixels.reshape(n_images, image_columns * image_rows)
# Add a bias column full of 1 as the first column in the matrix
return np.insert(images_matrix, 0, 1, axis=1)
# 60000 images, each 785 elements (1 bias + 28x28 pixels)
X_train = load_images("\\MNIST\\train-images-idx3-ubyte.gz")
X_train = load_images("\\MNIST\\t10k-images-idx3-ubyte.gz")but it returns me these errors :Error:Traceback (most recent call last):
File "recognition.py", line 23, in <module>
X_train = load_images("\\MNIST\\train-images-idx3-ubyte.gz")
File "recognition.py", line 13, in load_images
_ignored, n_images, image_columns, image_rows = struct.unpack('>IIII', bytearray)
TypeError: a bytes-like object is required, not 'type'I have tried to look at google and else, but no way to find an answer (I have just started used Python 10 days ago !).May you help me !
Thanks
Roro noa
