Skip to content

Commit

Permalink
Update GenerateAnnotationFeatureVectors job
Browse files Browse the repository at this point in the history
  • Loading branch information
mzur committed Dec 20, 2023
1 parent adf6aa3 commit 4a26329
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/Jobs/GenerateAnnotationFeatureVectors.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ public function handle()
->get()
->all();

$inputPath = tempnam(sys_get_temp_dir(), 'maia_feature_vector_input');
$outputPath = tempnam(sys_get_temp_dir(), 'maia_feature_vector_output');

try {
FileCache::batch($images, function ($images, $paths) use ($annotations, $outputPath) {
FileCache::batch($images, function ($images, $paths) use ($annotations, $inputPath, $outputPath) {
$annotations = $annotations->groupBy('image_id');
$input = $this->generateInput($images, $paths, $annotations);
if (!empty($input)) {
$this->python($input, $outputPath);
File::put($inputPath, json_encode($input));
$this->python($inputPath, $outputPath);
}
});

Expand All @@ -81,6 +84,7 @@ public function handle()
$this->insertFeatureVectorModelChunk($insert);
} finally {
File::delete($outputPath);
File::delete($inputPath);
}
}

Expand Down
8 changes: 4 additions & 4 deletions tests/Jobs/GenerateAnnotationFeatureVectorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ class GenerateProposalFeatureVectorsStub extends GenerateTrainingProposalFeature
public $outputPath;
public $output = [];

protected function python(array $input, string $outputPath)
protected function python(string $inputPath, string $outputPath)
{
$this->input = $input;
$this->input = json_decode(File::get($inputPath), true);
$this->outputPath = $outputPath;
$csv = implode("\n", array_map(fn ($row) => implode(',', $row), $this->output));
File::put($outputPath, $csv);
Expand All @@ -426,9 +426,9 @@ class GenerateCandidateFeatureVectorsStub extends GenerateAnnotationCandidateFea
public $outputPath;
public $output = [];

protected function python(array $input, string $outputPath)
protected function python(string $inputPath, string $outputPath)
{
$this->input = $input;
$this->input = json_decode(File::get($inputPath), true);
$this->outputPath = $outputPath;
$csv = implode("\n", array_map(fn ($row) => implode(',', $row), $this->output));
File::put($outputPath, $csv);
Expand Down

0 comments on commit 4a26329

Please sign in to comment.