Skip to content

Commit

Permalink
fix(plugin): add more lon for tfLite plugin (#2103)
Browse files Browse the repository at this point in the history
Signed-off-by: Jianxiang Ran <[email protected]>
Signed-off-by: Jianxiang Ran <[email protected]>
  • Loading branch information
superrxan committed Jul 18, 2023
1 parent 89d955d commit 9dd31a1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion extensions/functions/tfLite/interpreters.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -44,15 +44,18 @@ 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]
if !ok {
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)
Expand All @@ -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
Expand Down

0 comments on commit 9dd31a1

Please sign in to comment.