NVIDIA DeepStream SDK API Reference

9.2 Release
sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef REIDLIB_REIDFEATUREGALLERY_HPP_
19 #define REIDLIB_REIDFEATUREGALLERY_HPP_
20 
21 #include <map>
22 #include <deque>
23 #include <vector>
24 #include "modules/utility/cuda_common.hpp"
25 #include "modules/NvMultiObjectTracker/NvMultiObjectTracker_common.hpp"
26 
29 {
30 public:
33 
36 
45  void initialize(
46  const int reidFeatureSize, const int reidHistorySize, const uint32_t maxStreams,
47  const int maxTargetsPerStream, const int debugVerboseLevel
48  );
49 
56  int getReidFeatureIndGlobal(const NvMOTStreamId videoStreamId, uint targetInd);
57 
63  int getReidFeatureOffset(const NvMOTStreamId videoStreamId) const
64  {
65  auto it = m_reidFeatureOffsets.find(videoStreamId);
66  return (it == m_reidFeatureOffsets.end()) ? -1 : it->second;
67  }
68 
74  void remove(const NvMOTStreamId videoStreamId, const std::vector<int>& reidFeatureInds);
75 
80  void removeStream(const NvMOTStreamId videoStreamId);
81 
88  bool updateReIDFeature(
89  const NvMOTStreamId videoStreamId, const DetectedObjInfo *detObj, const std::shared_ptr<NvTrackedObject> target
90  );
91 
96  void removeStreamReIDFeature(const NvMOTStreamId videoStreamId);
97 
103  void removeTrackerReIDFeature(const NvMOTStreamId videoStreamId, const std::shared_ptr<NvTrackedObject> target);
104 
111  void fuseReidFeatureInd(const NvMOTStreamId videoStreamId, uint targetIndKept, uint targetIndFused);
112 
118  const int getLastInd(const NvMOTStreamId streamId) const;
119 
125  const float* getReIDFeaturePtrs(const NvMOTStreamId streamId) const;
126 
129 
131  const int getReIDHistorySize() const { return m_reidHistorySize; }
132 
137  const std::vector<int>& getTargetReIDFeatureInds(uint targetInd) const \
138  {
139  return m_reidFeatureIndsTargets.at(targetInd);
140  }
141 
146  const int getTargetReIDFeatureNextInd(uint targetInd) const \
147  {
148  return m_reidFeatureNextIndTargets.at(targetInd);
149  }
150 
156  {
157  m_reidFeatureIndsTargets.at(targetInd).clear();
158  m_reidFeatureNextIndTargets[targetInd] = 0;
159  }
160 
166  void updateTargetReIDFeatureInd(uint targetInd, int featureInd)
167  {
168  if ( int(m_reidFeatureIndsTargets.at(targetInd).size()) < m_reidHistorySize )
169  m_reidFeatureIndsTargets.at(targetInd).push_back(featureInd);
170  else
171  m_reidFeatureIndsTargets.at(targetInd)[m_reidFeatureNextIndTargets.at(targetInd)] = featureInd;
172 
174  }
175 
180  void printFeatureInds(uint targetInd) const
181  {
182  for (auto featureInd : m_reidFeatureIndsTargets.at(targetInd))
183  {
184  std::cout << featureInd << ", ";
185  }
186  }
187 
188  #ifdef VIZ_DEBUG
189 
193  void dumpReIDFeatureGallery(std::string filename);
194  #endif
195 
196 protected:
201  std::map<NvMOTStreamId, int> m_reidFeatureOffsets;
202  std::deque<int> m_reidFeatureOffsetsInPool;
203  std::map<NvMOTStreamId, std::set<int>> m_reidFeatureIndsInPool;
204  std::map<NvMOTStreamId, int> m_lastInds;
205  std::map<uint, std::vector<int>> m_reidFeatureIndsTargets;
206  std::map<uint, uint> m_reidFeatureNextIndTargets;
209  bool m_isInit;
210 };
211 
212 #endif // REIDLIB_REIDFEATUREGALLERY_HPP_
ReIDFeatureGallery::remove
void remove(const NvMOTStreamId videoStreamId, const std::vector< int > &reidFeatureInds)
Remove reid feature of given indices.
ReIDFeatureGallery::getTargetReIDFeatureNextInd
const int getTargetReIDFeatureNextInd(uint targetInd) const
Get the next circular-history slot for a target.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:146
ReIDFeatureGallery::getReidFeatureIndGlobal
int getReidFeatureIndGlobal(const NvMOTStreamId videoStreamId, uint targetInd)
For a new reid feature to add, determine its position in feature gallery and return the global index ...
ReIDFeatureGallery::getReIDHistorySize
const int getReIDHistorySize() const
Get the configured per-target feature history size.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:131
ReIDFeatureGallery::~ReIDFeatureGallery
~ReIDFeatureGallery()
Release resources owned by the ReIDFeatureGallery instance.
ReIDFeatureGallery::m_reidFeatureOffsetsInPool
std::deque< int > m_reidFeatureOffsetsInPool
Reid feature pointers in pool when unused.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:202
ReIDFeatureGallery::m_reidFeatureGallery_d
float * m_reidFeatureGallery_d
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:207
ReIDFeatureGallery::fuseReidFeatureInd
void fuseReidFeatureInd(const NvMOTStreamId videoStreamId, uint targetIndKept, uint targetIndFused)
Merge fused targets' reid features into its peer.
ReIDFeatureGallery::m_reidFeatureSize
int m_reidFeatureSize
Size of each reid feature.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:200
cudaStream_t
struct CUstream_st * cudaStream_t
Forward declaration of cudaStream_t.
Definition: includes/nvbufsurftransform.h:40
ReIDFeatureGallery::m_reidHistorySize
int m_reidHistorySize
Max number of reid features per object.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:199
ReIDFeatureGallery::m_reidFeatureOffsets
std::map< NvMOTStreamId, int > m_reidFeatureOffsets
Reid feature gallery indices being used by each stream, {streamID, ptr}.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:201
ReIDFeatureGallery::updateTargetReIDFeatureInd
void updateTargetReIDFeatureInd(uint targetInd, int featureInd)
Record a feature index for a target.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:166
uint
unsigned int uint
Definition: sources/libs/nvmultiobjecttracker/include/modules/cuDCFv2/helper_math.h:25
ReIDFeatureGallery::getTargetReIDFeatureInds
const std::vector< int > & getTargetReIDFeatureInds(uint targetInd) const
Get the gallery feature indices retained for a target.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:137
ReIDFeatureGallery::printFeatureInds
void printFeatureInds(uint targetInd) const
Print the feature indices retained for a target.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:180
ReIDFeatureGallery::m_cuStream
cudaStream_t m_cuStream
CUDA stream.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:208
ReIDFeatureGallery::m_reidFeatureIndsTargets
std::map< uint, std::vector< int > > m_reidFeatureIndsTargets
Each target's reid feature indices.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:205
ReIDFeatureGallery::m_isInit
bool m_isInit
If initialized.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:209
ReIDFeatureGallery::resetTargetReIDFeatureInds
void resetTargetReIDFeatureInds(uint targetInd)
Reset the feature indices retained for a target.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:155
ReIDFeatureGallery::m_reidFeatureNextIndTargets
std::map< uint, uint > m_reidFeatureNextIndTargets
Each target's next circular-history slot for a reid feature.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:206
ReIDFeatureGallery::removeStream
void removeStream(const NvMOTStreamId videoStreamId)
Remove a stream's all reid features.
ReIDFeatureGallery::ReIDFeatureGallery
ReIDFeatureGallery()
Construct a ReIDFeatureGallery instance.
ReIDFeatureGallery::removeStreamReIDFeature
void removeStreamReIDFeature(const NvMOTStreamId videoStreamId)
Remove reid feature gallery and each target's record.
ReIDFeatureGallery::removeTrackerReIDFeature
void removeTrackerReIDFeature(const NvMOTStreamId videoStreamId, const std::shared_ptr< NvTrackedObject > target)
Remove a target's reid features from the gallery.
NvMOTStreamId
uint64_t NvMOTStreamId
Definition: includes/nvdstracker.h:53
ReIDFeatureGallery::getReidFeatureOffset
int getReidFeatureOffset(const NvMOTStreamId videoStreamId) const
Get the global-gallery offset of a stream's partition.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:63
ReIDFeatureGallery::m_lastInds
std::map< NvMOTStreamId, int > m_lastInds
Index of last feature gallery being used in each stream.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:204
ReIDFeatureGallery::m_reidFeatureGallery_h
float * m_reidFeatureGallery_h
CUDA array saving target features in past frames.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:207
DetectedObjInfo
Detected object info obtained from input metadata.
Definition: sources/libs/nvmultiobjecttracker/include/modules/NvMultiObjectTracker/NvMultiObjectTracker_common.hpp:72
ReIDFeatureGallery::initialize
void initialize(const int reidFeatureSize, const int reidHistorySize, const uint32_t maxStreams, const int maxTargetsPerStream, const int debugVerboseLevel)
Allocate feature-gallery storage and initialize stream partitions.
ReIDFeatureGallery::m_reidFeatureIndsInPool
std::map< NvMOTStreamId, std::set< int > > m_reidFeatureIndsInPool
Feature gallery indices in pool.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:203
ReIDFeatureGallery::m_maxTargetsPerStream
int m_maxTargetsPerStream
Max targets per stream.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:198
ReIDFeatureGallery::m_debugVerboseLevel
int m_debugVerboseLevel
Debug message verbose mode level.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:197
ReIDFeatureGallery
Stores and updates per-target ReID feature histories.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:28
ReIDFeatureGallery::getLastInd
const int getLastInd(const NvMOTStreamId streamId) const
Get the last feature gallery index in use for a stream.
ReIDFeatureGallery::updateReIDFeature
bool updateReIDFeature(const NvMOTStreamId videoStreamId, const DetectedObjInfo *detObj, const std::shared_ptr< NvTrackedObject > target)
Update reid feature gallery and each target's record.
ReIDFeatureGallery::getFirstReIDFeaturePtrs
float * getFirstReIDFeaturePtrs()
Get the start of the complete feature gallery.
Definition: sources/libs/nvmultiobjecttracker/include/modules/ReID/ReIDFeatureGallery.hpp:128
ReIDFeatureGallery::getReIDFeaturePtrs
const float * getReIDFeaturePtrs(const NvMOTStreamId streamId) const
Get the device pointer to a stream's feature gallery partition.