% Load MNIST like words... % This code was found on several places on the internet and modified to % work with diffent types of Word sizes. % % Anders Hast % 2019-2021 % function images = loadMNISTwords(filename) fp = fopen(filename, 'rb'); assert(fp ~= -1, ['Could not open ', filename, '']); magic = fread(fp, 1, 'int32', 0, 'ieee-be'); try % 90x160 assert(magic == 14400, ['Bad magic number in ', filename, '']); catch MException % 90x320 try assert(magic == 24300, ['Bad magic number in ', filename, '']); catch MException assert(magic == 28800, ['Bad magic number in ', filename, '']); end end numImages = fread(fp, 1, 'int32', 0, 'ieee-be'); numRows = fread(fp, 1, 'int32', 0, 'ieee-be'); numCols = fread(fp, 1, 'int32', 0, 'ieee-be'); images = fread(fp, inf, 'unsigned char', 0, 'ieee-be'); fclose(fp); % Reshape to #pixels x #examples images=reshape(images,size(images,1)/(numImages), numImages); % Convert to double and rescale to [0,1] images = double(images) / 255; end