function inspect_dlnetwork(matFile)

    fprintf('=== Loading MAT file ===\n');
    S = load(matFile);
    vars = fieldnames(S);
    disp(vars)

    % Find dlnetwork variable
    net = [];
    for i = 1:numel(vars)
        if isa(S.(vars{i}), 'dlnetwork')
            net = S.(vars{i});
            fprintf('Found dlnetwork: %s\n', vars{i});
            break;
        end
    end

    if isempty(net)
        error('No dlnetwork object found in MAT file.');
    end

    fprintf('\n=== BASIC INFO ===\n');
    disp(net)

    % -------- INPUT INFO --------
    fprintf('\n=== INPUT INFO ===\n');
    disp('InputNames:')
    disp(net.InputNames)

    fprintf('Number of inputs: %d\n', numel(net.InputNames));

    % -------- LAYER INFO --------
    fprintf('\n=== INPUT LAYER DETAILS ===\n');
    lgraph = layerGraph(net);

    for i = 1:numel(net.InputNames)
        lgraph = layerGraph(net);
layers = lgraph.Layers;

for i = 1:numel(net.InputNames)
    inputName = net.InputNames{i};

    % Find matching layer by name
    idx = find(arrayfun(@(L) strcmp(L.Name, inputName), layers));

    if isempty(idx)
        fprintf('Could not find input layer for %s\n', inputName);
        continue;
    end

    layer = layers(idx);

    fprintf('\n--- Input Layer %d ---\n', i);
    fprintf('Name: %s\n', layer.Name);
    fprintf('Type: %s\n', class(layer));

    if isprop(layer,'InputSize')
        fprintf('InputSize: ');
        disp(layer.InputSize)
    end
end

        fprintf('\n--- Input Layer %d ---\n', i);
        fprintf('Name: %s\n', layer.Name);
        fprintf('Type: %s\n', class(layer));

        if isprop(layer,'InputSize')
            fprintf('InputSize: ');
            disp(layer.InputSize)
        end

        if isprop(layer,'MinLength')
            fprintf('MinLength: %d\n', layer.MinLength);
        end
    end

    % -------- TEST INPUT PROBE --------
    fprintf('\n=== AUTO PROBE ===\n');

    try
        % Try common formats
        testSizes = {
            [1 1 4096 1], 'SSCB';
            [4096 1 1],   'SCB';
            [1 4096 1],   'SCB'
        };

        for i = 1:size(testSizes,1)
            sz = testSizes{i,1};
            fmt = testSizes{i,2};

            fprintf('\nTrying size %s with format %s\n', mat2str(sz), fmt);

            Xtest = rand(sz,'single');
            dlX = dlarray(Xtest, fmt);

            try
                Y = forward(net, dlX);
                fprintf('✅ SUCCESS\n');
                disp(size(extractdata(Y)))
            catch ME
                fprintf('❌ FAILED: %s\n', ME.message);
            end
        end

    catch ME
        fprintf('Probe failed: %s\n', ME.message);
    end

    fprintf('\n=== INSPECTION COMPLETE ===\n');

end