Spaces:
Sleeping
Sleeping
Commit ·
bdd75a0
1
Parent(s): b332e79
Fix Grad-CAM gradient issue and add debug logging
Browse files149 unmodified lines1501511521531541556 unmodified lines162163164165166167168169170149 unmodified lines# Convert to Tensor [Batch, Channel, Depth, Height, Width]inp = torch.from_numpy(img_data_normalized).float().unsqueeze(0).unsqueeze(0)# Run Inferencewith torch.no_grad():outputs = model(inp)6 unmodified linesresults.append([label, float(probs[i])])print(f"Prediction result: {results}")# Generate Grad-CAM heatmap for the predicted classheatmap = grad_cam.generate_cam(inp, target_class=predicted_class)# Resize heatmap back to original scan sizeheatmap_resized = resize(heatmap, original_shape, mode='constant', anti_aliasing=True).astype(np.float32)149 unmodified lines1501511521531541551561576 unmodified lines164165166167168169170171172173174175176149 unmodified lines# Convert to Tensor [Batch, Channel, Depth, Height, Width]inp = torch.from_numpy(img_data_normalized).float().unsqueeze(0).unsqueeze(0)print(f"Input tensor shape: {inp.shape}, min: {inp.min()}, max: {inp.max()}")# Run Inferencewith torch.no_grad():outputs = model(inp)6 unmodified linesresults.append([label, float(probs[i])])print(f"Prediction result: {results}")print(f"Predicted class: {predicted_class} ({CLASS_LABELS[predicted_class]})")# Generate Grad-CAM heatmap for the predicted class# Need to create a new tensor that requires gradientsinp_grad = torch.from_numpy(img_data_normalized).float().unsqueeze(0).unsqueeze(0)inp_grad.requires_grad = Trueheatmap = grad_cam.generate_cam(inp_grad, target_class=predicted_class)# Resize heatmap back to original scan sizeheatmap_resized = resize(heatmap, original_shape, mode='constant', anti_aliasing=True).astype(np.float32)
app.py+7-1