在MATLAB中从AlexNet fc7层中提取特征

时间:2018-04-06 16:58:20

标签: matlab machine-learning deep-learning feature-extraction

我在MATLAB中有这个AlexNet模型:

net = alexnet;
layers = net.Layers;
layers(end-2) = fullyConnectedLayer(numClasses);
layers(end) = classificationLayer;

我正在使用它来学习来自不同课程视频的帧序列的功能。所以我需要从这个模型的'fc7'层提取学习的特征,将这些特征保存为矢量并将其传递给LSTM层。 转移学习这个模型的训练过程没问题,好吧。

我在imageDatastore()中使用splitEachLabel()将数据集划分为x_train和x_test集合,并使用函数augmentedImageSource()调整网络的所有图像大小。一切都好!

但是,当我尝试你使用这个代码片段来调整我的imageDatastore中的图像以通过函数activations()来重新调整时,为了将这些功能保存为矢量,我收到了一个错误:

imageSize = [227 227 3];
auimds = augmentedImageSource(imageSize, imds, 'ColorPreprocessing', 'gray2rgb');

功能激活:

layer = 'fc7';
fclayer = activations(mynet, auimds, layer,'OutputAs','columns');

错误:

Error using SeriesNetwork>iDataDispatcher (line 1113)
For an image input layer, the input data for predict must be a single image, a 4D array of images, or an imageDatastore with the correct size.

Error in SeriesNetwork/activations (line 791)
            dispatcher = iDataDispatcher( X, miniBatchSize, precision, ...

有人帮帮我,拜托! 感谢您的支持!

1 个答案:

答案 0 :(得分:0)

您是否检查过该图层的输入尺寸?您获得的错误与当前图层的输入大小有关。你能在Matlab中检查你的mynet结构及其fc7层输入的大小吗?

相关问题