juanpablomesa commited on
Commit
af56925
·
1 Parent(s): 682ae47

Fixed normalization error when only 1 image is sent to endpoint

Browse files
Files changed (1) hide show
  1. handler.py +5 -6
handler.py CHANGED
@@ -219,13 +219,14 @@ class EndpointHandler:
219
  # get image embeddings
220
  batch_emb = self.model_clip.get_image_features(pixel_values=batch)
221
  # detach text emb from graph, move to CPU, and convert to numpy array
222
- # Check the shape of the tensor before squeezing
223
- # if batch_emb.dim() > 1 and batch_emb.shape[0] == 1:
224
  self.logger.info(
225
  f"Shape of batch_emb after get_image_features: {batch_emb.shape}"
226
  )
227
 
228
- batch_emb = batch_emb.squeeze(0)
 
 
229
  self.logger.info(
230
  f"Shape of batch_emb after squeeze: {batch_emb.shape}"
231
  )
@@ -239,9 +240,7 @@ class EndpointHandler:
239
  )
240
  # transpose back to (21, 512)
241
  batch_emb = batch_emb.T.tolist()
242
- self.logger.info(
243
- f"Shape of batch_emb after transpose (2D case): {batch_emb.shape}"
244
- )
245
  embedding_end_time = timeit.default_timer()
246
  self.logger.info(
247
  f"Embedding calculation took {embedding_end_time - embedding_start_time} seconds"
 
219
  # get image embeddings
220
  batch_emb = self.model_clip.get_image_features(pixel_values=batch)
221
  # detach text emb from graph, move to CPU, and convert to numpy array
222
+
 
223
  self.logger.info(
224
  f"Shape of batch_emb after get_image_features: {batch_emb.shape}"
225
  )
226
 
227
+ # Check the shape of the tensor before squeezing
228
+ if batch_emb.shape[0] > 1:
229
+ batch_emb = batch_emb.squeeze(0)
230
  self.logger.info(
231
  f"Shape of batch_emb after squeeze: {batch_emb.shape}"
232
  )
 
240
  )
241
  # transpose back to (21, 512)
242
  batch_emb = batch_emb.T.tolist()
243
+
 
 
244
  embedding_end_time = timeit.default_timer()
245
  self.logger.info(
246
  f"Embedding calculation took {embedding_end_time - embedding_start_time} seconds"