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

Panoptic segmentation #4926

Draft
wants to merge 28 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2344fd8
add functionality for panoptic segmentations
Sep 16, 2024
93739f3
changes suggested by CodeRabbit
Sep 21, 2024
8c8427c
Merge pull request #4829 from kemaleren/panoptic_segmentation
benjaminpkane Oct 4, 2024
cf39921
Merge branch 'develop' into panoptic-segmentation
benjaminpkane Oct 4, 2024
0c6a494
Merge branch 'develop' into panoptic-segmentation
benjaminpkane Oct 8, 2024
adc1807
rm staticmethod
benjaminpkane Oct 8, 2024
48719d5
painter cleanup
benjaminpkane Oct 9, 2024
c61c28b
coloring details
benjaminpkane Oct 10, 2024
4ed23c9
move modal looker state to use-looker
benjaminpkane Oct 10, 2024
3709cfd
tmp
benjaminpkane Oct 11, 2024
709b57a
merge
benjaminpkane Oct 11, 2024
b25c4a1
linting, bug fixes
benjaminpkane Oct 14, 2024
9dae758
Merge branch 'develop' into panoptic-segmentation
benjaminpkane Oct 14, 2024
54dc52f
merge develop
benjaminpkane Oct 14, 2024
f620404
rm unused packages
benjaminpkane Oct 14, 2024
bdb5186
undo
benjaminpkane Oct 14, 2024
9882232
merge
benjaminpkane Dec 12, 2024
ca57b71
core changes for PanopticSegmentation
benjaminpkane Dec 13, 2024
51feb1a
linting
benjaminpkane Dec 13, 2024
be4fed5
frontend work
benjaminpkane Dec 13, 2024
685d855
merge
benjaminpkane Dec 23, 2024
b3c36de
fe work
benjaminpkane Dec 23, 2024
7ea2d81
organizing
benjaminpkane Jan 2, 2025
e188f9c
labels cleanup
benjaminpkane Jan 3, 2025
b4e81e7
work
benjaminpkane Jan 6, 2025
263b866
docs pass
benjaminpkane Jan 7, 2025
1519b09
tooltips
benjaminpkane Jan 7, 2025
ff75811
merge develop
benjaminpkane 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
74 changes: 62 additions & 12 deletions app/packages/core/src/components/Modal/TooltipInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,58 @@ const KeypointInfo = ({ detail }) => {
);
};

const PanopticSegmentationInfo = ({ detail }) => {
console.log(detail);
const targetValue = useTarget(detail.field, detail.target);
const hideTargetValue = detail.color === undefined;

return (
<AttrBlock style={{ borderColor: detail.color }}>
{!hideTargetValue &&
(targetValue ? (
<ContentItem
key={"target-value"}
field={detail.field}
name={"label"}
value={targetValue}
/>
) : (
<ContentItem
key={"pixel-value"}
field={detail.field}
name={"pixel"}
value={detail.target}
/>
))}
{detail.instance > 0 && (
<ContentItem
key={"instance-value"}
field={detail.field}
name={"instance"}
value={detail.instance}
/>
)}
<AttrInfo
field={detail.field}
label={detail.label}
labelType={detail.type}
/>
</AttrBlock>
);
};

const PolylineInfo = ({ detail }) => {
return (
<AttrBlock style={{ borderColor: detail.color }}>
<AttrInfo
field={detail.field}
label={detail.label}
labelType={detail.type}
/>
</AttrBlock>
);
};

const RegressionInfo = ({ detail }) => {
return (
<AttrBlock style={{ borderColor: detail.color }}>
Expand Down Expand Up @@ -679,18 +731,14 @@ const SegmentationInfo = ({ detail }) => {
value={detail.target}
/>
))}
<AttrInfo
field={detail.field}
label={detail.label}
labelType={detail.type}
/>
</AttrBlock>
);
};

const PolylineInfo = ({ detail }) => {
return (
<AttrBlock style={{ borderColor: detail.color }}>
{detail.instance > 0 && (
<ContentItem
key={"instance-value"}
field={detail.field}
name={"instance"}
value={detail.instance}
/>
)}
<AttrInfo
field={detail.field}
label={detail.label}
Expand All @@ -705,6 +753,7 @@ const OVERLAY_INFO = {
Detection: DetectionInfo,
Heatmap: HeatmapInfo,
Keypoint: KeypointInfo,
PanopticSegmentation: PanopticSegmentationInfo,
Polyline: PolylineInfo,
Regression: RegressionInfo,
Segmentation: SegmentationInfo,
Expand All @@ -715,6 +764,7 @@ const HIDDEN_LABELS = {
Detection: ["bounding_box", "mask"],
Heatmap: ["map"],
Keypoint: ["points", "occluded", "confidence"],
PanopticSegmentation: ["mask"],
Polyline: ["points"],
Regression: [],
Segmentation: ["mask"],
Expand Down
3 changes: 3 additions & 0 deletions app/packages/looker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"@ungap/event-target": "^0.2.2",
"@xmldom/xmldom": "^0.8.6",
"copy-to-clipboard": "^3.3.1",
"decode-tiff": "^0.2.1",
"geotiff": "^2.1.3",
"immutable": "^4.0.0-rc.12",
"lodash": "^4.17.21",
"lru-cache": "^11.0.1",
Expand All @@ -32,6 +34,7 @@
"@rollup/plugin-inject": "^5.0.2",
"@types/color-string": "^1.5.0",
"@types/lru-cache": "^7.10.10",
"@types/utif": "^3.0.5",
"@types/uuid": "^8.3.0",
"buffer": "^6.0.3",
"prettier": "^2.7.1",
Expand Down
3 changes: 2 additions & 1 deletion app/packages/looker/src/overlays/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*/

import { getCls, sizeBytesEstimate } from "@fiftyone/utilities";
import { OverlayMask } from "../numpy";
import type { BaseState, Coordinates, NONFINITE } from "../state";
import type { OverlayMask } from "../worker/decoders/types";
import { getLabelColor, shouldShowLabelTag } from "./util";

// in numerical order (CONTAINS_BORDER takes precedence over CONTAINS_CONTENT)
Expand All @@ -30,6 +30,7 @@ export interface PointInfo<Label extends BaseLabel = BaseLabel> {
attributes: [string, unknown][];
coordinates: Coordinates;
};
instance?: bigint | number;
target?: number;
type: string;
}
Expand Down
25 changes: 10 additions & 15 deletions app/packages/looker/src/overlays/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@
* Copyright 2017-2025, Voxel51, Inc.
*/
import { NONFINITES } from "@fiftyone/utilities";

import { INFO_COLOR } from "../constants";
import { BaseState, BoundingBox, Coordinates, NONFINITE } from "../state";
import type { BaseState, BoundingBox, Coordinates, NONFINITE } from "../state";
import { distanceFromLineSegment } from "../util";
import {
CONTAINS,
CoordinateOverlay,
LabelMask,
PointInfo,
RegularLabel,
} from "./base";
import type { LabelMask, PointInfo, RegularLabel } from "./base";
import { CONTAINS, CoordinateOverlay } from "./base";
import { t } from "./util";

export interface DetectionLabel extends RegularLabel {
mask?: LabelMask;
mask_path?: string;
bounding_box: BoundingBox;

// valid for 3D bounding boxes
Expand Down Expand Up @@ -166,17 +161,17 @@ export default class DetectionOverlay<
let text =
this.label.label && state.options.showLabel ? `${this.label.label}` : "";

if (state.options.showIndex && !isNaN(this.label.index)) {
text.length && (text += " ");
if (state.options.showIndex && !Number.isNaN(this.label.index)) {
if (text.length) text += " ";
text += `${Number(this.label.index).toLocaleString()}`;
}

if (
state.options.showConfidence &&
(!isNaN(this.label.confidence as number) ||
(!Number.isNaN(this.label.confidence as number) ||
NONFINITES.has(this.label.confidence as NONFINITE))
) {
text.length && (text += " ");
if (text.length) text += " ";
text += `(${
typeof this.label.confidence === "number"
? Number(this.label.confidence).toFixed(2)
Expand Down Expand Up @@ -268,7 +263,7 @@ export default class DetectionOverlay<

export const getDetectionPoints = (labels: DetectionLabel[]): Coordinates[] => {
let points: Coordinates[] = [];
labels.forEach((label) => {
for (const label of labels) {
const [tlx, tly, w, h] = label.bounding_box;
points = [
...points,
Expand All @@ -277,6 +272,6 @@ export const getDetectionPoints = (labels: DetectionLabel[]): Coordinates[] => {
[tlx + w, tly + h],
[tlx, tly + h],
];
});
}
return points;
};
18 changes: 9 additions & 9 deletions app/packages/looker/src/overlays/heatmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import {
getRGBAColor,
sizeBytesEstimate,
} from "@fiftyone/utilities";
import { ARRAY_TYPES, TypedArray } from "../numpy";
import { BaseState, Coordinates } from "../state";
import type { BaseState, Coordinates } from "../state";
import { isFloatArray } from "../util";
import { clampedIndex } from "../worker/painter";
import {
import type { TypedArray } from "../worker/decoders/types";
import { ARRAY_TYPES } from "../worker/decoders/types";
import { clampedIndex } from "../worker/painters/utils";
import type {
BaseLabel,
CONTAINS,
LabelMask,
Overlay,
PointInfo,
SelectData,
isShown,
} from "./base";
import { CONTAINS, isShown } from "./base";
import { strokeCanvasRect, t } from "./util";

interface HeatmapLabel extends BaseLabel {
export interface HeatmapLabel extends BaseLabel {
map?: LabelMask;
range?: [number, number];
}
Expand Down Expand Up @@ -103,7 +103,7 @@ export default class HeatmapOverlay<State extends BaseState>
if (this.containsPoint(state)) {
return 0;
}
return Infinity;
return Number.Infinity;
}

getPointInfo(state: Readonly<State>): PointInfo<HeatmapInfo> {
Expand Down Expand Up @@ -212,7 +212,7 @@ export default class HeatmapOverlay<State extends BaseState>
}
}

export const getHeatmapPoints = (labels: HeatmapLabel[]): Coordinates[] => {
export const getHeatmapPoints = (_: HeatmapLabel[]): Coordinates[] => {
return [
[0, 0],
[0, 1],
Expand Down
21 changes: 14 additions & 7 deletions app/packages/looker/src/overlays/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
/**
* Copyright 2017-2025, Voxel51, Inc.
*/
import type { Schema } from "@fiftyone/utilities";
import {
DYNAMIC_EMBEDDED_DOCUMENT_FIELD,
EMBEDDED_DOCUMENT_FIELD,
LABEL_LISTS_MAP,
getCls,
getFieldInfo,
LABEL_LISTS_MAP,
Schema,
} from "@fiftyone/utilities";
import { LABEL_TAGS_CLASSES } from "../constants";
import { BaseState } from "../state";
import { Overlay } from "./base";
import {
import type { BaseState } from "../state";
import type { Overlay } from "./base";
import type {
ClassificationLabel,
ClassificationsOverlay,
Labels,
TemporalDetectionLabel,
} from "./classifications";
import {
ClassificationsOverlay,
TemporalDetectionOverlay,
} from "./classifications";
import DetectionOverlay, { getDetectionPoints } from "./detection";
import HeatmapOverlay, { getHeatmapPoints } from "./heatmap";
import KeypointOverlay, { getKeypointPoints } from "./keypoint";
import PanopticSegmentationOverlay, {
getPanopticSegmentationPoints,
} from "./panoptic";
import PolylineOverlay, { getPolylinePoints } from "./polyline";
import SegmentationOverlay, { getSegmentationPoints } from "./segmentation";

Expand All @@ -41,6 +46,7 @@ export const FROM_FO = {
Heatmap: fromLabel(HeatmapOverlay),
Keypoint: fromLabel(KeypointOverlay),
Keypoints: fromLabelList(KeypointOverlay, "keypoints"),
PanopticSegmentation: fromLabel(PanopticSegmentationOverlay),
Polyline: fromLabel(PolylineOverlay),
Polylines: fromLabelList(PolylineOverlay, "polylines"),
Segmentation: fromLabel(SegmentationOverlay),
Expand All @@ -52,9 +58,10 @@ export const POINTS_FROM_FO = {
Heatmap: (label) => getHeatmapPoints(label ? [label] : []),
Keypoint: (label) => getKeypointPoints(label ? [label] : []),
Keypoints: (label) => getKeypointPoints(label?.keypoints ?? []),
PanopticSegmentation: (label) => getSegmentationPoints(label ? [label] : []),
Polyline: (label) => getPolylinePoints(label ? [label] : []),
Poylines: (label) => getPolylinePoints(label?.polylines ?? []),
Segmentation: (label) => getSegmentationPoints(label ? [label] : []),
Segmentation: (label) => getPanopticSegmentationPoints(label ? [label] : []),
};

const LABEL_LISTS = LABEL_LISTS_MAP;
Expand Down
Loading
Loading