print the shape of fully connected layer input and the shape of the output also in matlab

To print the shape of fully connected layer input and output in Matlab, you can use the size() function. The input shape is determined by the number of input features or nodes, and the output shape is determined by the number of output nodes. Here's an example code block:

main.m
% Create a fully connected layer with 10 input nodes and 5 output nodes
inputSize = 10;
outputSize = 5;
fcLayer = fullyConnectedLayer(outputSize);

% Define an input matrix of size [batchSize, inputSize]
batchSize = 1;
inputMatrix = rand(batchSize, inputSize);

% Pass the input matrix through the fully connected layer
outputMatrix = fcLayer.predict(inputMatrix);

% Print the shape of the input and output matrices
disp(['Input shape: ' num2str(size(inputMatrix))]);
disp(['Output shape: ' num2str(size(outputMatrix))]);
523 chars
16 lines

This code creates a fully connected layer with 10 input nodes and 5 output nodes using the fullyConnectedLayer function in Matlab's Neural Network Toolbox. It then defines an input matrix of size [batchSize, inputSize], where batchSize is set to 1 for simplicity. The input matrix is passed through the fully connected layer using the predict function, which produces an output matrix with size [batchSize, outputSize]. Finally, the code uses disp and num2str functions to print the shape of the input and output matrices to the command window.

gistlibby LogSnag