Perception encoder inference models
InferenceModelsPerceptionEncoderAdapter
¶
Bases: Model
Roboflow Perception Encoder model implementation.
This class is responsible for handling the Percpetion Encoder model, including loading the model, preprocessing the input, and performing inference.
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
compare(subject, prompt, subject_type='image', prompt_type='text', **kwargs)
¶
Compares the subject with the prompt to calculate similarity scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject
|
Any
|
The subject data to be compared. Can be either an image or text. |
required |
prompt
|
Any
|
The prompt data to be compared against the subject. Can be a single value (image/text), list of values, or dictionary of values. |
required |
subject_type
|
str
|
Specifies the type of the subject data. Must be either "image" or "text". Defaults to "image". |
'image'
|
prompt_type
|
Union[str, List[str], Dict[str, Any]]
|
Specifies the type of the prompt data. Can be "image", "text", list of these types, or a dictionary containing these types. Defaults to "text". |
'text'
|
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[List[float], Dict[str, float]]
|
Union[List[float], Dict[str, float]]: A list or dictionary containing cosine similarity scores between the subject and prompt(s). |
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
embed_image(image, **kwargs)
¶
Embeds an image or a list of images using the PE-CLIP model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Any
|
The image or list of images to be embedded. |
required |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The embeddings of the image(s) as a numpy array. |
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
embed_text(text, **kwargs)
¶
Embeds a text or a list of texts using the PE-CLIP model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
Union[str, List[str]]
|
The text string or list of text strings to be embedded. |
required |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The embeddings of the text or texts as a numpy array. |
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
infer(image, **kwargs)
¶
Embeds an image
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
259 260 261 | |
infer_from_request(request)
¶
Routes the request to the appropriate inference function.
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
make_compare_response(similarities)
¶
Creates a PerceptionEncoderCompareResponse object from the provided similarity data.
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
140 141 142 143 144 145 | |
make_embed_image_response(embeddings)
¶
Converts the given embeddings into a PerceptionEncoderEmbeddingResponse object.
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
211 212 213 214 215 216 | |
make_embed_text_response(embeddings)
¶
Converts the given text embeddings into a PerceptionEncoderEmbeddingResponse object.
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
218 219 220 221 222 223 | |
predict(img_in, **kwargs)
¶
Predict embeddings for an input tensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img_in
|
Tensor
|
The input tensor to get embeddings for. |
required |
**kwargs
|
Additional keyword arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
Tuple[ndarray]
|
Tuple[np.ndarray]: A tuple containing the embeddings as a numpy array. |
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
198 199 200 201 202 203 204 205 206 207 208 209 | |
preproc_image(image)
¶
Preprocesses an inference request image.
Source code in inference/models/perception_encoder/perception_encoder_inference_models.py
69 70 71 | |