Reducing 3D to 2D in Neural Network Training
9 views (last 30 days)
Show older comments
I want to reduce 3-dimensional data to 2-dimensional in neural network training, not by using preprocessing, but by using a customized network in training, or a built-in network.Here is my customized layer, it doesn't achieve the result I want, I tried to reduce the dimension from 128x1xN to 128xN
classdef DownDimension < nnet.layer.Layer
% 自定義降維層,將 (S*S*C) 降為 (S*C)
methods
function layer = DownDimension(name)
% 層建構函式
layer.Name = name;
layer.Description = "Squeeze layer from (S*S*C) to (S*C)";
end
function Z = predict(layer, X)
% 前向傳播操作
% 假設 X 的尺寸為 (128, 1)
% 顯示 X 的原始尺寸
disp('Original size of X:');
disp(size(X));
% 如果需要轉換為 (128, 1, N)
Z = reshape(X, [size(X,1), 1, size(X,2)]);
% 顯示 Z 的新尺寸
disp('New size of Z after reshaping:');
disp(size(Z));
end
end
end
3 Comments
Answers (1)
Umang Pandey
on 5 Nov 2024 at 4:19
Edited: Umang Pandey
on 5 Nov 2024 at 4:19
Hi,
You can make use of the "squeeze" function to convert the matrix of dimension "128X1XN" to "128XN". The function simply removes the dimension of length 1. You can refer to the following MATLAB documentation for details on implementation and examples:
However, this function would remove the dimension of length 1, if you want to perform Dimensionality Reduction using some neural net which would preserve the data for some expected parameters while reducing dimensions, you can make use of some popular DR techniques like PCA (Principal Component Analysis), SOM (Self-Organizing Maps), etc. You can refer to the following MATLAB documentation for more information:
- Reduce dimensionality using PCA : https://www.mathworks.com/help/stats/reducedimensionalitytask.html
- SOM : https://www.mathworks.com/help/deeplearning/ref/selforgmap.html
Best,
Umang
0 Comments
See Also
Categories
Find more on Quantization, Projection, and Pruning in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!