clear;clc;close all
unzip('MerchData.zip');
net=darknet19;
imds = imageDatastore('MerchData','IncludeSubfolders',true,'LabelSource','foldernames');
augImds=augmentedImageDatastore(net.Layers(1, 1).InputSize(1:2),imds);
idx=randperm(numel(imds.Files),20);
imgEx=readByIndex(augImds,idx);
figure;montage(imgEx.input);title('example of the dataset')
Labels=imds.Labels;
numClass=numel(countcats(Labels));
feature=squeeze(activations(net,augImds,'avg1'));
figure;
A=pca(feature,"Centered",true);
subplot(1,2,1)
gscatter(A(:,1),A(:,2),Labels)
subplot(1,2,2)
T=tsne(feature');
gscatter(T(:,1),T(:,2),Labels)
C=kmeans(feature',numClass,"Start","plus");
[~,Frequency] = mode(C);
sz=net.Layers(1, 1).InputSize(1:2);
I=zeros(sz(1)*numClass,sz(2)*Frequency,3,'uint8');
for i=1:numClass
ithGroup=readByIndex(augImds,find(C==i));
I((i-1)*sz(1)+1:i*sz(1),1:sz(2)*numel(find(C==i)),:)=cat(2,ithGroup.input{:});
end
figure;imshow(I);title('result of the image clustering using k-means after feature extraction with darknet19')
4 Comments
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/599281-#comment_1023118
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/599281-#comment_1023118
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/599281-#comment_1023145
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/599281-#comment_1023145
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/599281-#comment_1023157
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/599281-#comment_1023157
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/599281-#comment_1023178
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/599281-#comment_1023178
Sign in to comment.