Suppress a warning message from importNetworkFromPyTorch function.

14 Ansichten (letzte 30 Tage)
SHC
SHC am 13 Apr. 2025 um 4:13
Beantwortet: Manikanta Aditya am 13 Apr. 2025 um 4:23
Hello,
When I use importNetworkFromPyTorch() function to import a Torch neural network to MATLAB, the function always prints a warning message as below:
Warning: Network was imported as an uninitialized dlnetwork. Before using the network, initialize it with formatted dlarray(s):
% Create sample data for the network input at index 1:
dlX1 = dlarray(<dataArray1>, <missingFormat>);
% Initialize the network with formatted data:
net = initialize(net, dlX1);
I know that I need to initialize the imported network before using it, so I do not want to see the warning every time when I use the function.
However, I could not find any options in the function to suppress the printing.
Is there a way to suppress the printing?

Akzeptierte Antwort

Manikanta Aditya
Manikanta Aditya am 13 Apr. 2025 um 4:23
Hi @SHC,
You can suppress specific warning messages in MATLAB by using the warning function with the appropriate message identifier. Here's how you can do it:
  • After the warning is issued, you can use the lastwarn function to get the identifier:
[~, MSGID] = lastwarn();
  • Use the warning function with the identifier to turn off the specific warning:
warning('off', MSGID);
  • For your specific case, you can add these lines after importing the network to suppress the warning:
importNetworkFromPyTorch(...); % Your import function
[~, MSGID] = lastwarn();
warning('off', MSGID);
Refer to the following documentations:
I hope this helps.

Weitere Antworten (0)

Kategorien

Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange

Produkte


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by