TrainImagesClassifier itk Error - can't open csv when saving model

Hello !

While using the TrainImagesClassifier algorithm, I get the following (fatal) error : “TrainImagesClassifier: itk::ERROR: SamplingRateCalculator(000001FB06101D50): Couldn’t open C:\Users\Yay\Desktop\tmp2\model2012-rf.txt_rates_1.csv”. I’m using windows 10.

I get this error with command prompt and otbcli_TrainImagesClassifier with OTB-7.2.0 but also with two different versions of QGIS (3.14 and 2.14) for the graphical tool, using OTB-7.2.0 or 6.6.1. Admin command prompt doesn’t help, neither changing from random forest classifier to libsvm, neither changing the model extention to .txt, .file,.model,etc.
Interesting fact : whith QGIS, it only appends when saving the model to a file and not using a temporary output. Maybe some right to create a temporary file in this folder is not good ?

With this intall I already got this working with other data some time ago.
Any idea of the problem/solution ? Thanks !

Here is the full output of the command with parameters :
C:\OTB-7.2.0-Win64\bin>otbcli_TrainImagesClassifier C:\Users\Yay\Desktop\tmp2\20120819_ortho_10m.tif -io.vd C:\Users\Yay\Desktop\tmp2\train_classes.shp -io.out C:\Users\Yay\Desktop\tmp2\model2012-rf.txt -sample.vtr 0.7 -sample.vfn class -ram 4000 -classifier rf
2020-11-05 10:49:27 (INFO) TrainImagesClassifier: Default RAM limit for OTB is 256 MB
2020-11-05 10:49:27 (INFO) TrainImagesClassifier: GDAL maximum cache size is 403 MB
2020-11-05 10:49:27 (INFO) TrainImagesClassifier: OTB will use at most 4 threads
2020-11-05 10:49:27 (INFO) TrainImagesClassifier: Polygon analysis…
2020-11-05 10:49:27 (INFO) TrainImagesClassifier: Elevation management: setting default height above ellipsoid to 0 meters
2020-11-05 10:49:27 (INFO): Estimated memory for full processing: 25.2037MB (avail.: 4000 MB), optimal image partitioning: 1 blocks
2020-11-05 10:49:27 (INFO): Estimation will be performed in 1 blocks of 1625x2036 pixels
Analyze polygons…: 100% [**************************************************] (0s)
2020-11-05 10:49:27 (INFO) TrainImagesClassifier: Sampling rates…
2020-11-05 10:49:27 (INFO) TrainImagesClassifier: Sampling strategy : fit the number of samples based on the smallest class
2020-11-05 10:49:27 (INFO) TrainImagesClassifier: Sampling rates for image 1 : className requiredSamples totalSamples rate
1 7874 16855 0.467161
2 7874 7874 1

2020-11-05 10:49:28 (FATAL) TrainImagesClassifier: itk::ERROR: SamplingRateCalculator(000001FB06101D50): Couldn’t open C:\Users\Yay\Desktop\tmp2\model2012-rf.txt_rates_1.csv

[Update] Hey, I if can give some idea to someone :
I have noticed the same problem with TrainImages for saving output tif, so it’s really a permission issue I guess, and not a model/csv problem. But I still don’t know any solution, and the answer to a few others that got this issue didn’t helped. Here is the error message :

2020-11-08 17:22:30 (FATAL) ImageClassifier: itk::ERROR: GDALImageIO(000001DCA1A60390): Attempt to create new tiff file `C:/Users/Yay/Desktop/tmp2/tmptest.tif’ failed: Permission denied



Have you tried with other applications ? Or does this problem only occurs when using other applications ?

Have you checked the permissions of C:/Users/Yay/Desktop/tmp2 ?


Hi, thanks for your answer.
Saving a cache raster to a .tif in the folder works well, saving a docx from Word also, etc.
And it can’t creates .csv but “model.txt_stats_1.xml” yep.
I checked permissions yes. I noticed that it works in “C:\Users\Yay”, and the security set up is the same : admin/system/Yay in full control, inheritance disabled.


I meant another OTB application, like otbcli_EdgeExtraction.bat -in input.tif -out C:/Users/Yay/Desktop/tmp2/out.tif.

I’m trying to understand if the problem comes from the TrainImagesClassifier application specifically, or from OTB in general.


Hello Cédric,

Oh right, so in addition to ImageClassifier (2nd message), EdgeExtraction doesn’t work either, I also get “permission denied”.
However : core GQIS, GDAL and GRASS raster info tools works fine, SAGA histogram surface also (some other tools no but it seems there is another problem).

I can’t set .bat to run with admin right like .exe in properties. But I launched the graphical version otbgui_EdgeExtraction.bat as admin and it worked, while not working with usual rights
So I guess I have to grant admin rights to all my otbcli_[…].bat ? It seems not easy and I tried through an admin shortcut of the .bat without success. But unless you think of something else I guess it is not an OTB problem anymore…

Gdalwarp neither can save here. And just QGIS basic “Export > Save as” doesn’t always work (I had to try twice), at least for some rasters in cache.
Maybe my whole install is broken but more or less “asymptomatic” (that’s the year).


That’s probably a little bit overkill, but a full clean new install of windows 10 solved the whole thing!
Thanks Cédric for participating :wink:

1 Like