-
Notifications
You must be signed in to change notification settings - Fork 902
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
Cleanup 🧹 image argument checking #1322
Conversation
src/utils/handleArguments.js
Outdated
} | ||
// All other objects are assumed to be options. | ||
else { | ||
this.options = arg; |
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.
Question:
- If multiple objects are passed, should we spread all those obj properties into this
options
object? 😬
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.
That's an interesting idea! I wouldn't want to encourage a situation where the user is providing multiple options
objects. But it does open up some interesting possibilities for internal use:
- We can pass the
DEFAULT_OPTIONS
as the first argument when parsing the arguments for constructing a model. TheArgHelper
would handle merging the provided arguments with the defaults and we could take that logic out of a bunch of constructors. - We can merge this.options with additional options that are provided to a specific method. (For models like
BodyPix
where we are accepting options on methods likesegment
)
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.
With my latest change they will get a warning if there are multiple options objects. I think that what you are suggesting is a good idea for a future PR. But for now this one should be good to go as-is!
# Conflicts: # src/BodyPix/index.js # src/FaceApi/index.js # src/Facemesh/index.js # src/Handpose/index.js
|
||
return callCallback(this.segmentWithPartsInternal(imgToSegment, segmentationOptions), callback); | ||
|
||
return callCallback(this.segmentWithPartsInternal(image, options), callback); |
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.
Positive affirmation:
- 🧹 ✨ !!!
return callback ? instance : instance.ready; | ||
const bodyPix = (...inputs) => { | ||
const args = handleArguments(...inputs); | ||
const instance = new BodyPix(args.video, args.options || {}, args.callback); |
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.
Positive affirmation
- 🤩 digging this!
let model = string; | ||
// TODO: I think we should delete this. | ||
if (model.indexOf("http") === -1) { | ||
model = model.toLowerCase(); |
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.
This is a good note:
- Maybe we keep this in for now, but let's do a follow up at some point reassessing the model name handling. I feel like we talked about these somewhere? 😂
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.
modelName = 'model'; | ||
} | ||
const { string, callback } = handleArguments(nameOrCb, cb); | ||
const modelName = string || 'model'; |
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.
nonblocking comment:
handleArguements()
feels like some kind of super hero magic -- "with great power comes great responsibility" 😂
|
||
// const PATH_START_LARGE = 'https://storage.googleapis.com/quickdraw-models/sketchRNN/large_models/'; | ||
// const PATH_START_SMALL = 'https://storage.googleapis.com/quickdraw-models/sketchRNN/models/'; | ||
// const PATH_END = '.gen.json'; | ||
|
||
|
||
const DEFAULTS = { | ||
// TODO: this doesn't look right... -Linda |
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.
nonblocking comment:
- Oh weird! Hmm seems like we might add this to another follow up to resolve. 🙈
|
||
this.config = { | ||
temperature: 0.65, | ||
pixelFactor: 3.0, | ||
// TODO: it doesn't make sense for these to be instance properties -Linda |
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.
nonblocking comment:
- Agreed! Let's circle back around to this cleanup work.
*/ | ||
export default function handleArguments(...args) { | ||
return new ArgHelper(...args); | ||
}; |
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.
Positive Affirmation:
- Very clever + makes argument handling so much cleaner! Bravo! 🌟
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.
Such a long needed overhaul and cleanup of this major part of ml5. Thanks so much! 🏅
Fix a bug that I introduced in #1322
Related issue #1189
handleArguments
handleArguments
constructs and returns an instance of newArgHelper
class.const { video, callback } = args
or accessed asargs.video
..require
method as a wrapper around error throwing, which is called asargs.require('image', 'message when missing')
.Utilities
isCanvas
,isVideo
, etc.).getImageElement
to access the underlying DOM element from p5 objects.flipImage
andimgToPixelArray
into functiondrawToCanvas
.imageUtilities
functions.Models
handleArguments
to delete large chunks of repeated code from models.