Browse Source

fix(plugin): add more lon for tfLite plugin (#2103)

Signed-off-by: Jianxiang Ran <jianxiang.ran@emqx.io>
Signed-off-by: Jianxiang Ran <rxan_embedded@163.com>
superxan 1 year ago
parent
commit
9dd31a1b71
1 changed files with 6 additions and 1 deletions
  1. 6 1
      extensions/functions/tfLite/interpreters.go

+ 6 - 1
extensions/functions/tfLite/interpreters.go

@@ -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