what is problem in ResNet50 Code, Error: Check for incorrect argument data type or missing argument in call to function 'activations'. line 30

1 view (last 30 days)
% Set the path to the folder containing the image files
folder_path = 'C:\Reseaarch\ChestX-rayDataset\Data\train\COVID19';
% Get a list of all the image files in the folder
file_list = dir(fullfile(folder_path, '*.jpg'));
% Load the ResNet model
net = resnet50('Weights','none');
% Create an empty matrix to store the features
num_images = numel(file_list);
features = zeros(num_images, 2048);
% Loop through each image file and extract its features
for i = 1:num_images
% Load the image
img = imread(fullfile(folder_path, file_list(i).name));
% Convert the image to RGB format
img = cat(3, img, img, img);
% Resize the image to match the input size of the ResNet model
img = imresize(img, [224 224]);
% Preprocess the image
img = resnet50_preprocess(img);
% Extract features using the ResNet model
layer = 'fc1000';
features(i,:) = squeeze(double(activations(net, img, layer, 'OutputAs', 'rows')));
end
function img = resnet50_preprocess(img)
% Normalize the pixel values of the image to the range [-1, 1]
img = im2double(img);
img = (img - 0.5) * 2;
% Subtract the mean RGB values of the ImageNet dataset from the image
mean_rgb = [123.68 116.779 103.939];
img(:,:,1) = img(:,:,1) - mean_rgb(1);
img(:,:,2) = img(:,:,2) - mean_rgb(2);
img(:,:,3) = img(:,:,3) - mean_rgb(3);
end
%Check for incorrect argument data type or missing argument in call to function 'activations'. Error in resnet (line 30)
%features(i,:) = squeeze(double(activations(net, img, layer, 'OutputAs', 'rows')));

Answers (1)

Prasanna
Prasanna on 10 Dec 2024
Hi Muhammad,
The error “Check for incorrect argument data type or missing argument in call to function activations” you are encountering suggests that there is an issue with the arguments passed to the activations function.
To solve the error, you should load a pre-trained network and send it as an argument to the ‘activations’ function. Ensure that the network is correctly loaded with pre-trained weights. The resnet50 function should load a pre-trained network by default. If you specify “('Weights','none')” it will not load pre-trained weights, which might cause issues. To load a pre-trained ‘resnet50’ network, you can use “net = resnet50” which loads a pre-trained network. These corrections should resolve the issue with the activations function. For more information regarding the functions and their corresponding parameters, refer to the following documentations:
Hope this helps!

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!