Skip to content

Commit

Permalink
Dynamically set n_annos_per_canvas if user doesnt provide
Browse files Browse the repository at this point in the history
  • Loading branch information
TrevorBurgoyne committed Sep 20, 2024
1 parent dbfc797 commit bbb6069
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Nothing yet.
## [0.12.0] - ???
- Fix bug where `delete` modes and the `FilterDistance` toolbox item would clash.
- Expose `n_annos_per_canvas` arg to `config_data` as an advanced feature for performance tuning.
- Also added some dynamic scaling of this value based on the max number of annotations in a single subtask if no value is provided by the user.

## [0.11.0] - Sept 19th, 2024
- Fix bug where class counts wouldn't update when changing subtasks.
Expand Down
2 changes: 1 addition & 1 deletion dist/ulabel.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ulabel.min.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export enum AllowedToolboxItem {
Brush, // 9
}

export const DEFAULT_N_ANNOS_PER_CANVAS: number = 100;
export const TARGET_MAX_N_CANVASES_PER_SUBTASK: number = 8;

export class Configuration {
public toolbox_map = new Map<AllowedToolboxItem, any> ([
[AllowedToolboxItem.ModeSelect, ModeSelectionToolboxItem],
Expand Down Expand Up @@ -107,7 +110,7 @@ export class Configuration {

public decrease_brush_size_keybind: string = "["

public n_annos_per_canvas: number = 100;
public n_annos_per_canvas: number = DEFAULT_N_ANNOS_PER_CANVAS;

constructor(...kwargs: {[key: string]: unknown}[]) {
this.modify_config(...kwargs)
Expand Down
38 changes: 36 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import {
} from '../build/annotation';
import { ULabelSubtask } from '../build/subtask';
import { GeometricUtils } from '../build/geometric_utils';
import { Configuration, AllowedToolboxItem } from '../build/configuration';
import {
AllowedToolboxItem,
Configuration,
DEFAULT_N_ANNOS_PER_CANVAS,
TARGET_MAX_N_CANVASES_PER_SUBTASK,
} from '../build/configuration';
import { get_gradient } from '../build/drawing_utilities'
import {
filter_points_distance_from_line,
Expand All @@ -27,7 +32,7 @@ import {
build_confidence_dialog
} from '../build/html_builder';

import $, { unique } from 'jquery';
import $ from 'jquery';
const jQuery = $;
window.$ = window.jQuery = require('jquery');

Expand Down Expand Up @@ -846,6 +851,7 @@ export class ULabel {

static initialize_annotation_canvases(ul, subtask_key = null) {
if (subtask_key === null) {
ul.dynamically_set_n_annos_per_canvas();
for (const subtask_key in ul.subtasks) {
ULabel.initialize_annotation_canvases(ul, subtask_key)
}
Expand Down Expand Up @@ -1685,6 +1691,34 @@ export class ULabel {
}
}

/**
* If no user-provided n_annos_per_canvas is provided,
* Check if we should dynamically set it based on the number of annotations
* in the subtasks, to help with performance.
*
*/
dynamically_set_n_annos_per_canvas() {
// Check if we should increase n_annos_per_canvas
// First, check if the value is still the default
if (this.config.n_annos_per_canvas === DEFAULT_N_ANNOS_PER_CANVAS) {
// See if we should dynamically raise the default by checking max number of annotations in a subtask
let max_annos = 0;
for (const subtask_key in this.subtasks) {
const subtask = this.subtasks[subtask_key];
if (subtask.annotations.ordering.length > max_annos) {
max_annos = subtask.annotations.ordering.length;
}
}
// Performance starts to deteriorate when we require many canvases to be drawn on
// To be safe, check if max_annos / DEFAULT_N_ANNOS_PER_CANVAS is greater than TARGET_MAX_N_CANVASES_PER_SUBTASK
if (max_annos / DEFAULT_N_ANNOS_PER_CANVAS > TARGET_MAX_N_CANVASES_PER_SUBTASK) {
// If so, raise the default
this.config.n_annos_per_canvas = Math.ceil(max_annos / TARGET_MAX_N_CANVASES_PER_SUBTASK);
console.log("Dynamically setting n_annos_per_canvas to", this.config.n_annos_per_canvas);
}
}
}

/**
* Find the next available annotation context and return its ID.
* If all annotation contexts are in use, create a new canvas and return it's id.
Expand Down

0 comments on commit bbb6069

Please sign in to comment.