def vis_on_batch(self, batch, savedir_image): self.eval() images = batch["images"].to(self.device) points = batch["points"].long().to(self.device) logits = self.model_base.forward(images) probs = logits.sigmoid().cpu().numpy() blobs = lcfcn_loss.get_blobs(probs=probs) pred_counts = (np.unique(blobs)!=0).sum() pred_blobs = blobs pred_probs = probs.squeeze() # loc pred_count = pred_counts.ravel()[0] pred_blobs = pred_blobs.squeeze() pred_points = lcfcn_loss.blobs2points(pred_blobs).squeeze() img_org = hu.get_image(batch["images"],denorm="rgb") i1 = convert(np.array(img_org), batch['points'][0], enlarge=20) i2 = convert(np.array(img_org), pred_blobs, enlarge=0) i3 = convert(np.array(img_org), pred_points, enlarge=20) hu.save_image(savedir_image, np.hstack([i1, i2, i3]))
def val_on_batch(self, batch): self.eval() images = batch["images"].to(self.device) points = batch["points"].long().to(self.device) logits = self.model_base.forward(images) probs = logits.sigmoid().cpu().numpy() blobs = lcfcn_loss.get_blobs(probs=probs) pred_points = lcfcn_loss.blobs2points(blobs).squeeze() mae = abs(float((np.unique(blobs)!=0).sum() - (points!=0).sum())) game = lcfcn_loss.compute_game(pred_points=pred_points.squeeze(), gt_points=points.squeeze().cpu().numpy(), L=3) return {'mae':mae, 'game':game }
def vis_on_batch(self, batch, savedir_image): self.eval() images = batch["images"].to('cpu') #helen changed this from .cuda() #print(images) #print(images.shape) points = batch["points"].long().to( 'cpu') #helen changed this from .cuda() logits = self.model.forward(images) probs = logits.sigmoid().cpu().numpy() blobs = lcfcn_loss.get_blobs(probs=probs) pred_counts = (np.unique(blobs) != 0).sum() pred_blobs = blobs pred_probs = probs.squeeze() # loc pred_count = pred_counts.ravel()[0] pred_blobs = pred_blobs.squeeze() img_org = hu.get_image(batch["images"], denorm="rgb") # true points y_list, x_list = np.where(batch["points"][0].long().numpy().squeeze()) img_peaks = hi.points_on_image(y_list, x_list, img_org, radius=11) text = "%s ground truth" % (batch["points"].sum().item()) hi.text_on_image(text=text, image=img_peaks) # pred points pred_points = lcfcn_loss.blobs2points(pred_blobs).squeeze() y_list, x_list = np.where(pred_points.squeeze()) img_pred = hi.mask_on_image(img_org, pred_blobs) #img_pred = hi.points_on_image(y_list, x_list, img_org) text = "%s predicted" % (len(y_list)) hi.text_on_image(text=text, image=img_pred) # *************** helen added this code plt.imshow( img_pred ) #these lines of code display the image with the model's predications on it plt.show() # *************** end of helen's code # heatmap heatmap = hi.gray2cmap(pred_probs) heatmap = hu.f2l(heatmap) hi.text_on_image(text="lcfcn heatmap", image=heatmap) img_mask = np.hstack([img_peaks, img_pred, heatmap]) hu.save_image(savedir_image, img_mask)
def vis_on_batch_helen(self, batch, savedir_image): self.eval() images = batch.to('cpu') #print(images) #print statement to check what images is for debugging #print(images.shape) #print statement to check images has the correct shape logits = self.model.forward(images) probs = logits.sigmoid().cpu().numpy() blobs = lcfcn_loss.get_blobs(probs=probs) pred_counts = (np.unique(blobs) != 0).sum() pred_blobs = blobs pred_probs = probs.squeeze() # loc pred_count = pred_counts.ravel()[0] pred_blobs = pred_blobs.squeeze() img_org = hu.get_image(images, denorm="rgb") #this is what was originally written: img_org = hu.get_image(batch["images"],denorm="rgb") #the following lines are commented out because my own data does not have labels and will thus throw errors # true points #y_list, x_list = np.where(batch["points"][0].long().numpy().squeeze()) #img_peaks = hi.points_on_image(y_list, x_list, img_org, radius=11) #text = "%s ground truth" % (batch["points"].sum().item()) #hi.text_on_image(text=text, image=img_peaks) # pred points pred_points = lcfcn_loss.blobs2points(pred_blobs).squeeze() y_list, x_list = np.where(pred_points.squeeze()) img_pred = hi.mask_on_image(img_org, pred_blobs) # img_pred = hi.points_on_image(y_list, x_list, img_org) text = "%s predicted" % (len(y_list)) hi.text_on_image(text=text, image=img_pred) # these lines of code display the image with the model's predications on it plt.imshow(img_pred) plt.show() # heatmap heatmap = hi.gray2cmap(pred_probs) heatmap = hu.f2l(heatmap) hi.text_on_image(text="lcfcn heatmap", image=heatmap) img_mask = np.hstack([img_pred, heatmap]) #helen took out im_peaks #this is what was originally written: img_mask = np.hstack([img_peaks, img_pred, heatmap]) hu.save_image(savedir_image, img_mask)
def vis_on_batch(self, batch, savedir_image): self.eval() images = batch["images"].cuda() points = batch["points"].long().cuda() logits = self.model_base.forward(images) probs = logits.sigmoid().cpu().numpy() blobs = lcfcn_loss.get_blobs(probs=probs) pred_counts = (np.unique(blobs)!=0).sum() pred_blobs = blobs pred_probs = probs.squeeze() # loc pred_count = pred_counts.ravel()[0] pred_blobs = pred_blobs.squeeze() img_org = hu.get_image(batch["images"],denorm="rgb") # true points y_list, x_list = np.where(batch["points"][0].long().numpy().squeeze()) img_peaks = haven_img.points_on_image(y_list, x_list, img_org) text = "%s ground truth" % (batch["points"].sum().item()) haven_img.text_on_image(text=text, image=img_peaks) # pred points pred_points = lcfcn_loss.blobs2points(pred_blobs).squeeze() y_list, x_list = np.where(pred_points.squeeze()) img_pred = hi.mask_on_image(img_org, pred_blobs) # img_pred = haven_img.points_on_image(y_list, x_list, img_org) text = "%s predicted" % (len(y_list)) haven_img.text_on_image(text=text, image=img_pred) # heatmap heatmap = hi.gray2cmap(pred_probs) heatmap = hu.f2l(heatmap) haven_img.text_on_image(text="lcfcn heatmap", image=heatmap) img_mask = np.hstack([img_peaks, img_pred, heatmap]) hu.save_image(savedir_image, img_mask)