fix: Update production API base URL in documentation and configuration files. Correct the URL in the desktop app README, migration documentation, and Vite configuration. Enhance ONNX model feature handling in the processing pipeline to align with the updated feature set, ensuring compatibility with the latest model version. Add tests for feature extraction to validate changes.
This commit is contained in:
@@ -10,15 +10,18 @@ import (
|
||||
ort "github.com/yalue/onnxruntime_go"
|
||||
)
|
||||
|
||||
const defaultFeatureCount = 14
|
||||
|
||||
type InferenceMeta struct {
|
||||
Threshold float64 `json:"threshold"`
|
||||
FeatureColumns []string `json:"feature_columns"`
|
||||
}
|
||||
|
||||
type Predictor struct {
|
||||
session *ort.DynamicAdvancedSession
|
||||
threshold float64
|
||||
mu sync.Mutex
|
||||
session *ort.DynamicAdvancedSession
|
||||
threshold float64
|
||||
featureCount int
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
func NewPredictor(modelPath, metaPath string) (*Predictor, error) {
|
||||
@@ -41,6 +44,11 @@ func NewPredictor(modelPath, metaPath string) (*Predictor, error) {
|
||||
meta.Threshold = 0.5
|
||||
}
|
||||
|
||||
featureCount := len(meta.FeatureColumns)
|
||||
if featureCount == 0 {
|
||||
featureCount = defaultFeatureCount
|
||||
}
|
||||
|
||||
session, err := ort.NewDynamicAdvancedSession(
|
||||
modelPath,
|
||||
[]string{"float_input"},
|
||||
@@ -51,13 +59,21 @@ func NewPredictor(modelPath, metaPath string) (*Predictor, error) {
|
||||
return nil, fmt.Errorf("onnx session: %w", err)
|
||||
}
|
||||
|
||||
return &Predictor{session: session, threshold: meta.Threshold}, nil
|
||||
return &Predictor{
|
||||
session: session,
|
||||
threshold: meta.Threshold,
|
||||
featureCount: featureCount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *Predictor) Threshold() float64 {
|
||||
return p.threshold
|
||||
}
|
||||
|
||||
func (p *Predictor) FeatureCount() int {
|
||||
return p.featureCount
|
||||
}
|
||||
|
||||
func (p *Predictor) Close() error {
|
||||
if p.session != nil {
|
||||
p.session.Destroy()
|
||||
@@ -65,18 +81,24 @@ func (p *Predictor) Close() error {
|
||||
return ort.DestroyEnvironment()
|
||||
}
|
||||
|
||||
func (p *Predictor) PredictProba(features [][8]float32) ([]float64, error) {
|
||||
func (p *Predictor) PredictProba(features [][]float32) ([]float64, error) {
|
||||
if len(features) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
n := len(features)
|
||||
flat := make([]float32, 0, n*8)
|
||||
for _, row := range features {
|
||||
flat = append(flat, row[:]...)
|
||||
flat := make([]float32, 0, n*p.featureCount)
|
||||
for i, row := range features {
|
||||
if len(row) != p.featureCount {
|
||||
return nil, fmt.Errorf(
|
||||
"fila %d: se esperaban %d features, se recibieron %d (revisa pipeline vs inference.json)",
|
||||
i, p.featureCount, len(row),
|
||||
)
|
||||
}
|
||||
flat = append(flat, row...)
|
||||
}
|
||||
|
||||
inputShape := ort.NewShape(int64(n), 8)
|
||||
inputShape := ort.NewShape(int64(n), int64(p.featureCount))
|
||||
inputTensor, err := ort.NewTensor(inputShape, flat)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user