KitwareMedical / tensorboard-plugin-3d

Home Page:https://tensorboardplugin3d.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ZeroDivisionError for a Simple Example

siavashk opened this issue · comments

This plugin produces a ZeroDivisonError for a simple example. I installed the most recent version (1.0.3) from pypi. I have attached the full stack trace and the relevant portion of the error is the following:

...
 File "/home/ubuntu/anaconda3/envs/pytensorboard3d/lib/python3.8/site-packages/tensorboard_plugin_3d/plugin.py", line 80, in _serve_image
    data = self._find_next_images(1)
File "/home/ubuntu/anaconda3/envs/pytensorboard3d/lib/python3.8/site-packages/tensorboard_plugin_3d/plugin.py", line 173, in _find_next_images
    self.current_run = (int(idx) - 1) % len(self._all_runs)
ZeroDivisionError: integer division or modulo by zero

Steps to reproduce:

  1. Environment setup. The pip installation step is taken from here:
conda create -n pytensorboard3d python=3.8 -y
conda activate pytensorboard3d

pip install -q "monai-weekly[gdown, nibabel, tqdm, ignite]"
pip install -q matplotlib
pip install -q tensorboard-plugin-3d
  1. Write a simple cube to the summary:
from monai.visualize.img2tensorboard import plot_2d_or_3d_image
import torch
from torch.utils.tensorboard import SummaryWriter

def make_white_cube_batch():
    x = torch.zeros((8, 1, 100, 100, 100))
    x[:, :, 25:75, 25:75, 25:75] = 1
    return x

log_dir = '/home/ubuntu/foo'
sw = SummaryWriter(log_dir=log_dir)

batch = make_white_cube_batch()
plot_2d_or_3d_image(data=batch, step=1, writer=sw, tag='White Cube')
  1. Run tensorboard from the terminal:
tensorboard --logdir /home/ubuntu/foo --port 8080

Expected behaviour:

  1. Tensorboad 3D tab appears in tensorboard.
  2. If you navigate manually to Tensorboard 3D in the plugin tab, a volume would be rendered.

Actual Behaviour:

  1. Tensorboad 3D tab does not appear in tensorboard.
  2. If you navigate manually to Tensorboard 3D in the plugin tab, you get spinning wheel with the following message:
    Tensorboard 3D is loading, please wait....
  3. There is an error in the stack trace as mentioned earlier.

image

@siavashk thanks for the report 👍 @bnmajor please take a look

@siavashk I took a look at this and I am able to view the cube, but I can see where the problems that you are seeing are coming from. Important to note:

  1. The tag that is passed in must be either image or label, as this is how the plugin identifies what to load and what role the data has. Changing the tag should fix your issue.
  2. In TensorBoard plugins are made available if they have data to display. If the TensorBoard tab is not available it is because no data is being found. This is why you saw the infinitely spinning wheel.

cube

Thank you for sharing your issue though! This information is covered in the docs but I think that it should be made even clearer and probably re-iterated throughout the docs in a few more places. And I can look into a more useful message for others that select the plugin from the drop down in the future so that it is not a misleading progress bar.

I am going to close this for now but please feel free to re-open or add on if you have additional questions!

@bnmajor thank you for looking into this. I will try it out later today.

I didn't find the information in the docs though (maybe I am looking at the wrong place?). I looked here.

@siavashk Yes, that information is in the TensorBoardPlugin3D docs here (at the bottom of the Plot Images section directly above the Select Images to View section). But this is a bit buried and since, as you can see in the docs you were referencing, this differs from the MONAI docs a little I think we should make it more obvious.

Thank you. I can verify that this works.