class ObjectDetection extends DetectionJob

Traits

Queueable

Properties

protected bool $deleteWhenMissingModels

Ignore this job if the MAIA job does not exist any more.

from  DetectionJob
protected string $tmpDir

Temporary directory for files of this job.

from  DetectionJob
protected array $trainingProposals

Selected training proposals.

protected string $knowledgeTransferVolumeUrl

URL of the volume for knowledge transfer (if any).

protected array $knowledgeTransferImages

Filenames of the images of the knowledge transfer volume, indexed by their IDs.

Methods

__construct(MaiaJob $job)

Create a new instance

void
failed(Exception $exception)

The job failed to process.

array
getGenericImages()

Create GenericImage instances for the images of this job.

cleanup()

Clean up temporary data produced by this job.

dispatchFailure(Exception $e)

Dispatch the job to notify the BIIGLE instance of a failure.

createTmpDir()

Create the temporary directory for this request.

ensureDirectory(string $path)

Creates the specified directory if it does not exist.

string
getTmpDirPath()

Get the path to the temporary directory.

string
python(string $command, string $log = 'log.txt')

Execute a Python command and return the path to a file containing the output.

array
parseAnnotations(array $images)

Parse the output JSON files to get the array of annotations for each image.

array
parseAnnotationsFile(GenericImage $image)

Parse the output JSON file of a single image.

createMaiaAnnotations(array $annotations)

Create MAIA annotations from the training proposals.

array
createMaiaAnnotation(array $annotation)

Create an insert array for a MAIA annotation.

insertAnnotationChunk(array $chunk)

Insert one chunk of the MAIA annotations that should be created into the database.

updateJobState()

Update the state of the MAIA job after processing the response.

handle()

Execute the job

bool
shouldUseKnowledgeTransfer()

Determine whether knowledge transfer should be performed in this job.

array
bundleTrainingProposals(MaiaJob $job)

Bundle the training proposals to be sent to the GPU server.

string
generateDataset(array $images, array $paths)

Generate the training dataset for the object detection model.

string
createDatasetJson(array $imagesMap, string $outputJsonPath)

Create the JSON file that is the input to the dataset generation script.

string
performTraining(string $datasetOutputPath)

Perform training of object detection model.

maybeDownloadWeights(string $from, string $to)

Downloads the model pretrained weights if they weren't downloaded yet.

string
createTrainingJson(string $outputJsonPath)

Create the JSON file that is the input to the training script.

performInference(array $images, string $datasetOutputPath, string $trainingOutputPath)

Perform inference with the trained object detection model.

string
createInferenceJson(array $imagesMap)

Create the JSON file that is the input to the inference script.

array
buildImagesMap(array $images, array $paths)

Build the map from image ID to path of the cached image file.

dispatchResponse(array $annotations)

Dispatch the job to store the object detection results.

array
getKnowledgeTransferImages()

Create GenericImage instances for the images of the knowledge transfer volume.

Details

at line 46
__construct(MaiaJob $job)

Create a new instance

Parameters

MaiaJob $job

in DetectionJob at line 49
void failed(Exception $exception)

The job failed to process.

Parameters

Exception $exception

Return Value

void

in DetectionJob at line 61
protected array getGenericImages()

Create GenericImage instances for the images of this job.

Return Value

array

in DetectionJob at line 77
protected cleanup()

Clean up temporary data produced by this job.

at line 323
protected dispatchFailure(Exception $e)

Dispatch the job to notify the BIIGLE instance of a failure.

Parameters

Exception $e

in DetectionJob at line 92
protected createTmpDir()

Create the temporary directory for this request.

in DetectionJob at line 107
protected ensureDirectory(string $path)

Creates the specified directory if it does not exist.

Parameters

string $path

at line 331
protected string getTmpDirPath()

Get the path to the temporary directory.

Return Value

string

in DetectionJob at line 133
protected string python(string $command, string $log = 'log.txt')

Execute a Python command and return the path to a file containing the output.

Parameters

string $command
string $log

Name of the log file to write any output to.

Return Value

string

Exceptions

Exception

in DetectionJob at line 157
protected array parseAnnotations(array $images)

Parse the output JSON files to get the array of annotations for each image.

Parameters

array $images

GenericImage instances.

Return Value

array

in DetectionJob at line 189
protected array parseAnnotationsFile(GenericImage $image)

Parse the output JSON file of a single image.

Parameters

GenericImage $image

Return Value

array

in DetectionJob at line 214
protected createMaiaAnnotations(array $annotations)

Create MAIA annotations from the training proposals.

Parameters

array $annotations

in DetectionJob at line 236
protected array createMaiaAnnotation(array $annotation)

Create an insert array for a MAIA annotation.

Parameters

array $annotation

Return Value

array

at line 354
protected insertAnnotationChunk(array $chunk)

Insert one chunk of the MAIA annotations that should be created into the database.

Parameters

array $chunk

at line 362
protected updateJobState()

Update the state of the MAIA job after processing the response.

at line 66
handle()

Execute the job

at line 110
protected bool shouldUseKnowledgeTransfer()

Determine whether knowledge transfer should be performed in this job.

Return Value

bool

at line 122
protected array bundleTrainingProposals(MaiaJob $job)

Bundle the training proposals to be sent to the GPU server.

Parameters

MaiaJob $job

Return Value

array

at line 151
protected string generateDataset(array $images, array $paths)

Generate the training dataset for the object detection model.

Parameters

array $images

GenericImage instances.

array $paths

Paths to the cached image files.

Return Value

string

Path to the JSON output file.

at line 171
protected string createDatasetJson(array $imagesMap, string $outputJsonPath)

Create the JSON file that is the input to the dataset generation script.

Parameters

array $imagesMap

Map from image IDs to cached file paths.

string $outputJsonPath

Path to the output file of the script.

Return Value

string

Input JSON file path.

at line 198
protected string performTraining(string $datasetOutputPath)

Perform training of object detection model.

Parameters

string $datasetOutputPath

Path to the JSON output of the dataset generator.

Return Value

string

Path to the JSON output file of the training script.

at line 217
protected maybeDownloadWeights(string $from, string $to)

Downloads the model pretrained weights if they weren't downloaded yet.

Parameters

string $from
string $to

at line 236
protected string createTrainingJson(string $outputJsonPath)

Create the JSON file that is the input to the training script.

Parameters

string $outputJsonPath

Path to the output file of the script.

Return Value

string

Input JSON file path.

at line 261
protected performInference(array $images, string $datasetOutputPath, string $trainingOutputPath)

Perform inference with the trained object detection model.

Parameters

array $images

GenericImage instances.

string $datasetOutputPath

Path to the JSON output of the dataset generator.

string $trainingOutputPath

Path to the JSON output of the training script.

at line 278
protected string createInferenceJson(array $imagesMap)

Create the JSON file that is the input to the inference script.

Parameters

array $imagesMap

Map from image IDs to cached file paths.

Return Value

string

Input JSON file path.

at line 300
protected array buildImagesMap(array $images, array $paths)

Build the map from image ID to path of the cached image file.

Parameters

array $images

GenericImage instances.

array $paths

Cached image file paths.

Return Value

array

at line 315
protected dispatchResponse(array $annotations)

Dispatch the job to store the object detection results.

Parameters

array $annotations

at line 341
protected array getKnowledgeTransferImages()

Create GenericImage instances for the images of the knowledge transfer volume.

Return Value

array