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

Choose mag when training models on multiple annotations #8266

Merged
merged 25 commits into from
Jan 7, 2025
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9c61a80
very much WIP: add form item to select mag per annotation
knollengewaechs Dec 6, 2024
6305026
pass mags to form
knollengewaechs Dec 9, 2024
19a1666
pass mags through to parent form
knollengewaechs Dec 9, 2024
f90cacc
Merge branch 'master' into multi-anno-trainings-choose-mag
knollengewaechs Dec 12, 2024
5d3151f
remove default value
knollengewaechs Dec 12, 2024
b7ce334
WIP: clear mag selection when new layer is selected
knollengewaechs Dec 12, 2024
5fc98f0
WIP: update mags
knollengewaechs Dec 13, 2024
9011674
select intersection of data and segmentation layer mags
knollengewaechs Dec 16, 2024
48876d9
load mags if both layers are already selected
knollengewaechs Dec 16, 2024
7fdf1e1
adjust line height for non required fields
knollengewaechs Dec 16, 2024
da1ba84
Merge branch 'master' into multi-anno-trainings-choose-mag
knollengewaechs Dec 16, 2024
0dea8e5
add changelog
knollengewaechs Dec 16, 2024
3f4bcaf
remove dev edits
knollengewaechs Dec 16, 2024
420f648
WIP: address review
knollengewaechs Dec 20, 2024
3da8f49
WIP: add Form.useWatch to update value whenever form changes
knollengewaechs Dec 20, 2024
88581c6
fix multi mag form
knollengewaechs Dec 20, 2024
0f83dba
use useRef for watcherFunction to get the current annotation infos
knollengewaechs Dec 23, 2024
0e692b4
Merge branch 'master' into multi-anno-trainings-choose-mag
knollengewaechs Dec 23, 2024
6325828
add await to async method
knollengewaechs Jan 3, 2025
0aee521
WIP: render volume annotation layer names more nicely in layer selection
knollengewaechs Jan 3, 2025
78af65e
fix that tracing ids were shown (and sent to worker) even though huma…
philippotto Jan 6, 2025
feb8a45
remove application.conf edit
knollengewaechs Jan 6, 2025
0ca90f2
merge master
knollengewaechs Jan 6, 2025
e12ab6f
lint
knollengewaechs Jan 6, 2025
76b1fa6
Merge branch 'master' into multi-anno-trainings-choose-mag
knollengewaechs Jan 7, 2025
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
53 changes: 25 additions & 28 deletions frontend/javascripts/oxalis/view/jobs/train_ai_model.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useRef, useState } from "react";
import {
Alert,
Form,
Expand Down Expand Up @@ -180,7 +180,10 @@ export function TrainAiModelTab<GenericAnnotation extends APIAnnotation | Hybrid
}) {
const [form] = Form.useForm();

const magInfoPerLayer: Array<MagInfo> = Form.useWatch(() => {
const watcherFunctionRef = useRef(() => {
return [new MagInfo([])];
});
watcherFunctionRef.current = () => {
const getIntersectingMags = (idx: number, annotationId: string, dataset: APIDataset) => {
const segmentationLayerName = form.getFieldValue(["trainingAnnotations", idx, "layerName"]);
const imageDataLayerName = form.getFieldValue(["trainingAnnotations", idx, "imageDataLayer"]);
Expand All @@ -192,15 +195,15 @@ export function TrainAiModelTab<GenericAnnotation extends APIAnnotation | Hybrid
return new MagInfo([]);
};

const annotationInfos = form.getFieldValue("trainingAnnotations");
if (annotationInfos == null) {
return [];
}
return annotationInfos.map((_: TrainingAnnotation, idx: number) => {
const annotation = annotationInfos[idx].annotation;
return annotationInfos.map((annotationInfo, idx: number) => {
const annotation = annotationInfo.annotation;
const annotationId = "id" in annotation ? annotation.id : annotation.annotationId;
return getIntersectingMags(idx, annotationId, annotationInfos[idx].dataset);
return getIntersectingMags(idx, annotationId, annotationInfo.dataset);
});
};

const magInfoForLayer: Array<MagInfo> = Form.useWatch(() => {
return watcherFunctionRef.current();
}, form);

const [useCustomWorkflow, setUseCustomWorkflow] = React.useState(false);
Expand Down Expand Up @@ -228,18 +231,16 @@ export function TrainAiModelTab<GenericAnnotation extends APIAnnotation | Hybrid
return colorLayer != null ? getMagInfo(colorLayer.resolutions).getMagList() : null;
};

const getTrainingAnnotations = async (values: any) => {
return Promise.all(
values.trainingAnnotations.map(async (trainingAnnotation: TrainingAnnotation) => {
const { annotationId, imageDataLayer, layerName, mag } = trainingAnnotation;
return {
annotationId,
colorLayerName: imageDataLayer,
segmentationLayerName: layerName,
mag,
};
}),
);
const getTrainingAnnotations = (values: any) => {
return values.trainingAnnotations.map((trainingAnnotation: TrainingAnnotation) => {
const { annotationId, imageDataLayer, layerName, mag } = trainingAnnotation;
return {
annotationId,
colorLayerName: imageDataLayer,
segmentationLayerName: layerName,
mag,
};
});
};

const onFinish = async (form: FormInstance<any>, useCustomWorkflow: boolean, values: any) => {
Expand All @@ -250,8 +251,8 @@ export function TrainAiModelTab<GenericAnnotation extends APIAnnotation | Hybrid
await ensureSavedState();
}

await runTraining({
trainingAnnotations: await getTrainingAnnotations(values),
philippotto marked this conversation as resolved.
Show resolved Hide resolved
runTraining({
trainingAnnotations: getTrainingAnnotations(values),
name: values.modelName,
aiModelCategory: values.modelCategory,
workflowYaml: useCustomWorkflow ? values.workflowYaml : undefined,
Expand Down Expand Up @@ -393,11 +394,7 @@ export function TrainAiModelTab<GenericAnnotation extends APIAnnotation | Hybrid
<Col span={6}>
<MagSelectionFormItem
name={["trainingAnnotations", idx, "mag"]}
magInfo={
magInfoPerLayer != null && magInfoPerLayer[idx] != null
? magInfoPerLayer[idx]
: new MagInfo([])
}
magInfo={magInfoForLayer != null ? magInfoForLayer[idx] : new MagInfo([])}
/>
</Col>
</Row>
Expand Down