Skip to content

Commit

Permalink
RSDK-8629: mock out all tflite model services in vision service tests (
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaney authored Aug 28, 2024
1 parent a91d4c4 commit 7c53a0a
Show file tree
Hide file tree
Showing 5 changed files with 748 additions and 212 deletions.
4 changes: 4 additions & 0 deletions .artifact/tree.json
Original file line number Diff line number Diff line change
Expand Up @@ -52273,6 +52273,10 @@
"hash": "93b03dc453206b6ce0cd083f96066544",
"size": 23685
},
"imagenetlabels_bkg.txt": {
"hash": "3fbcd001ab4d94fa66e61c033aeee134",
"size": 23698
},
"lion.jpeg": {
"hash": "7a24ee403e1606a0956d63dc744f24de",
"size": 31645
Expand Down
2 changes: 1 addition & 1 deletion services/vision/mlvision/classifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func attemptToBuildClassifier(mlm mlmodel.Service,
}
confs := checkClassificationScores(probs)
if labels != nil && len(labels) != len(confs) {
return nil, errors.New("length of output expected to be length of label list (but is not)")
return nil, errors.Errorf("length of output (%d) expected to be length of label list (%d)", len(confs), len(labels))
}
classifications := make(classification.Classifications, 0, len(confs))
for i := 0; i < len(confs); i++ {
Expand Down
21 changes: 10 additions & 11 deletions services/vision/mlvision/ml_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,14 @@ func getLabelsFromFile(labelPath string) []string {
}
labels = append(labels, scanner.Text())
}
// if the labels come out as one line, try splitting that line by spaces or commas to extract labels
// Check if the labels should be comma split first and then space split.
if len(labels) == 1 {
labels = strings.Split(labels[0], ",")
}
if len(labels) == 1 {
labels = strings.Split(labels[0], " ")
}
return labels
}

Expand All @@ -255,18 +263,9 @@ func getLabelsFromMetadata(md mlmodel.MLMetadata, labelPath string) []string {
return nil
}
labels := getLabelsFromFile(labelPath)
if len(labels) == 0 {
return nil
}
// if the labels come out as one line, try splitting that line by spaces or commas to extract labels
// Check if the labels should be comma split first and then space split.
if len(labels) == 1 {
labels = strings.Split(labels[0], ",")
}
if len(labels) == 1 {
labels = strings.Split(labels[0], " ")
if len(labels) != 0 {
return labels
}
return labels
}
return nil
}
Expand Down
Loading

0 comments on commit 7c53a0a

Please sign in to comment.