|
@@ -1,4 +1,4 @@
|
|
|
-// Copyright 2022 EMQ Technologies Co., Ltd.
|
|
|
+// Copyright 2022-2023 EMQ Technologies Co., Ltd.
|
|
|
//
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
// you may not use this file except in compliance with the License.
|
|
@@ -44,6 +44,7 @@ type interpreterManager struct {
|
|
|
}
|
|
|
|
|
|
func (m *interpreterManager) GetOrCreate(name string) (*tflite.Interpreter, error) {
|
|
|
+ log := conf.Log
|
|
|
m.Lock()
|
|
|
defer m.Unlock()
|
|
|
ip, ok := m.registry[name]
|
|
@@ -51,8 +52,10 @@ func (m *interpreterManager) GetOrCreate(name string) (*tflite.Interpreter, erro
|
|
|
mf := filepath.Join(m.path, name+".tflite")
|
|
|
model := tflite.NewModelFromFile(mf)
|
|
|
if model == nil {
|
|
|
+ log.Errorf("fail to load model: %s", mf)
|
|
|
return nil, fmt.Errorf("fail to load model: %s", mf)
|
|
|
}
|
|
|
+ log.Infof("success load model: %s", mf)
|
|
|
defer model.Delete()
|
|
|
options := tflite.NewInterpreterOptions()
|
|
|
options.SetNumThread(4)
|
|
@@ -63,9 +66,11 @@ func (m *interpreterManager) GetOrCreate(name string) (*tflite.Interpreter, erro
|
|
|
ip = tflite.NewInterpreter(model, options)
|
|
|
status := ip.AllocateTensors()
|
|
|
if status != tflite.OK {
|
|
|
+ log.Errorf("allocate tensors failed for: %s", mf)
|
|
|
ip.Delete()
|
|
|
return nil, fmt.Errorf("allocate failed: %v", status)
|
|
|
}
|
|
|
+ log.Infof("success allocate tensors for: %s", mf)
|
|
|
m.registry[name] = ip
|
|
|
}
|
|
|
return ip, nil
|