karolzak/ipyplot

Unable to open local image using url (local path).

sickerin opened this issue ยท 4 comments

I work on a shared GPU server (ubuntu). It seems I'm not able to open an image if it's in a folder like /data, or my colleague's workspace. I've tried converting the absolute path to relative paths, and it also doesn't work.

Hi @sickerin , thanks for reporting this issue.
Could you please provide some additional information:

  • Can you share more details about folders structure (absolute path to the data folder and your notebook folder)?
  • Which directory (absolute path) was your jupyter notebook server started from?

As you said it's possible that you can't display images from folders you don't have access to as a user, or your data directory is higher in the tree than the directory from which you're running your jupyter server. Check this thread for more details about this issue: #17 (comment)

Hi @karolzak, thanks for replying! The notebook folder was /home/workspace/myusername/repos/notebook.ipynb and the data folder was /data/somefolder.

Initally the jupyter notebook was started from the notebook folder, and I wasn't able to display images even when I used relative paths. When I started the jupyter server in root, /, I was able to display the images only if I used relative paths, absolute path still doesn't work.

This is the kind of error message in the console you might see.

[W 13:17:06.606 LabApp] 404 GET /files/data/image_folder/image_name.jpg?_xsrf=2%7C1d56d369%7Cd0df8a65daf3c24ec0017eeb20b4169f%7C1603708797&1605593825515 (::1) 2.09ms referer=http://localhost:9056/lab

I find it really weird that the jupyter server started on a lower dir can't access images above it. I looked through your code and it seems the way you display images is by putting the path directly to HTML right. I looked online to find if this was the issue and didn't find anything about it.

If this is the case that the HTML has issues accessing images if you just pass it thru src=, I think there should be some changes made, so that the package works in most cases without always having to specifically specify where the server starts.

I use it to view some images by label before training models. This is what my usage looks like, sample 10 images of each category, convert them to PIL images, then view. But ideally, the most convenient and intuitive way should be giving ipyplot a list of labels, and a list of image paths, then having ipyplot take care of sampling and choosing an image to show if I set max_images. The reason I'm converting to PIL images is that I can start a notebook/server in any dir, and PIL can access the photos. I'm sampling images beforehand because converting all the images will be too much since there are thousands per label.

I'm willing to help contribute!

Some suggestions would be to convert images using PIL when supplying the path to images. So, ippyplot chooses the images to display -> before displaying open images using PIL, and display it using base64.

Initally the jupyter notebook was started from the notebook folder, and I wasn't able to display images even when I used relative paths. When I started the jupyter server in root, /, I was able to display the images only if I used relative paths, absolute path still doesn't work.

Thanks @sickerin for coming back and confirming that!

I find it really weird that the jupyter server started on a lower dir can't access images above it.

That was weird for me as well but after some research I realized that this has something to do with the fact that HTML part of Jupyter Server is running in a local web server and I think (even more importantly) because it's the web browser that is responsible for getting/requesting the content and displaying it. And if I'm correct, web browser can't access that local file because it can only access what is being shared with it through that local web server (folders bellow the start directory). It's not possible for web browsers to have a free access to all the resources in local file system.

If this is the case that the HTML has issues accessing images if you just pass it thru src=, I think there should be some changes made, so that the package works in most cases without always having to specifically specify where the server starts.
[...]
Some suggestions would be to convert images using PIL when supplying the path to images. So, ippyplot chooses the images to display -> before displaying open images using PIL, and display it using base64.

Great suggestion and it actually is already implemented! ๐Ÿ˜„
Try something like below and let me know if that solves the problems you're facing:

ipyplot.plot_class_tabs(image_paths, labels, max_imgs_per_tab=10, force_b64=True)

Let me know if that works for you!

Thanks, the force_b64 is perfect, sorry I missed that ๐Ÿ˜…. It also works with absolute paths!