Unable to save trainingstats in MATLAB 2024a

20 Ansichten (letzte 30 Tage)
Vasu Sharma
Vasu Sharma am 14 Aug. 2024
Beantwortet: Aniket am 16 Aug. 2024
I am runnning a training script based on a simulink environment. At the end when I try to save the training results, it always throws an error. I am wondering if it has something to do with the .mat format. This issue does not occur in Matlab 2023a.
%% Train the agent
trainingStats = train(agent, env, trainOpts);
%% Save Agent
results_dir = strcat('./Results/',num2str(time(1)),'0',num2str(time(2)),num2str(time(3)));
mkdir(results_dir)
save(strcat(results_dir,'/TrainingStats.mat'),"trainingStats")
generatePolicyBlock(agent)
save_system('untitled','Agent')
%% Simulate
%addpath('D:\Masters\HiWi\Tikz')
simEpisodes = 1;
simOpts = rlSimulationOptions("MaxSteps",1250,...
"NumSimulations", simEpisodes);
experience = sim(env,agent,simOpts);
save(strcat(results_dir,'/Experience.mat'),"experience")
The error message is usually:
>> load('C:\Users\vasu3\Documents\Work\sharma_ma_rlonh2df\acados_implementation\rl\savedAgents\PPO\20240814\Agent5852.mat', 'savedAgentResult')
Error using load
Cannot read file
C:\Users\vasu3\Documents\Work\sharma_ma_rlonh2df\acados_implementation\rl\savedAgents\PPO\20240814\Agent5852.mat.
Warning: Directory already exists.
Error using save
Unable to save file
'C:\Users\vasu3\Documents\Work\sharma_ma_rlonh2df\acados_implementation\rl\Results\20240814\TrainingStats.mat'.
The file could not be closed, and might now be corrupt.
Error in run_H2DFRL_GRU (line 195)
save(strcat(results_dir,'/TrainingStats.mat'),"trainingStats")
Warning: Unable to read some of the variables due to unknown MAT-file error.
> In matfinfo (line 9)
In finfo>fetchDescriptions (line 278)
In finfo (line 82)
In uiimport/gatherFilePreviewData (line 419)
In uiimport (line 260)
Error using load
Unable to read file
'C:\Users\vasu3\Documents\Work\sharma_ma_rlonh2df\acados_implementation\rl\Results\20240814\TrainingStats.mat'. Input must be a
MAT-file or an ASCII file containing numeric data with same number of columns in each row.
Error in uiimport/runImportdata (line 470)
datastruct = load('-ascii', fileAbsolutePath);
Error in uiimport/gatherFilePreviewData (line 438)
[datastruct, textDelimiter, headerLines]= runImportdata(fileAbsolutePath, type);
Error in uiimport (line 260)
gatherFilePreviewData(fileAbsolutePath);
Could someone please help out

Akzeptierte Antwort

Aniket
Aniket am 16 Aug. 2024
I understand that there is an issue with saving training results in MATLAB, and it might be related to the file size limitations of the .mat format. The default version used for saving, version 7, has a size limit of 2GB per variable, which could be causing the error. You can switch to version 7.3 as it supports larger variable sizes.
Here's how you can modify the code to save the results using version 7.3:
save(strcat(results_dir, '/TrainingStats.mat'), "trainingStats", '-v7.3');
By specifying '-v7.3' in the save function, MATLAB is able to handle larger data sizes, which should help resolve this issue.
For more details, check out the MATLAB documentation on the ‘version’ argument of save function here:
Hope this helps!

Weitere Antworten (0)

Kategorien

Mehr zu Sequence and Numeric Feature Data Workflows finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by