| | |
| | | |
| | | var Count = make(chan int) |
| | | |
| | | type wfOp func(a []byte, b string) float32 |
| | | type wfOp func(a, b []float32) float32 |
| | | |
| | | /** |
| | | * @param uint8, shardCnt must be pow of two |
| | |
| | | value interface{} |
| | | } |
| | | |
| | | func (s *ShardMap) Walk(wf wfOp, sourceFea []byte, baseScore float32) (targets []*protomsg.SdkCompareEach) { |
| | | func (s *ShardMap) Walk(wf wfOp, sourceFea []float32, baseScore float32) (targets []*protomsg.SdkCompareEach) { |
| | | var wg sync.WaitGroup |
| | | var lock sync.Mutex |
| | | for _, si := range s.shards { |
| | |
| | | |
| | | wg.Add(1) |
| | | |
| | | go func(st *shardItem, fw wfOp, sf []byte, baseSec float32) { |
| | | go func(st *shardItem, fn wfOp, srcFeat []float32, baseSec float32) { |
| | | defer wg.Done() |
| | | for _, feature := range st.data { |
| | | if eif, ok := feature.(*db.FeatureCacheBase); ok { |
| | | if item, ok := feature.(*db.FeatureCacheBase); ok { |
| | | score := float32(0) |
| | | score = fw(sf, eif.FaceFeature) |
| | | score = fn(srcFeat, item.FaceFeature) |
| | | if score > 0 && score >= baseScore { |
| | | lock.Lock() |
| | | targets = append(targets, &protomsg.SdkCompareEach{ |
| | | Id: eif.Id, |
| | | Id: item.Id, |
| | | CompareScore: score, |
| | | Tableid: eif.TableId, |
| | | Tableid: item.TableId, |
| | | }) |
| | | lock.Unlock() |
| | | } |