Safemotion Lib
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
fastreid.engine.defaults.DefaultPredictor Class Reference

Public Member Functions

 __init__ (self, cfg)
 
 __call__ (self, image)
 

Public Attributes

 cfg
 
 model
 

Detailed Description

Create a simple end-to-end predictor with the given config.
The predictor takes an BGR image, resizes it to the specified resolution,
runs the model and produces a dict of predictions.
This predictor takes care of model loading and input preprocessing for you.
If you'd like to do anything more fancy, please refer to its source code
as examples to build and use the model manually.
Attributes:
Examples:
.. code-block:: python
    pred = DefaultPredictor(cfg)
    inputs = cv2.imread("input.jpg")
    outputs = pred(inputs)

Definition at line 126 of file defaults.py.

Constructor & Destructor Documentation

◆ __init__()

fastreid.engine.defaults.DefaultPredictor.__init__ ( self,
cfg )

Definition at line 142 of file defaults.py.

142 def __init__(self, cfg):
143 self.cfg = cfg.clone() # cfg can be modified by model
144 self.cfg.defrost()
145 self.cfg.MODEL.BACKBONE.PRETRAIN = False
146 self.model = build_model(self.cfg)
147 self.model.eval()
148
149 Checkpointer(self.model).load(cfg.MODEL.WEIGHTS)
150

Member Function Documentation

◆ __call__()

fastreid.engine.defaults.DefaultPredictor.__call__ ( self,
image )
Args:
    image (torch.tensor): an image tensor of shape (B, C, H, W).
Returns:
    predictions (torch.tensor): the output features of the model

Definition at line 151 of file defaults.py.

151 def __call__(self, image):
152 """
153 Args:
154 image (torch.tensor): an image tensor of shape (B, C, H, W).
155 Returns:
156 predictions (torch.tensor): the output features of the model
157 """
158 inputs = {"images": image}
159 with torch.no_grad(): # https://github.com/sphinx-doc/sphinx/issues/4258
160 predictions = self.model(inputs)
161 # Normalize feature to compute cosine distance
162 features = F.normalize(predictions)
163 features = features.cpu().data
164 return features
165
166

Member Data Documentation

◆ cfg

fastreid.engine.defaults.DefaultPredictor.cfg

Definition at line 143 of file defaults.py.

◆ model

fastreid.engine.defaults.DefaultPredictor.model

Definition at line 146 of file defaults.py.


The documentation for this class was generated from the following file: