Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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('
|
| 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('
|
| 41 |
|
| 42 |
-
cam = GradCAM(model=model,use_cuda=
|
| 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, :]
|