-
Notifications
You must be signed in to change notification settings - Fork 45
:chore: Extract explanations from prediction queries #650
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
base: main
Are you sure you want to change the base?
Conversation
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.
Pull Request Overview
This PR refactors how explanation data is fetched by extracting it into its own React Query hook and updating relevant components, providers, interfaces, and tests to consume the new useExplanationsQuery
hook instead of bundling explanations with prediction results.
- Introduce a standalone
useExplanationsQuery
hook and add anEXPLANATIONS
key toquery-keys
. - Remove inline explanation fetching from prediction hooks and providers, wiring in the new explanations query.
- Update components (
TestDetailsPreview
,TrainingDatasetDetailsPreview
,SelectedMediaItemProvider
,PredictionProvider
,AnnotatorProvider
) and tests to useexplanationsQuery
and adjust interfaces.
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
use-test-results-query.hook.ts | Split out explanations query and updated predictionsQuery to only return annotations |
test-details-preview.component.tsx | Added explanationsQuery and updated explanations source |
training-dataset-details-preview.component.tsx | Introduced useExplanationsQuery and replaced old maps usage |
use-predictions-query.hook.ts | Removed inline explanation logic and returned only annotations |
use-explanation-query.hook.ts | New hook to fetch explanations separately |
selected-media-item.interface.ts | Extended interface to include optional explanations |
selected-media-item-provider.component.tsx | Aggregated explanations into selected item and context value |
default-selected-media-item-provider.component.tsx | Added stub for explanationsQuery in default provider |
use-prediction-roi-query.hook.ts | Removed explanations from ROI query, now only returns annotations |
use-prediction-roi-query.hook.test.tsx | Updated tests to reflect removed maps field |
prediction-provider.component.tsx | Removed setExplanations call in prediction success handler |
use-initial-annotations.hook.test.tsx | Adapted tests to new predictions-only shape and added explanations |
annotator-provider.component.tsx | Wired in explanationsQuery data instead of old maps |
layers-factory.test.tsx | Added explanationsQuery stub in test context |
query-keys.ts | Added EXPLANATIONS key for query caching |
Comments suppressed due to low confidence (1)
web_ui/src/pages/annotator/providers/selected-media-item-provider/use-explanation-query.hook.ts:1
- [nitpick] Consider renaming this file from
use-explanation-query.hook.ts
touse-explanations-query.hook.ts
so the filename matches theuseExplanationsQuery
hook and follows the plural naming convention of other query hooks.
// Copyright (C) 2022-2025 Intel Corporation
...or/providers/selected-media-item-provider/default-selected-media-item-provider.component.tsx
Show resolved
Hide resolved
web_ui/src/pages/annotator/providers/prediction-provider/prediction-provider.component.tsx
Show resolved
Hide resolved
4ad36cb
to
a838fc0
Compare
image: getMockedImage(), | ||
annotations, | ||
predictions: { annotations: predictions, maps: [] }, | ||
predictions: { annotations: predictions }, |
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.
i think on a different PR we can also simplify this interface.
|
||
// If we are at task chain's second task, get prediction for the selected ROI input | ||
const predictionsRoiQuery = usePredictionsRoiQuery({ | ||
selectedInput, |
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.
Regarding this file: I think we can refactor this provider so that we no longer need to keep track of the explanations inside of it. Instead it should be possible to retrieve the explanations directly from a query result.
selectedMediaItemQuery, | ||
setSelectedMediaItem: noop, | ||
predictionsQuery: { isLoading: false } as UseQueryResult<PredictionResult>, | ||
explanationsQuery: { isLoading: false } as UseQueryResult<ExplanationResult>, |
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.
Is it possible to completely remove this and instead use the query directly?
}); | ||
|
||
const predictionsQuery = usePredictionsQueryBasedOnAnnotatorMode(mediaItem); | ||
const explanationsQuery = useExplanationsQuery({ |
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.
Similar question/comment as above: I'd prefer if we can fully remove it from this provider.
The logic in here is already a bit too complex with trying to make a dependant query based on three other queries, adding one more could result in some more subtle bugs.
queryFn: async ({ signal }) => { | ||
if (!mediaItem) throw new Error("Can't fetch undefined media item"); | ||
|
||
try { |
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.
Suggestion for later: we can remove this try catch and rely on the actual query's error after we remove it from our selected media item provider: If we use the query directly in the annotator's toolbar and canvas then we can deal with its error handling locally and inform the user that we weren't able to retrieve explanation maps.
EXPLANATIONS: ( | ||
datasetIdentifier: DatasetIdentifier, | ||
mediaIdentifier: MediaIdentifier | undefined, | ||
taskId?: string |
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.
Should this also depend on the roi
? Iirc when we are in task chain we request the explanation map based on a given ROI.
userAnnotationScene={userAnnotationScene} | ||
initPredictions={initialPredictionAnnotations} | ||
explanations={selectedMediaItem?.predictions?.maps || EMPTY_EXPLANATION} | ||
explanations={selectedMediaItem?.explanations || EMPTY_EXPLANATION} |
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.
Let's try to
explanations={selectedMediaItem?.explanations || EMPTY_EXPLANATION} | |
explanations={explanationQuery.data?.explanations || EMPTY_EXPLANATION} | |
// or | |
explanationsQuery={explanationsQuery} |
where we can define the query inside of this function or possibly remove the argument and use this query directly inside of the prediction provider.
📝 Description
usePredictionQuery
andusePredictionROIQuery
)Follow up:
usePredictionQuery
withusePredictionROIQuery
✨ Type of Change
Select the type of change your PR introduces:
🧪 Testing Scenarios
Describe how the changes were tested and how reviewers can test them too:
✅ Checklist
Before submitting the PR, ensure the following: