필터 지우기
필터 지우기

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

조회 수: 4 (최근 30일)
Aditya
Aditya 2023년 3월 16일
댓글: Aditya 2023년 3월 30일
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);

채택된 답변

Himanshu
Himanshu 2023년 3월 27일
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
Aditya
Aditya 2023년 3월 30일
Thanks a lot Himanshu, This method is working and I am getting the output for the same.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by