我称之为对 MNIST 图像进行分类的简单 CNN。CNN 内部调用 loadMNISTImages() 函数从文件中读取图像。当这个 CNN 连接到我的 simulink 模型时。
我收到以下错误:
对于代码生成,您不能使用 'machineformat' 输入参数。函数 'loadMNISTImages.m' (#77.233.262),第 8 行,第 9 列:“fread(fp, 1, 'int32', 0, 'b')" 启动诊断报告。
这是读取 MNIST 图像的函数:
function images = loadMNISTImages(filename)
%loadMNISTImages returns a 28x28x[number of MNIST images] matrix
%containing the raw MNIST images
fp = fopen(filename, 'rb');
assert(fp ~= -1, ['Could not open ', filename, '']);
magic = fread(fp, 1, 'int32', 0, 'b');
assert(magic == 2051, ['Bad magic number in ', filename, '']);
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=>unsigned char');
images = reshape(images, numCols, numRows, numImages);
images = permute(images,[2 1 3]);
fclose(fp);
% Reshape to #pixels x #examples
images = reshape(images, size(images, 1) * size(images, 2), size(images, 3));
% Convert to double and rescale to [0,1]
images = double(images) / 255;
end
上面的函数是从函数 TestMNISTCONV 调用的
function y2 = TestMnistConv()
Images =
loadMNISTImages('C:\Users\surinder\Downloads\experiments\cnn\MNIST\t10k-images.idx3-ubyte');
Images = reshape(Images, 28, 28, []);
Labels =
loadMNISTLabels('C:\Users\surinder\Downloads\experiments\cnn\MNIST\t10k-
labels.idx1-ubyte');
Labels(Labels == 0) = 10; % 0 --> 10
最后,我从 Stateflow 图中的状态调用此函数,因此出现此错误。请问有人可以帮忙吗?:)