Skip to content

Commit

Permalink
Added recipes endpoint to sparsezoo table ui (#77)
Browse files Browse the repository at this point in the history
* Added recipes endpoint to sparsezoo table ui

* Removed commented code
  • Loading branch information
kevinaer authored Apr 29, 2021
1 parent a762ef1 commit 2becaa1
Show file tree
Hide file tree
Showing 21 changed files with 651 additions and 50 deletions.
39 changes: 10 additions & 29 deletions docs/source/recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,16 @@ The properties within each model stub are defined as the following:

### Image Classification

| Model Tag | Validation Baseline Metric |
| ----------------------------------------------------------------------------------------------------------------- | -------------------------- |
| cv/classification/efficientnet-b0/pytorch/sparseml/imagenet/arch-moderate?recipe_type=original | 76.5% top1 accuracy |
| cv/classification/efficientnet-b4/pytorch/sparseml/imagenet/arch-moderate?recipe_type=original | 82.1% top1 accuracy |
| cv/classification/inception_v3/pytorch/sparseml/imagenet/pruned-conservative?recipe_type=original | 77.4% top1 accuracy |
| cv/classification/inception_v3/pytorch/sparseml/imagenet/pruned-moderate?recipe_type=original | 76.6% top1 accuracy |
| cv/classification/mobilenet_v1-1.0/pytorch/sparseml/imagenet/base-none?recipe_type=original | 70.9% top1 accuracy |
| cv/classification/mobilenet_v1-1.0/pytorch/sparseml/imagenet/pruned-conservative?recipe_type=original | 70.9% top1 accuracy |
| cv/classification/mobilenet_v1-1.0/pytorch/sparseml/imagenet/pruned-moderate?recipe_type=original | 70.1% top1 accuracy |
| cv/classification/mobilenet_v1-1.0/pytorch/sparseml/imagenet/pruned_quant-moderate?recipe_type=original | 70.1% top1 accuracy |
| cv/classification/mobilenet_v1-1.0/pytorch/sparseml/imagenet/pruned_quant-moderate?recipe_type=original | 70.1% top1 accuracy |
| cv/classification/resnet_v1-101/pytorch/sparseml/imagenet/pruned-moderate?recipe_type=original | 76.6% top1 accuracy |
| cv/classification/resnet_v1-152/pytorch/sparseml/imagenet/pruned-moderate?recipe_type=original | 77.5% top1 accuracy |
| cv/classification/resnet_v1-18/pytorch/sparseml/imagenet/pruned-conservative?recipe_type=original | 69.8% top1 accuracy |
| cv/classification/resnet_v1-34/pytorch/sparseml/imagenet/pruned-conservative?recipe_type=original | 73.3% top1 accuracy |
| cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned-conservative?recipe_type=original | 76.1% top1 accuracy |
| cv/classification/resnet_v1-50/pytorch/sparseml/imagenet/pruned-moderate?recipe_type=original | 75.3% top1 accuracy |
| cv/classification/resnet_v1-50/pytorch/sparseml/imagenet-augmented/pruned_quant-aggressive?recipe_type=original | 76.1% top1 accuracy |
| cv/classification/resnet_v1-50/pytorch/sparseml/imagenette/pruned-conservative?recipe_type=original | 99.9% top1 accuracy |
| cv/classification/resnet_v1-50/pytorch/torchvision/imagenette/pruned-conservative?recipe_type=original | 99.9% top1 accuracy |
| cv/classification/vgg-11/pytorch/sparseml/imagenet/pruned-moderate?recipe_type=original | 68.3% top1 accuracy |
| cv/classification/vgg-16/pytorch/sparseml/imagenet/pruned-conservative?recipe_type=original | 71.6% top1 accuracy |
| cv/classification/vgg-16/pytorch/sparseml/imagenet/pruned-moderate?recipe_type=original | 70.8% top1 accuracy |
| cv/classification/vgg-19/pytorch/sparseml/imagenet/pruned-moderate?recipe_type=original | 71.7% top1 accuracy |
<div>
<iframe src="https://sparsezoo.neuralmagic.com/recipes/cv/classification" title="Image Classification Recipes" width="100%" height="500px"></iframe>
</div>

Image classification table not loading? View full table [here](https://sparsezoo.neuralmagic.com/recipes/cv/classification).

### Object Detection

| Model Tag | Validation Baseline Metric |
| ----------------------------------------------------------------------------------------------------------------- | -------------------------- |
| cv/detection/ssd-resnet50_300/pytorch/sparseml/coco/pruned-moderate?recipe_type=original | 41.8 mAP@0.5 |
| cv/detection/ssd-resnet50_300/pytorch/sparseml/voc/pruned-moderate?recipe_type=original | 51.5 mAP@0.5 |
| cv/detection/yolo_v3-spp/pytorch/ultralytics/coco/pruned-aggressive?recipe_type=original | 62.1 mAP@0.5 |
<div>
<iframe src="https://sparsezoo.neuralmagic.com/recipes/cv/detection" title="Object Detect Recipes" width="100%" height="500px"></iframe>
</div>

Object detection table not loading? View full table [here](https://sparsezoo.neuralmagic.com/recipes/cv/detection).
1 change: 1 addition & 0 deletions src/ui/api/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ limitations under the License.

export * from "./auth";
export * from "./models";
export * from "./recipes";
export * from "./utils";
2 changes: 1 addition & 1 deletion src/ui/api/models.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { API_ROOT, validateAPIResponseJSON } from "./utils";
* training_scheme: string,
* sparse_name: string,
* sparse_category: string,
* sparse_target
* sparse_target: string
* }} requestBody.queries the additional queries for the search result
* @returns {Promise<Array>}
*/
Expand Down
64 changes: 64 additions & 0 deletions src/ui/api/recipes.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { API_ROOT, validateAPIResponseJSON } from "./utils";

/**
* API action for searching for models in the model zoo
* @param {object} requestBody the requestBody
* @param {string} requestBody.domain the domain of the model search
* @param {string} requestBody.subdomain the subdomain of the model search
* @param {string} requestBody.token the token for the model search authentication
* @param {string} requestBody.page the page of search results to return
* @param {string} requestBody.page_legth the amount of search results to return
* @param {{
* architecture: string,
* sub_architecture: string,
* repo: string,
* framework: string,
* dataset: string,
* training_scheme: string,
* sparse_name: string,
* sparse_category: string,
* sparse_target: string,
* recipe_type: string
* }} requestBody.queries the additional queries for the search result
* @returns {Promise<Array>}
*/
export function requestSearchRecipes({
domain,
subdomain,
token,
page = 1,
page_length = 20,
queries = {},
}) {
let url = `${API_ROOT}/recipes/search/${domain}/${subdomain}?page=${page}&page_length=${page_length}`;
if (queries) {
for (const [key, value] of Object.entries(queries)) {
url = `${url}&${key}=${value}`;
}
}
return validateAPIResponseJSON(
fetch(url, {
method: "GET",
headers: {
"Content-Type": "application/json",
"nm-token-header": token,
},
})
);
}
2 changes: 1 addition & 1 deletion src/ui/components/model-table/model-table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function ModelTable({ domain, subdomain, includePagination, includeHeader, queri
const modelsState = useSelector(selectModelsState);

const results = useSelector(selectModelTable);

useEffect(() => {
const status = lodash.get(modelsState.status, `${domain}.${subdomain}`, "idle");
if (authState.token !== null && status === "idle") {
Expand Down Expand Up @@ -81,6 +80,7 @@ function ModelTable({ domain, subdomain, includePagination, includeHeader, queri
copy={lodash.get(results, `${domain}.${subdomain}.copy`, false)}
width={lodash.get(results, `${domain}.${subdomain}.width`)}
includePagination={includePagination}
loadingMessage="Loading models"
/>
</div>
);
Expand Down
17 changes: 17 additions & 0 deletions src/ui/components/recipe-table/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

export { default } from "./recipe-table";
29 changes: 29 additions & 0 deletions src/ui/components/recipe-table/recipe-table-styles.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { makeStyles } from "@material-ui/core/styles";

export default function makeRecipeTableStyles() {
return makeStyles(
(theme) => ({
root: {
padding: theme.spacing(0.5),
},
toolbar: {},
}),
{ name: "RecipeTable" }
);
}
104 changes: 104 additions & 0 deletions src/ui/components/recipe-table/recipe-table.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import React, { useEffect } from "react";
import { useSelector, useDispatch } from "react-redux";
import PropTypes from "prop-types";

import lodash from "lodash";

import Typography from "@material-ui/core/Typography";

import {
selectAuthState,
selectRecipesState,
searchRecipesThunk,
selectRecipesTable,
} from "../../store";
import makeStyles from "./recipe-table-styles";
import ZooTable from "../zoo-table";

function RecipeTable({ domain, subdomain, includePagination, includeHeader, queries }) {
const useStyles = makeStyles();
const classes = useStyles();
const dispatch = useDispatch();

const authState = useSelector(selectAuthState);
const recipesState = useSelector(selectRecipesState);
console.log(recipesState);
const results = useSelector(selectRecipesTable);

useEffect(() => {
const status = lodash.get(recipesState.status, `${domain}.${subdomain}`, "idle");
if (authState.token !== null && status === "idle") {
dispatch(
searchRecipesThunk({
domain,
subdomain,
token: authState.token,
queries,
})
);
}
}, [authState.token, recipesState.status, dispatch, domain, subdomain, queries]);

const rows = lodash
.get(results, `${domain}.${subdomain}.data`, [])
.map((data) => data.row);
const status = lodash.get(results, `${domain}.${subdomain}.status`, "idle");
const loaded = status !== "idle" && status !== "loading";
return (
<div className={classes.root}>
{loaded && includeHeader && (
<Typography variant="h6">
{lodash.get(
results,
`${domain}.${subdomain}.displayName`,
`${domain} ${subdomain}`
)}
</Typography>
)}
<ZooTable
ariaLabel={`${domain}.${subdomain}`}
headers={lodash.get(results, `${domain}.${subdomain}.headers`, [])}
rows={rows}
status={status}
error={authState.error || recipesState.error}
aligns={lodash.get(results, `${domain}.${subdomain}.aligns`, "left")}
copy={lodash.get(results, `${domain}.${subdomain}.copy`, false)}
width={lodash.get(results, `${domain}.${subdomain}.width`)}
includePagination={includePagination}
loadingMessage="Loading recipes"
/>
</div>
);
}

RecipeTable.propTypes = {
domain: PropTypes.string.isRequired,
subdomain: PropTypes.string.isRequired,
queries: PropTypes.object,
includePagination: PropTypes.bool,
includeHeader: PropTypes.bool,
};

RecipeTable.defaultProps = {
includePagination: false,
includeHeader: false,
queries: {},
};

export default RecipeTable;
5 changes: 4 additions & 1 deletion src/ui/components/zoo-table/zoo-table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function ZooTable({
width,
copy,
includePagination,
loadingMessage,
}) {
const useStyles = makeStyles();
const classes = useStyles();
Expand Down Expand Up @@ -68,7 +69,7 @@ function ZooTable({
loaderSize={150}
loaderChildren={
<Typography className={classes.loaderText}>
{!error && "Loading models"}
{!error && loadingMessage}
</Typography>
}
></LoaderOverlay>
Expand Down Expand Up @@ -135,6 +136,7 @@ ZooTable.propTypes = {
]),
copy: PropTypes.oneOfType([PropTypes.bool, PropTypes.arrayOf(PropTypes.bool)]),
includePagination: PropTypes.bool,
loadingMessage: PropTypes.string,
};

ZooTable.defaultProps = {
Expand All @@ -146,6 +148,7 @@ ZooTable.defaultProps = {
paginationOptions: [10, 25, 100],
includePagination: false,
copy: false,
loadingMessage: "Loading...",
};

export default ZooTable;
2 changes: 2 additions & 0 deletions src/ui/routes/paths.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ limitations under the License.

export const MODEL_TABLE_ROOT_PATH = "/models";
export const MODEL_TABLE_PATH = "/models/:domain/:subdomain";
export const RECIPE_TABLE_ROOT_PATH = "/recipes";
export const RECIPE_TABLE_PATH = "/recipes/:domain/:subdomain";
17 changes: 17 additions & 0 deletions src/ui/routes/recipes-root/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

export { default } from "./recipes-root";
26 changes: 26 additions & 0 deletions src/ui/routes/recipes-root/recipes-root-styles.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
Copyright (c) 2021 - present / Neuralmagic, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import { makeStyles } from "@material-ui/core/styles";

export default function makeRecipeTableRootStyles() {
return makeStyles(
(theme) => ({
root: {},
}),
{ name: "RecipeTableRoot" }
);
}
Loading

0 comments on commit 2becaa1

Please sign in to comment.