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

Release updates #3972

Merged
merged 5 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
68 changes: 45 additions & 23 deletions app/packages/core/src/components/Schema/SchemaSelectControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import React, { useMemo } from "react";
import { Box, FormControlLabel, FormGroup, Switch } from "@mui/material";

import { useSchemaSettings, useSearchSchemaFields } from "@fiftyone/state";
import styled from "styled-components";
import styled, { useTheme } from "styled-components";
import { ExternalLink, InfoIcon } from "@fiftyone/components";
import { FIELD_METADATA } from "../../utils/links";

const ContainerBox = styled(Box)`
position: relative;
Expand All @@ -25,6 +27,7 @@ export const SchemaSelectionControls = () => {
setIncludeNestedFields,
mergedSchema,
} = useSchemaSettings();
const theme = useTheme();

const { searchResults } = useSearchSchemaFields(mergedSchema);
const showMetadataVisible = !(isFilterRuleActive && !searchResults.length);
Expand All @@ -33,7 +36,8 @@ export const SchemaSelectionControls = () => {
const controlList = useMemo(() => {
return [
{
label: "Show metadata",
label: "Show field metadata",
link: FIELD_METADATA,
isVisible: showMetadataVisible,
value: showMetadata,
checked: showMetadata,
Expand Down Expand Up @@ -86,27 +90,45 @@ export const SchemaSelectionControls = () => {
<Box display="flex" width="100%" flexDirection="row" marginTop="1rem">
{controlList
.filter(({ isVisible }) => isVisible)
.map(({ label, value, checked, onChange, disabled = false }) => (
<ContainerBox key={label} flex="1">
<FormGroup>
<FormControlLabel
control={
<Switch
value={value}
checked={checked}
onChange={onChange}
disabled={disabled}
data-cy={`field-visibility-controls-${label
.toLowerCase()
.replace(/ /g, "-")}`}
/>
}
label={label}
sx={{ letterSpacing: "0.05rem" }}
/>
</FormGroup>
</ContainerBox>
))}
.map(
({ label, value, checked, onChange, disabled = false, link }) => (
<ContainerBox key={label} flex="1">
<FormGroup>
<FormControlLabel
control={
<Switch
value={value}
checked={checked}
onChange={onChange}
disabled={disabled}
data-cy={`field-visibility-controls-${label
.toLowerCase()
.replace(/ /g, "-")}`}
/>
}
label={
<>
{label}{" "}
{link && (
<ExternalLink href={link}>
<InfoIcon
sx={{
color: theme.text.tertiary,
position: "absolute",
ml: 0.5,
mt: "1px",
}}
/>
</ExternalLink>
)}
</>
}
sx={{ letterSpacing: "0.05rem" }}
/>
</FormGroup>
</ContainerBox>
)
)}
</Box>
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { generateSchema } from "../utils";
import DynamicIO from "./DynamicIO";

export default function InferredView(props) {
const { data, schema } = props;
const readOnly = schema?.readOnly || schema?.view?.readOnly;
const generatedSchema = generateSchema(data || schema?.default, {
label: schema?.view?.label,
readOnly,
const { schema = {} } = props;
const { view = {}, default: defaultValue, readOnly } = schema;
const generatedSchema = generateSchema(defaultValue, {
label: view.label,
readOnly: readOnly || view.readOnly,
});

return <DynamicIO {...props} schema={generatedSchema} />;
const schemaWithDefault = { ...generatedSchema, default: defaultValue };
return <DynamicIO {...props} schema={schemaWithDefault} />;
}
22 changes: 15 additions & 7 deletions app/packages/core/src/plugins/SchemaIO/utils/generate-schema.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Auto generate SchemaIO compatible schema based on a value

import { isPrimitiveType } from "@fiftyone/utilities";
import { isNullish, isPrimitiveType } from "@fiftyone/utilities";

// todo: add support for OneOfView, TupleView, and MapView
export function generateSchema(value, options?) {
export function generateSchema(value: any, options?: GenerateSchemaOptions) {
const type = getType(value);
const { label, readOnly } = options;
const { label, readOnly } = options || {};
if (type === "array") {
const dominantType = getDominantType(value);
const isValueTable = isTable(value);
Expand All @@ -16,10 +16,9 @@ export function generateSchema(value, options?) {
label,
component: "TableView",
columns: getTableColumns(value),
readOnly: true,
},
};
} else if (isPrimitiveType(dominantType) && readOnly) {
} else if (isPrimitiveType(dominantType || "") && readOnly) {
return {
type,
view: {
Expand Down Expand Up @@ -53,7 +52,7 @@ export function generateSchema(value, options?) {
readOnly,
},
};
} else {
} else if (isPrimitiveType(type || "")) {
return {
type,
view: {
Expand All @@ -66,12 +65,16 @@ export function generateSchema(value, options?) {
readOnly,
},
};
} else {
// todo: improve unknown type - TupleView? CodeView?
return { type, view: { label, component: "UnsupportedView", readOnly } };
}
}

function getType(value) {
if (value !== undefined || value !== null)
if (!isNullish(value)) {
return Array.isArray(value) ? "array" : typeof value;
}
}

function getDominantType(array) {
Expand Down Expand Up @@ -119,3 +122,8 @@ function getTableColumns(array) {
const [firstItem] = array;
return Object.keys(firstItem).map((key) => ({ key, label: key }));
}

type GenerateSchemaOptions = {
label?: string;
readOnly?: boolean;
};
3 changes: 3 additions & 0 deletions app/packages/core/src/utils/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export const COLOR_SCHEME =
export const EVALUATION_PATCHES =
"https://docs.voxel51.com/user_guide/app.html#app-evaluation-patches";

export const FIELD_METADATA =
"https://docs.voxel51.com/user_guide/using_datasets.html#storing-field-metadata";

export const LIGHTNING_MODE =
"https://docs.voxel51.com/user_guide/app.html#lightning-mode";

Expand Down
6 changes: 4 additions & 2 deletions e2e-pw/src/oss/poms/field-visibility/field-visibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ export class FieldVisibilityPom {
);
}

getControl(name: "select-all" | "show-metadata" | "show-nested-fields") {
getControl(
name: "select-all" | "show-field-metadata" | "show-nested-fields"
) {
return this.getFieldVisibilityControl(name);
}

Expand Down Expand Up @@ -162,7 +164,7 @@ export class FieldVisibilityPom {
}

async toggleShowMetadata() {
const toggle = this.getControl("show-metadata");
const toggle = this.getControl("show-field-metadata");
await toggle.click();
}

Expand Down
34 changes: 34 additions & 0 deletions fiftyone/utils/open_clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@ def __init__(self, config):
super().__init__(config)
self._text_features = None

@property
def can_embed_prompts(self):
return True

def embed_prompt(self, prompt):
"""Generates an embedding for the given text prompt.

Args:
prompt: a text string

Returns:
a numpy vector
"""
return self.embed_prompts([prompt])[0]

def embed_prompts(self, prompts):
"""Generates an embedding for the given text prompts.

Args:
prompts: an iterable of text strings

Returns:
a ``num_prompts x num_dims`` array of prompt embeddings
"""
return self._embed_prompts(prompts).detach().cpu().numpy()

def _load_model(self, config):
(
self._model,
Expand All @@ -80,6 +106,14 @@ def _get_text_features(self):

return self._text_features

def _embed_prompts(self, prompts):
formatted_prompts = [
"%s %s" % (self.config.text_prompt, p) for p in prompts
]
# Tokenize text
text = self._tokenizer(formatted_prompts)
return self._model.encode_text(text)

def _get_class_logits(self, text_features, image_features):
# source: https://github.com/openai/CLIP/blob/main/README.md
image_features = image_features / image_features.norm(
Expand Down
4 changes: 0 additions & 4 deletions fiftyone/zoo/models/manifest-torch.json
Original file line number Diff line number Diff line change
Expand Up @@ -1869,10 +1869,6 @@
"description": "OPEN CLIP text/image encoder from `Learning Transferable Visual Models From Natural Language Supervision <https://arxiv.org/abs/2103.00020>`_ trained on 400M text-image pairs",
"source": "https://github.com/mlfoundations/open_clip",
"size_bytes": 353976522,
"manager": {
"type": "fiftyone.core.models.ModelManager",
"config": {}
},
"default_deployment_config_dict": {
"type": "fiftyone.utils.open_clip.TorchOpenClipModel",
"config": {
Expand Down
Loading