Neylton commited on
Commit
63ccd82
·
1 Parent(s): 15b48fb

rolling back to good version

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -327,14 +327,14 @@ def transform_image(image_bytes):
327
  def get_prediction(image_tensor, model):
328
  """Get prediction from model - optimized"""
329
  try:
330
- with torch.no_grad():
331
  # Ensure tensor is on CPU for consistency
332
  if image_tensor.device.type != 'cpu':
333
  image_tensor = image_tensor.cpu()
334
 
335
- outputs = model(image_tensor)
336
- probabilities = torch.nn.functional.softmax(outputs[0], dim=0)
337
- top5_prob, top5_indices = torch.topk(probabilities, 5)
338
 
339
  # Convert to Python types immediately for faster processing
340
  top5_prob = top5_prob.cpu().numpy()
@@ -344,7 +344,7 @@ def get_prediction(image_tensor, model):
344
  for i in range(5):
345
  predictions.append({
346
  'food': CLASS_NAMES[top5_indices[i]],
347
- 'confidence': float(top5_prob[i] * 100)
348
  })
349
 
350
  return predictions
 
327
  def get_prediction(image_tensor, model):
328
  """Get prediction from model - optimized"""
329
  try:
330
+ with torch.no_grad():
331
  # Ensure tensor is on CPU for consistency
332
  if image_tensor.device.type != 'cpu':
333
  image_tensor = image_tensor.cpu()
334
 
335
+ outputs = model(image_tensor)
336
+ probabilities = torch.nn.functional.softmax(outputs[0], dim=0)
337
+ top5_prob, top5_indices = torch.topk(probabilities, 5)
338
 
339
  # Convert to Python types immediately for faster processing
340
  top5_prob = top5_prob.cpu().numpy()
 
344
  for i in range(5):
345
  predictions.append({
346
  'food': CLASS_NAMES[top5_indices[i]],
347
+ 'confidence': float(top5_prob[i] * 100)
348
  })
349
 
350
  return predictions