raihanp commited on
Commit
b0f2d06
·
verified ·
1 Parent(s): f5de5fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -8,9 +8,13 @@ inference = torch.load('fine_tune_resnet.pth')
8
  inference.eval()
9
 
10
  def classifier(image):
11
- output = inference(test_transform(Image.open('/content/1000-ml-plastic-water-bottle-500x500.webp')).unsqueeze(0))
12
- _, prediction = torch.max(output,1)
13
- confidence = round(torch.softmax(output,1).max().item(),4)*100
 
 
 
 
14
 
15
  return f'{label_dict[prediction.item()]} (Confidence: {confidence}%)'
16
 
 
8
  inference.eval()
9
 
10
  def classifier(image):
11
+ if torch.cuda.is_available():
12
+ inference.cpu()
13
+
14
+ with torch.no_grad():
15
+ output = inference(test_transform(Image.open('/content/1000-ml-plastic-water-bottle-500x500.webp')).unsqueeze(0))
16
+ _, prediction = torch.max(output,1)
17
+ confidence = round(torch.softmax(output,1).max().item(),4)*100
18
 
19
  return f'{label_dict[prediction.item()]} (Confidence: {confidence}%)'
20