Batch.h¶
Go to the source code of this file.
Batch inspection is a feature that processes multiple images at once.
ExampleClsRuntimeBatch.cpp shows how to perform batch inspection. Batch inspection in SAIGE VISION is a feature that processes multiple images at once. This uses more GPU memory. Also, processing more images at once does not always make it faster. Therefore, it is necessary to select an appropriate Batch Size.
Batch Inspection Steps¶
To perform batch inspection, follow these steps:
- Set the Batch Size when creating a handle
- Load multiple image data into memory
- Call the Batch Infer API SaigeInferFromMultipleByteArray
- Retrieve and utilize the inspection results for each image from each result handle
Setting the Batch Size¶
Set the SaigeHandleConfig::batchSize value and create a handle by specifying the flag.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |
Load Images¶
In this example, all .png files under the specified dataDir path are read and stored in imagePaths. Then, the application code bundles and processes these images according to batchSize. That is, in this example, batchSize >= numOfImages.
The following code is the beginning of the loop that inspects the entire image list divided by batchSize. Load the image corresponding to each iteration into ucBatchImageData.
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
Call the Batch Infer API¶
Call the Batch Infer API, SaigeInferFromMultipleByteArray function.
285 286 287 288 289 290 291 292 293 | |
Retrieve Inspection Results¶
After calling the Batch Infer API, retrieve the inspection results for each image from each result handle. Therefore, the number of result handles must be at least numOfImages.
298 299 300 301 302 303 304 305 306 307 308 309 310 | |
Relationship between Batch Size and numOfImages¶
The Batch Size set and the actual number of images input to the SaigeInferFromMultipleByteArray function do not have to match.
The Batch Size is the number of images processed simultaneously on the GPU.
Therefore, if the number of images input to the Batch Infer API, numOfImages, is greater than the Batch Size, the operation is divided into multiple operations. Also, if the number of input images is less than the Batch Size, GPU resources are wasted. Therefore, the Batch Size is an important tuning factor that should be set carefully.
That is, the number of input images, numOfImages, can be set differently depending on the characteristics of the application. For example, there are cases where multiple images are collected and processed at once, and cases where the inspection results are needed as soon as
Generally, to increase the throughput of the inspection, it is recommended to set the batchSize as large as possible. Conversely, if the latency of the inspection is important, it is recommended to call the inspection API as soon as possible without waiting for the inspection images to be collected.