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:
- 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
- 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')
- Run tensorboard from the terminal:
tensorboard --logdir /home/ubuntu/foo --port 8080
Expected behaviour:
- Tensorboad 3D tab appears in tensorboard.
- If you navigate manually to Tensorboard 3D in the plugin tab, a volume would be rendered.
Actual Behaviour:
- Tensorboad 3D tab does not appear in tensorboard.
- 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...
. - There is an error in the stack trace as mentioned earlier.
@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:
- The tag that is passed in must be either
image
orlabel
, as this is how the plugin identifies what to load and what role the data has. Changing the tag should fix your issue. - 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.
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!
@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.