Skip to content

Commit d757dc9

Browse files
working
1 parent fbb6b65 commit d757dc9

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

cli/ml_inference.go

+46-10
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ func MLInferenceInferAction(c *cli.Context, args mlInferenceInferArgs) error {
3434
return err
3535
}
3636

37-
// Print the arguments
38-
fmt.Println("OrgID: ", args.OrgID)
39-
fmt.Println("FileOrgID: ", args.FileOrgID)
40-
fmt.Println("FileID: ", args.FileID)
41-
fmt.Println("FileLocationID: ", args.FileLocationID)
42-
fmt.Println("ModelID: ", args.ModelID)
43-
fmt.Println("ModelVersion: ", args.ModelVersion)
44-
4537
_, err = client.mlRunInference(
4638
args.OrgID, args.FileOrgID, args.FileID, args.FileLocationID,
4739
args.ModelID, args.ModelVersion)
@@ -72,7 +64,51 @@ func (c *viamClient) mlRunInference(orgID, fileOrgID, fileID, fileLocation, mode
7264
if err != nil {
7365
return nil, errors.Wrapf(err, "received error from server")
7466
}
75-
fmt.Println("OutputTensors: ", resp.OutputTensors)
76-
fmt.Println("Annotations: ", resp.Annotations)
67+
printInferenceResponse(resp)
7768
return resp, nil
7869
}
70+
71+
// printInferenceResponse prints a neat representation of the GetInferenceResponse.
72+
func printInferenceResponse(resp *mlinferencepb.GetInferenceResponse) {
73+
fmt.Println("Inference Response:")
74+
fmt.Println("Output Tensors:")
75+
if resp.OutputTensors != nil {
76+
for name, tensor := range resp.OutputTensors.Tensors {
77+
fmt.Printf(" Tensor Name: %s\n", name)
78+
fmt.Printf(" Shape: %v\n", tensor.Shape)
79+
if tensor.Tensor != nil {
80+
fmt.Print(" Values: [")
81+
for i, value := range tensor.GetDoubleTensor().GetData() {
82+
if i > 0 {
83+
fmt.Print(", ")
84+
}
85+
fmt.Printf("%.4f", value)
86+
}
87+
fmt.Println("]")
88+
} else {
89+
fmt.Println(" No values available.")
90+
}
91+
}
92+
} else {
93+
fmt.Println(" No output tensors.")
94+
}
95+
96+
fmt.Println("Annotations:")
97+
if resp.Annotations != nil {
98+
for _, bbox := range resp.Annotations.Bboxes {
99+
fmt.Printf(" Bounding Box ID: %s, Label: %s\n", bbox.Id, bbox.Label)
100+
fmt.Printf(" Coordinates: [%f, %f, %f, %f]\n", bbox.XMinNormalized, bbox.YMinNormalized, bbox.XMaxNormalized, bbox.YMaxNormalized)
101+
if bbox.Confidence != nil {
102+
fmt.Printf(" Confidence: %.4f\n", *bbox.Confidence)
103+
}
104+
}
105+
for _, classification := range resp.Annotations.Classifications {
106+
fmt.Printf(" Classification Label: %s\n", classification.Label)
107+
if classification.Confidence != nil {
108+
fmt.Printf(" Confidence: %.4f\n", *classification.Confidence)
109+
}
110+
}
111+
} else {
112+
fmt.Println(" No annotations.")
113+
}
114+
}

0 commit comments

Comments
 (0)