Skip to content

Commit

Permalink
In Compose, replace lambda function with named function (openai#151)
Browse files Browse the repository at this point in the history
This prevents the following error on Windows (when using
a multi-process DataLoader, for example):

AttributeError: Can't pickle local object '_transform.<locals>.<lambda>'
  • Loading branch information
janluke authored Sep 24, 2021
1 parent 3b473b0 commit c13005f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion clip/clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ def _download(url: str, root: str):
return download_target


def _convert_image_to_rgb(image):
return image.convert("RGB")


def _transform(n_px):
return Compose([
Resize(n_px, interpolation=BICUBIC),
CenterCrop(n_px),
lambda image: image.convert("RGB"),
_convert_image_to_rgb,
ToTensor(),
Normalize((0.48145466, 0.4578275, 0.40821073), (0.26862954, 0.26130258, 0.27577711)),
])
Expand Down

0 comments on commit c13005f

Please sign in to comment.