我对MatCaffe有意见。我成功地在python中使用我自己的数据集(2种分类,0或1)训练了LeNet,并且现在尝试在Matlab上部署它。Net体系结构来自caffe/examples/mnist/lenet.prototxt。所有输入到网络中的图像总是返回1 (我尝试使用训练中的正负图像)。
下面是我的代码:
deployNet = 'lenet_deploy.prototxt';
caffeModel = 'weight.caffemodel';
caffe.set_mode_cpu();
net = caffe.Net(deployNet, caffeModel, 'test');
net.blobs('data').reshape([28 28 1 1]);
net.reshape();
patch_data = imread('cropped.jpg'); % already in greyscale
patch_data = imresize(patch_data, [28 28],'bilinear');
imshow(patch_data)
input_data = {patch_data};
scores = net.forward(input_data);
highest = max(scores{1});
disp(i);
disp(highest);最高的总是返回1,即使是负面的图像。我试着在python上部署它,它工作得很好。我在猜测我处理输入的方式有问题。
发布于 2017-05-10 23:19:58
发现了问题。我忘了用训练尺度来增加图像的宽度和高度,因为Matlab是1索引和列大的,通常Matlab中的4个blob维度是宽度、高度、通道、数字和宽度是最快的维度。因此,只需再加2行代码:
deployNet = 'lenet_deploy.prototxt';
caffeModel = 'weight.caffemodel';
caffe.set_mode_cpu();
net = caffe.Net(deployNet, caffeModel, 'test');
net.blobs('data').reshape([28 28 1 1]);
net.reshape();
patch = imread('cropped.jpg'); % already in greyscale
patch = single(patch) * 0.00390625; % multiply with scale
patch = permute(patch, [2,1,3]); %permute width and height
input_data = {patch};
scores = net.forward(input_data);
highest = scores{1};https://stackoverflow.com/questions/43623482
复制相似问题