Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outlier detection #120

Merged
merged 41 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
90dd432
Update GenerateAnnotationPatch with test cases from biigle/maia
mzur Dec 6, 2023
cc4cc99
Merge branch 'master' into sim-sort
mzur Dec 6, 2023
9e406a1
Implement trait to compute an annotation bounding box
mzur Dec 8, 2023
33ebbee
Add ExtractFeatures script from biigle/maia
mzur Dec 8, 2023
4c1addc
Implement feature vector models
mzur Dec 15, 2023
fb73480
Fix migration timestamp
mzur Dec 15, 2023
0896365
Implement GenerateFeatureVectors job
mzur Dec 20, 2023
27ce50c
Implement generating feature vectors in GenerateAnnotationPatch jobs
mzur Dec 20, 2023
c1df26f
Generate new feature vectors for all annotation labels instead of first
mzur Jan 4, 2024
bc57c1e
Implement annotation label observers to copy feature vectors
mzur Jan 4, 2024
e8ff0b5
Update/fix feature vector migration
mzur Jan 4, 2024
271d0dd
Copy feature vectors when a Largo job is applied
mzur Jan 4, 2024
f458f4b
Handle feature vector generation of whole frame annotations
mzur Jan 5, 2024
5098614
Add update schema action
mzur Jan 9, 2024
16b3328
WIP Start implementing sorting tab with sort by ID and outlier
mzur Jan 10, 2024
d55c42d
Implement outlier sorting UI for volume largo
mzur Jan 11, 2024
6960687
Fix default patch sorting direction
mzur Jan 11, 2024
a5b75b4
Implement project largo sort by outlier controller
mzur Jan 11, 2024
1715d01
Implement outlier sorting in project Largo UI
mzur Jan 12, 2024
3a44e20
Implement job to initialize feature vectors from thumbnails
mzur Jan 12, 2024
c216ba7
Simplify InitializeFeatureVectorChunk job
mzur Jan 15, 2024
09f5bc7
Implement command to initialize feature vectors from thumbnails
mzur Jan 15, 2024
9021480
WIP Implement updated feature vector initialization based on thumbnails
mzur Jan 17, 2024
567ff7e
WIP Transform GenerateAnnotationPatch to ProcessAnnotatedFile
mzur Jan 18, 2024
6e681de
Fix data returned by volume sort by outliers controller
mzur Jan 18, 2024
1f5f7d0
Implement missing features of ProcessAnnotationFile jobs
mzur Jan 18, 2024
e609f4a
Make code more reusable in biigle/maia
mzur Jan 19, 2024
f804ff8
Update Python requirements
mzur Jan 23, 2024
3fe453a
Merge branch 'sim-sort-thumbs' into sim-sort
mzur Jan 23, 2024
78c4957
Finish and test refined InitializeFeatureVectorChunk job
mzur Jan 23, 2024
40e2d7f
Update initialize feature vector command to process only one volume
mzur Jan 23, 2024
e0c9ade
Fix sorting in video volume
mzur Jan 23, 2024
a960cdb
Merge branch 'master' into sim-sort
mzur Jan 23, 2024
54fe650
Merge branch 'master' into sim-sort
mzur Jan 23, 2024
90a30a7
WIP Update GenerateMissing command
mzur Jan 23, 2024
5f54efc
Finish update of generate missing command with tests
mzur Jan 24, 2024
7bf82b8
Refactor generate missing command
mzur Jan 24, 2024
9012f5d
Implement checking for feature vectors in generate missing command
mzur Jan 24, 2024
6eade58
Update manual article with sorting instructions
mzur Jan 24, 2024
13ca366
Replace annotation label observers with event handler
mzur Jan 24, 2024
2343427
Update Pillow version
mzur Jan 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Implement command to initialize feature vectors from thumbnails
  • Loading branch information
mzur committed Jan 15, 2024
commit 09f5bc7fe5e272a7aa5cb5a718282832164aa6b2
76 changes: 76 additions & 0 deletions src/Console/Commands/InitializeFeatureVectors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Biigle\Modules\Largo\Console\Commands;

use Biigle\ImageAnnotation;
use Biigle\Modules\Largo\Jobs\InitializeFeatureVectorChunk;
use Biigle\VideoAnnotation;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Queue;

class InitializeFeatureVectors extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'largo:initialize-feature-vectors
{--dry-run : Do not submit jobs to generate feature vectors}
{--queue=default : Queue name to push jobs to generate feature vectors to}
{--chunk-size=1000 : Number of annotations to process in a single job}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate annotation feature vectors based on their annotation thumbnails.';

/**
* Execute the command.
*
* @return void
*/
public function handle()
{
$chunkSize = intval($this->option('chunk-size'));
$loopChunkSize = max($chunkSize, 10000);

$count = ImageAnnotation::count();
$this->info("Processing {$count} image annotations.");
$p = $this->output->createProgressBar($count);

ImageAnnotation::select('id')
->chunkById($loopChunkSize, function ($chunk) use ($p, $chunkSize) {
$chunk->chunk($chunkSize)->each(function ($c) use ($p) {
$job = new InitializeFeatureVectorChunk($c->pluck('id')->all(), []);
if (!$this->option('dry-run')) {
Queue::pushOn($this->option('queue'), $job);
}
$p->advance($c->count());
});
});

$p->finish();
$this->line('');

$count = VideoAnnotation::count();
$this->info("Processing {$count} video annotations.");
$p = $this->output->createProgressBar($count);

VideoAnnotation::select('id')
->chunkById($loopChunkSize, function ($chunk) use ($p, $chunkSize) {
$chunk->chunk($chunkSize)->each(function ($c) use ($p) {
$job = new InitializeFeatureVectorChunk([], $c->pluck('id')->all());
if (!$this->option('dry-run')) {
Queue::pushOn($this->option('queue'), $job);
}
$p->advance($c->count());
});
});

$p->finish();
$this->line('');
}
}
2 changes: 1 addition & 1 deletion src/Jobs/InitializeFeatureVectorChunk.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function getFeatureVectors(Collection $models, string $outputPath): \Gene
try {
$input = $models->mapWithKeys(function (Annotation $a) use ($disk, $rect, &$paths) {
$srcPath = GenerateAnnotationPatch::getTargetPath($a);
$tmpPath = tempnam(sys_get_temp_dir(), '').'.'.config('largo.patch_format');
$tmpPath = tempnam(sys_get_temp_dir(), '');

$thumbnail = $disk->get($srcPath);
if (is_null($thumbnail)) {
Expand Down
6 changes: 6 additions & 0 deletions src/LargoServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public function register()
return new \Biigle\Modules\Largo\Console\Commands\MigratePatchStorage;
});
$this->commands('command.largo.migrate-patch-storage');

$this->app->singleton('command.largo.initialize-feature-vectors', function ($app) {
return new \Biigle\Modules\Largo\Console\Commands\InitializeFeatureVectors;
});
$this->commands('command.largo.initialize-feature-vectors');
}

/**
Expand All @@ -116,6 +121,7 @@ public function provides()
'command.largo.config',
'command.largo.generate-missing',
'command.largo.migrate-patch-storage',
'command.largo.initialize-feature-vectors',
];
}
}