Shreeraj commited on
Commit
93fcfa6
·
1 Parent(s): 4a64a60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -11,7 +11,7 @@ import matplotlib.pyplot as plt
11
 
12
 
13
  # Load the pre-trained model
14
- model = torch.load('model.pth', map_location=torch.device('cuda' if torch.cuda.is_available() else 'cpu'))
15
  model.eval()
16
 
17
  #define the target layer to pull for gradcam
@@ -37,9 +37,9 @@ def classify_image(inp, transperancy=0.8):
37
  #image = Image.fromarray((inp * 255).astype(np.uint8)) # Convert NumPy array to PIL Image
38
  #input_tensor = preprocess(image)
39
  input_tensor = preprocess(inp)
40
- input_batch = input_tensor.unsqueeze(0).to('cuda' if torch.cuda.is_available() else 'cpu') # Create a batch
41
 
42
- cam = GradCAM(model=model,use_cuda=True, target_layers=target_layers)
43
 
44
  grayscale_cam = cam(input_tensor=input_batch, targets=None)
45
  grayscale_cam = grayscale_cam[0, :]
 
11
 
12
 
13
  # Load the pre-trained model
14
+ model = torch.load('model.pth', map_location=torch.device('cpu'))
15
  model.eval()
16
 
17
  #define the target layer to pull for gradcam
 
37
  #image = Image.fromarray((inp * 255).astype(np.uint8)) # Convert NumPy array to PIL Image
38
  #input_tensor = preprocess(image)
39
  input_tensor = preprocess(inp)
40
+ input_batch = input_tensor.unsqueeze(0).to('cpu') # Create a batch
41
 
42
+ cam = GradCAM(model=model,use_cuda=False, target_layers=target_layers)
43
 
44
  grayscale_cam = cam(input_tensor=input_batch, targets=None)
45
  grayscale_cam = grayscale_cam[0, :]