ImageSegmentation Optimization isn't reading my input Raster

8 views
Skip to first unread message

Brandon Van Huizen

unread,
Jan 6, 2025, 3:17:50 PMJan 6
to SegOptim user group
Hi there, 

I am trying to optimize my input parameters using the gaOptimizeSegmentationParams() with the segmentMethod set to "OTB_LSMS". However it fails after two iterations with the following error

Error in if(object@run >= run) break:
missing value where TRUE/FALSE needed
Error in gaOptimizeSegmentationParams(rstFeatures = rast("Rasters/Dinner/DIN_All_1m.tif")

It is also reporting -Inf for the "Best" output.

Here is the tool call

gaOptim <- gaOptimizeSegmentationParams(  rstFeatures =
rast("Rasters/Dinner/DIN_All_1m.tif"),
                                          trainData   = polyRst,
                                          # // Segmentation parameters ---
                                          segmentMethod = "OTB_LSMS",
                                          inputRstPath  =
"C:/ImageClassification/SegOutputs/DIN_All_Segm.tif",
                                          pythonPath    = "C:/OTB/OTB_720/bin",
                                          verbose = TRUE,
                                          # // End segmentation parameters ---
                                          trainThresh   = 0.5,
                                          segmStatsFuns = c("mean"),
                                          classificationMethod = "RF",
                                          classificationMethodParams = NULL,
                                          balanceTrainData = FALSE,
                                          balanceMethod = "ubOver",
                                          evalMethod = "10FCV",
                                          evalMetric = "Kappa",
                                          minTrainCases = 30,
                                          minCasesByClassTrain = 10,
                                          minCasesByClassTest = 10,
                                          minImgSegm = 30,
                                          lower = c(5,10,3),
                                          upper = c(12,60,40),
                                          popSize = 20,
                                          pcrossover = 0.8,
                                          pmutation = 0.2,
                                          maxiter = 100,
                                          run = 20,
                                          keepBest = TRUE,
                                          parallel = 2) # use two
cores for optimization (change to available resources)

João F Gonçalves

unread,
Jan 7, 2025, 12:22:53 PMJan 7
to segoptim-...@googlegroups.com

Hi Brandon,

(sorry for the slow reply)

Can you run the optimization without the parallel option and put here the messages issued by R? Does the optimization process reach the classification stage (after doing the image segmentation step)?

Also if you can manage to generate a reproducible example to test this it would be really helpful. Send me a dm with this if you prefer.


Cheers

João

- - -

20:17 - 06/01/2025, Brandon Van Huizen:
--
You received this message because you are subscribed to the Google Groups "SegOptim user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to segoptim-user-g...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/segoptim-user-group/8429c0fe-95a4-4e2e-be4c-81eac67a95d6n%40googlegroups.com.

Brandon Van Huizen

unread,
Jan 7, 2025, 4:54:24 PMJan 7
to João F Gonçalves, segoptim-...@googlegroups.com
Hi João,

No worries, the output I got when I set the parallel option to false
is below. I will DM you an example that you can test it on as well

Thanks,
Brandon

-> Performing OBIA segmentation with method OTB_LSMS ...
Error in segmentation_OTB_LSMS(...) :
unused argument (pythonPath = FALSE)
In addition: Warning message:
In (function (x, rstFeatures, trainData, segmentMethod, ...,
trainThresh = 0.5, :
An error occurred while trying to perform the selected segmentation algorithm!
> To view this discussion visit https://groups.google.com/d/msgid/segoptim-user-group/26eb4010-d64d-47f5-ad4a-4b82d5e89b13%40gmail.com.

João Gonçalves

unread,
Jan 10, 2025, 1:06:55 PMJan 10
to SegOptim user group
Hi Brandon,

Seems like a simple issue. Replace:

pythonPath    = "C:/OTB/OTB_720/bin" # by

otbBinPath    = "C:/OTB/OTB_720/bin"

Because "OTB_LSMS" is being optimized you have to use the parameters of its specific segmentation function, in this case:
segmentation_OTB_LSMS()

This means that you can also modify parameters such as:

tilesizex = 2500, # Size of tiles along the X-axis (integer).
tilesizey = 2500, # Size of tiles along the Y-axis (integer).or
RAM = 3072 # allocated RAM
which are specific to this segmentation function (but beware of these values when running in parallel to not exceed the resources of your machine)

Try it without parallelization and let me know how it goes.

Cheers
João
Reply all
Reply to author
Forward
0 new messages