(node: Leaf)
| 43 | |
| 44 | |
| 45 | def _leaf_vis(node: Leaf): |
| 46 | if node._log_probabilities: |
| 47 | ws = copy.deepcopy(torch.exp(node.distribution()).cpu().detach().numpy()) |
| 48 | else: |
| 49 | ws = copy.deepcopy(node.distribution().cpu().detach().numpy()) |
| 50 | |
| 51 | ws = np.ones(ws.shape) - ws |
| 52 | ws *= 255 |
| 53 | |
| 54 | height = 24 |
| 55 | |
| 56 | if ws.shape[0] < 36: |
| 57 | img_size = 36 |
| 58 | else: |
| 59 | img_size = ws.shape[0] |
| 60 | scaler = math.ceil(img_size/ws.shape[0]) |
| 61 | |
| 62 | img = Image.new('F', (ws.shape[0]*scaler, height)) |
| 63 | pixels = img.load() |
| 64 | |
| 65 | for i in range(scaler*ws.shape[0]): |
| 66 | for j in range(height-10): |
| 67 | pixels[i,j]=ws[int(i/scaler)] |
| 68 | for j in range(height-10,height-9): |
| 69 | pixels[i,j]=0 #set bottom line of leaf distribution black |
| 70 | for j in range(height-9,height): |
| 71 | pixels[i,j]=255 #set bottom part of node white such that class label is readable |
| 72 | |
| 73 | if scaler*ws.shape[0]>100: |
| 74 | img=img.resize((100,height)) |
| 75 | return img |
| 76 | |
| 77 | |
| 78 | def _branch_vis(node: Branch, upsample_dir: str): |
no test coverage detected