-
Notifications
You must be signed in to change notification settings - Fork 29
Add option to train AI using Tasks and their bounding boxes #8310
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
Changes from 1 commit
293c98f
d45ea84
a271981
675d369
bc2b55b
1c44bf0
0a5a046
f63afb8
a329a16
8ab7b3e
b9e0946
52a80ef
c37fe7f
d526816
d53eb2a
aafd50b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -47,6 +47,7 @@ import { computeArrayFromBoundingBox } from "libs/utils"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { MagSelectionFormItem } from "components/mag_selection"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { MagInfo } from "oxalis/model/helpers/mag_info"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { V3 } from "libs/mjs"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { getAnnotationsForTask } from "admin/api/tasks"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { TextArea } = Input; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const FormItem = Form.Item; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -55,10 +56,12 @@ const FormItem = Form.Item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// only the APIAnnotations of the given annotations to train on are loaded from the backend. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Thus, the code needs to handle both HybridTracing | APIAnnotation where APIAnnotation is missing some information. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Therefore, volumeTracings with the matching volumeTracingMags are needed to get more details on each volume annotation layer and its magnifications. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// The userBoundingBoxes are needed for checking for equal bounding box sizes. As training on fallback data is supported and an annotation is not required to have VolumeTracings, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// As the userBoundingBoxes should have multiple sizes of the smallest one, a check with a warning should be included. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// As training on fallback data is supported and an annotation is not required to have VolumeTracings, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// it is necessary to save userBoundingBoxes separately and not load them from volumeTracings entries to support skeleton only annotations. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// Moreover, in case an annotations is a task, its task bounding box should also be used for training. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
// Moreover, in case an annotations is a task, its task bounding box should also be used for training. | |
// Moreover, in case an annotation is a task, its task bounding box should also be used for training. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve error handling in task validation.
The catch block silently swallows all errors to determine if the input is a task. This could hide real API errors or other issues.
Consider this improvement:
- try {
- const annotations = await getAnnotationsForTask(taskOrAnnotationIdOrUrl);
- const finishedAnnotations = annotations.filter(({ state }) => state === "Finished");
- if (annotations.length > 0) {
- annotationIdsForTraining.push(...finishedAnnotations.map(({ id }) => id));
- } else {
- unfinishedTasks.push(taskOrAnnotationIdOrUrl);
- }
- } catch (_e) {
- isTask = false;
- }
+ try {
+ const annotations = await getAnnotationsForTask(taskOrAnnotationIdOrUrl);
+ const finishedAnnotations = annotations.filter(({ state }) => state === "Finished");
+ if (annotations.length > 0) {
+ annotationIdsForTraining.push(...finishedAnnotations.map(({ id }) => id));
+ } else {
+ unfinishedTasks.push(taskOrAnnotationIdOrUrl);
+ }
+ } catch (error) {
+ if (error.response?.status === 404) {
+ isTask = false;
+ } else {
+ throw new Error(`Failed to fetch task ${taskOrAnnotationIdOrUrl}: ${error.message}`);
+ }
+ }
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
let isTask = true; | |
try { | |
const annotations = await getAnnotationsForTask(taskOrAnnotationIdOrUrl); | |
const finishedAnnotations = annotations.filter(({ state }) => state === "Finished"); | |
if (annotations.length > 0) { | |
annotationIdsForTraining.push(...finishedAnnotations.map(({ id }) => id)); | |
} else { | |
unfinishedTasks.push(taskOrAnnotationIdOrUrl); | |
} | |
} catch (_e) { | |
isTask = false; | |
} | |
let isTask = true; | |
try { | |
const annotations = await getAnnotationsForTask(taskOrAnnotationIdOrUrl); | |
const finishedAnnotations = annotations.filter(({ state }) => state === "Finished"); | |
if (annotations.length > 0) { | |
annotationIdsForTraining.push(...finishedAnnotations.map(({ id }) => id)); | |
} else { | |
unfinishedTasks.push(taskOrAnnotationIdOrUrl); | |
} | |
} catch (error) { | |
if (error.response?.status === 404) { | |
isTask = false; | |
} else { | |
throw new Error(`Failed to fetch task ${taskOrAnnotationIdOrUrl}: ${error.message}`); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.