Skip to content

Commit

Permalink
Merge pull request #5132 from voxel51/feat/extend-array-deserialization
Browse files Browse the repository at this point in the history
extend compatibility of array deserialization in lookers
  • Loading branch information
tom-vx51 authored Nov 16, 2024
2 parents e0c22fd + deaf55b commit 9a13da7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/packages/looker/src/overlays/segmentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export default class SegmentationOverlay<State extends BaseState>
private getTarget(state: Readonly<State>): number {
const index = this.getIndex(state);

if (index < 0) {
if (index < 0 || !this.targets || index >= this.targets.length) {
return null;
}
return this.targets[index];
Expand Down
31 changes: 25 additions & 6 deletions app/packages/looker/src/worker/deserializer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import { deserialize } from "../numpy";

const extractSerializedMask = (
label: object,
maskProp: string
): string | undefined => {
if (typeof label?.[maskProp] === "string") {
return label[maskProp];
} else if (typeof label?.[maskProp]?.$binary?.base64 === "string") {
return label[maskProp].$binary.base64;
}

return undefined;
};

export const DeserializerFactory = {
Detection: (label, buffers) => {
if (typeof label?.mask === "string") {
const data = deserialize(label.mask);
const serializedMask = extractSerializedMask(label, "mask");

if (serializedMask) {
const data = deserialize(serializedMask);
const [height, width] = data.shape;
label.mask = {
data,
Expand All @@ -20,8 +35,10 @@ export const DeserializerFactory = {
}
},
Heatmap: (label, buffers) => {
if (typeof label?.map === "string") {
const data = deserialize(label.map);
const serializedMask = extractSerializedMask(label, "map");

if (serializedMask) {
const data = deserialize(serializedMask);
const [height, width] = data.shape;

label.map = {
Expand All @@ -34,8 +51,10 @@ export const DeserializerFactory = {
}
},
Segmentation: (label, buffers) => {
if (typeof label?.mask === "string") {
const data = deserialize(label.mask);
const serializedMask = extractSerializedMask(label, "mask");

if (serializedMask) {
const data = deserialize(serializedMask);
const [height, width] = data.shape;

label.mask = {
Expand Down

0 comments on commit 9a13da7

Please sign in to comment.