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

Support for Pillow >= 8.3.0 #230

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions scripts/test_vistas_single_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
from dataset.transform import SegmentationTransform
from inplace_abn import InPlaceABN
from modules import DeeplabV3
import PIL
from PIL import Image, ImagePalette
from torch.utils.data import DataLoader
from torch.utils.data.distributed import DistributedSampler
from itertools import chain

parser = argparse.ArgumentParser(
description="Testing script for the Vistas segmentation model"
Expand Down Expand Up @@ -317,11 +319,18 @@ def load_snapshot(snapshot_file):
_PALETTE = np.concatenate(
[_PALETTE, np.zeros((256 - _PALETTE.shape[0], 3), dtype=np.uint8)], axis=0
)
_PALETTE = ImagePalette.ImagePalette(
palette=list(_PALETTE[:, 0]) + list(_PALETTE[:, 1]) + list(_PALETTE[:, 2]),
mode="RGB",
)

PIL_version = PIL.__version__.split('.')
if int(PIL_version[0])<8 or (int(PIL_version[0])==8 and int(PIL_version[1])<3):
_PALETTE = ImagePalette.ImagePalette(
palette=list(_PALETTE[:, 0]) + list(_PALETTE[:, 1]) + list(_PALETTE[:, 2]),
mode="RGB",
)
else:
_PALETTE = ImagePalette.ImagePalette(
palette=list(chain.from_iterable(_PALETTE)),
mode="RGB",
)

def get_pred_image(tensor, out_size, with_palette):
tensor = tensor.numpy()
Expand Down