我在MATLAB中有一个AlexNet模型:
net = alexnet;layers = net.Layers;layers(end-2) = fullyConnectedLayer(numClasses);layers(end) = classificationLayer;
我使用它来从不同类别的视频帧序列中学习特征。因此,我需要从这个模型的’fc7’层中提取学习到的特征,将这些特征保存为一个向量,并传递给LSTM层。这个模型的迁移学习训练过程进行得很顺利,没有问题。
我使用splitEachLabel()在我的imageDatastore()中将数据集分为x_train和x_test集合,并使用augmentedImageSource()函数调整所有图像的大小以适应网络。一切正常!
但是,当我尝试使用下面的代码片段调整我的imageDatastore中的图像大小,以便通过activations()函数读取并将特征保存为向量时,我遇到了一个错误:
imageSize = [227 227 3];auimds = augmentedImageSource(imageSize, imds, 'ColorPreprocessing', 'gray2rgb');
activations函数:
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, ...
请有人帮帮我,谢谢支持!
回答:
你检查过那个层的输入大小了吗?你遇到的错误与当前层的输入大小有关。你能在Matlab的工作区中检查你的mynet结构及其fc7层的输入大小吗?