MCPcopy Create free account
hub / github.com/breeze-sys/Label-Only-MIA-Go / Predict

Method Predict

pkg/client/http_client.go:71–89  ·  view source on GitHub ↗

========================================== 3. 核心功能实现 (实现 core.Model 接口) ========================================== Predict: 获取最终标签

(img core.Image)

Source from the content-addressed store, hash-verified

69
70// Predict: 获取最终标签
71func (c *HTTPClient) Predict(img core.Image) (int, error) {
72 // 注意:根据 A 的接口规范,单图预测通常在 /predict 路径
73 endpoint := c.url + "/predict"
74
75 payload := requestBody{Image: img}
76 jsonData, _ := json.Marshal(payload)
77
78 resp, err := c.httpClient.Post(endpoint, "application/json", bytes.NewBuffer(jsonData))
79 if err != nil {
80 return -1, err
81 }
82 defer resp.Body.Close()
83
84 var result responseBody
85 if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
86 return -1, err
87 }
88 return result.Label, nil
89}
90
91// PredictLogits: 获取原始分数 (用于算方案一的 Loss) —— 【这是你最需要的改动】
92func (c *HTTPClient) PredictLogits(img core.Image) ([]float32, error) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected