Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise appropriate exception during mask interpretation #359

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ bash scripts/download_data.sh

The input images and target masks should be in the `data/imgs` and `data/masks` folders respectively (note that the `imgs` and `masks` folder should not contain any sub-folder or any other files, due to the greedy data-loader). For Carvana, images are RGB and masks are black and white.

You can use your own dataset as long as you make sure it is loaded properly in `utils/data_loading.py`.
You can use your own dataset as long as you make sure it is loaded properly in `utils/data_loading.py`. For example, loading RGB-coded black and white masks will not work with the data-loading code as-is.


---
Expand Down
6 changes: 5 additions & 1 deletion utils/data_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ def preprocess(pil_img, scale, is_mask):
pil_img = pil_img.resize((newW, newH), resample=Image.NEAREST if is_mask else Image.BICUBIC)
img_ndarray = np.asarray(pil_img)

if not is_mask:
if is_mask:
if img_ndarray.ndim > 2:
# customize this function if you want it to support RGB masks
raise RuntimeError("Only black-and-white images are supported as masks.")
else:
if img_ndarray.ndim == 2:
img_ndarray = img_ndarray[np.newaxis, ...]
else:
Expand Down