-
Notifications
You must be signed in to change notification settings - Fork 9
Custom model validation #288
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
base: main
Are you sure you want to change the base?
Changes from 10 commits
972c402
c957abf
e1f6e8e
52e0ab7
6e7eba1
8ba6ce8
ad4cba6
8641287
f80d870
e0d07d6
9917c51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,9 +19,12 @@ package custommodel | |
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
|
|
||
| "github.com/arduino/go-paths-helper" | ||
| "github.com/goccy/go-yaml" | ||
|
|
||
| "github.com/arduino/arduino-app-cli/internal/orchestrator/bricksindex" | ||
| ) | ||
|
|
||
| type ModelDescriptor struct { | ||
|
|
@@ -52,10 +55,64 @@ func ParseModelDescriptorFile(file *paths.Path) (ModelDescriptor, error) { | |
| return descriptor, nil | ||
| } | ||
|
|
||
| func (a *ModelDescriptor) IsValid() bool { | ||
| /* TODO: check | ||
| 1) brick list are present into the brick-list | ||
| 2) metadata are coherent with the source | ||
| */ | ||
| return true | ||
| func (a *ModelDescriptor) Validate() error { | ||
| if a.ID == "" { | ||
| return fmt.Errorf("invalid model descriptor: id is empty") | ||
| } | ||
| if a.Name == "" { | ||
| return fmt.Errorf("invalid model descriptor: name is empty") | ||
| } | ||
| source, ok := a.Metadata["source"] | ||
| if !ok { | ||
| return nil // source is optional | ||
| } | ||
|
|
||
| switch source { | ||
| case "edgeimpulse": | ||
| return validateEdgeImpulseMetadata(a.Metadata) | ||
| default: | ||
| return fmt.Errorf("invalid model descriptor: unsupported source '%s'", source) | ||
| } | ||
| } | ||
|
|
||
| func (a *ModelDescriptor) CheckEdgeImpulseBricks(bricksIndex *bricksindex.BricksIndex) error { | ||
| for _, brickConfig := range a.Bricks { | ||
| brick, ok := bricksIndex.FindBrickByID(brickConfig.ID) | ||
| if !ok { | ||
| return fmt.Errorf("invalid model descriptor: brick with ID '%s' not found", brickConfig.ID) | ||
| } | ||
|
|
||
| for _, variable := range brick.Variables { | ||
| if strings.HasPrefix(variable.Name, "EI_") && strings.HasSuffix(variable.Name, "_MODEL") { | ||
| if val, ok := brickConfig.ModelConfiguration[variable.Name]; !ok || val == "" { | ||
| return fmt.Errorf("invalid model descriptor: missing model configuration for variable '%s' in brick '%s'", variable.Name, brickConfig.ID) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func validateEdgeImpulseMetadata(metadata map[string]string) error { | ||
| requiredFields := []string{ | ||
| "ei-project-id", | ||
| "ei-impulse-id", | ||
| "ei-impulse-name", | ||
| "ei-deployment-version", | ||
| } | ||
|
Comment on lines
+97
to
+102
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would double-check that all these tags are mandatory for the edge impulse.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From our side, we don't use these fields. We just store them and return to the front-end. We could check into the Figma flows how they use the information, but I guess it is better to check directly with the front-end.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for example I see from App-lab that they read ei-deployment-version to check if an installed model is outdated:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I confirm that they are all mandatory for App Lab |
||
| for _, field := range requiredFields { | ||
| if val, ok := metadata[field]; !ok || val == "" { | ||
| return fmt.Errorf("invalid Edge Impulse metadata: missing required field '%s'", field) | ||
| } | ||
| } | ||
|
|
||
| if metadata["ei-model-type"] != "float32" { | ||
| return fmt.Errorf("invalid Edge Impulse metadata: unsupported model type") | ||
| } | ||
|
|
||
| if metadata["ei-engine"] != "tflite" { | ||
| return fmt.Errorf("invalid Edge Impulse metadata: unsupported engine") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.