Filter löschen
Filter löschen

I am trying to find deep learned features at fc7 layer of alexnet

4 Ansichten (letzte 30 Tage)
I am trying to find deep learned features at fc7 layer of alexnet using the below code:
close all;
clear all;
clc;
run './matconvnet/matlab/vl_setupnn'
% Load pre-trained AlexNet
net = alexnet;
% Load an example image
im = imread('01.jpg');
% Resize the image to the input size of AlexNet
im = imresize(im, [227 227]);
% Preprocess the image for AlexNet
im = im2single(im);
%im = im - net.meta.normalization.averageImage;
for j=1:3
im(:,:,j) = im(:,:,j) - net.meta.normalization.averageImage(j);
end
% Extract features at fc7 layer
features = activations(net, im, 'fc7');
% Display the extracted features
disp(features);
I am getting this error:
Unrecognized method, property, or field 'meta' for class 'SeriesNetwork'.
Error in alexnet_fc7 (line 19)
im(:,:,j) = im(:,:,j) - net.meta.normalization.averageImage(j);

Akzeptierte Antwort

Himanshu
Himanshu am 27 Mär. 2023
Hello Aditya,
As per my understanding, you are facing an error while extracting the features from the "fc7" Fully Connected Layer of the AlexNet Convolutional Neural Network.
The error occurs because you are trying to access the "meta" field of the "net" object, which doesn't exist in the "SeriesNetwork" class.
As per the provided code, I understand that you want to normalize the input data by subtracting the mean of the dataset images. You can perform the operation by replacing the "for" loop with the following code:
average_image = mean(net.Layers(1).Mean(1,:), 2)
im = bsxfun(@minus, im, average_image)
Here, it first calculates the average image value using the "Mean" property of the first layer and then subtracts it from the input image.
You can refer to the below documentation to understand more about the "AlexNet", "SeriesNetwork" and "bsxfun" function.
  1 Kommentar
Aditya
Aditya am 30 Mär. 2023
Thanks a lot Himanshu, This method is working and I am getting the output for the same.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by