-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add controls for AILabImage component stories - Half-Fix #36
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
109 changes: 92 additions & 17 deletions
109
examples/ai-lab-example/storybook/AILabImage.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,105 @@ | ||
import React from 'react'; | ||
import { AILabImage } from 'ai-lab'; | ||
import { ComponentStory, ComponentMeta } from '@storybook/react'; | ||
|
||
export default { | ||
title: 'Example/AILabImage', | ||
title: 'Example/AILabImage/SSD Model', | ||
component: AILabImage, | ||
argTypes: { | ||
imageSource: { | ||
options: ['dinner', 'cat', 'beach'], | ||
control: { type: 'select' }, | ||
}, | ||
threshold: { | ||
control: { type: 'range', min: 0, max: 1, step: 0.01 }, | ||
}, | ||
maxBoxes: { | ||
control: { type: 'range', min: 0, max: 50, step: 1 }, | ||
}, | ||
iouThreshold: { | ||
control: { type: 'range', min: 0, max: 1, step: 0.01 }, | ||
}, | ||
}, | ||
} as ComponentMeta<typeof AILabImage>; | ||
|
||
const gimmeImage = (src: string) => { | ||
switch (src) { | ||
case 'dinner': | ||
return require('./dinner.jpg'); | ||
case 'cat': | ||
return require('./cat.jpeg'); | ||
default: | ||
return require('./beach.jpeg'); | ||
} | ||
}; | ||
|
||
// @ts-ignore | ||
const imageStory = args => { | ||
const theImage = require('./dinner.jpg'); | ||
//////////////////////////////////////////////////////////////// | ||
// Image Defaults | ||
//////////////////////////////////////////////////////////////// | ||
|
||
const imageStory: ComponentStory<typeof AILabImage> = (args, { loaded }) => { | ||
//@ts-ignore | ||
const theImage = gimmeImage(args.imageSource); | ||
return ( | ||
<AILabImage perf={args.perf} src={theImage} style={{ width: '100%' }} /> | ||
<AILabImage | ||
model={loaded.SSDModel} | ||
src={theImage} | ||
style={{ height: '100%' }} | ||
/> | ||
); | ||
}; | ||
|
||
export const withAnImage = imageStory.bind({}); | ||
export const withAnImageDefaults = imageStory.bind({}); | ||
// @ts-ignore | ||
withAnImage.args = { | ||
withAnImageDefaults.args = { | ||
imageSource: 'cat', | ||
}; | ||
withAnImageDefaults.parameters = { | ||
controls: { include: ['imageSource'] }, | ||
}; | ||
|
||
//////////////////////////////////////////////////////////////// | ||
// Image with Params | ||
//////////////////////////////////////////////////////////////// | ||
const imageParamsStory: ComponentStory<typeof AILabImage> = ( | ||
args, | ||
{ loaded } | ||
) => { | ||
//@ts-ignore | ||
const theImage = gimmeImage(args.imageSource); | ||
return ( | ||
<AILabImage | ||
model={loaded.SSDModel} | ||
perf={args.perf} | ||
src={theImage} | ||
style={{ height: '100%' }} | ||
modelInfo={{ | ||
modelType: 'ssd', | ||
threshold: args.threshold, | ||
nmsActive: args.nmsActive, | ||
maxBoxes: args.maxBoxes, | ||
}} | ||
/> | ||
); | ||
}; | ||
export const withImageAndCustomizedSettings = imageParamsStory.bind({}); | ||
withImageAndCustomizedSettings.args = { | ||
perf: true, | ||
// restrain: false, | ||
// modelInfo: { | ||
// model: 'this is the model', | ||
// objectDetection: true, | ||
// labels: ['dog', 'cat'], | ||
// threshold: 0.4, | ||
// max: 20, | ||
// IOU: 0.5, | ||
// }, | ||
imageSource: 'dinner', | ||
threshold: 0.4, | ||
iouThreshold: 0.5, | ||
maxBoxes: 20, | ||
nmsActive: true, | ||
}; | ||
|
||
withImageAndCustomizedSettings.parameters = { | ||
controls: { | ||
include: [ | ||
'threshold', | ||
'imageSource', | ||
'perf', | ||
'nmsActive', | ||
'maxBoxes', | ||
'iouThreshold', | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,21 @@ | ||
import * as tf from '@tensorflow/tfjs'; | ||
|
||
export const parameters = { | ||
actions: { argTypesRegex: "^on[A-Z].*" }, | ||
actions: { argTypesRegex: '^on[A-Z].*' }, | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/, | ||
}, | ||
}, | ||
} | ||
}; | ||
|
||
// Load models to feed into all components | ||
// @ts-ignore | ||
export const loaders = [ | ||
async () => ({ | ||
SSDModel: await tf.loadGraphModel( | ||
'https://storage.googleapis.com/tfhub-tfjs-modules/tensorflow/tfjs-model/ssd_mobilenet_v2/1/default/1/model.json' | ||
), | ||
}), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm not sure why this dispose was commented out, but it needs to be brought back in to protect from mem-leaks
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.
You are right! I was getting type errors and since fast refresh disposed tensors I commented those out then forgot to brought them back even after the type errors are fixed in different components.