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

Accelerator Fix and Local Image Load Support #10

Open
wants to merge 3 commits 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
15 changes: 11 additions & 4 deletions finetune_instruct_pix2pix.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,16 @@ def convert_to_np(image, resolution):
image = image.convert("RGB").resize((resolution, resolution))
return np.array(image).transpose(2, 0, 1)

def load_image(source):
if source.startswith('http'):
# Download image from URL
response = requests.get(source, stream=True)
response.raise_for_status()
image = PIL.Image.open(response.raw)
Comment on lines +438 to +442
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can simply use load_image() from diffusers.utils for this.

else:
# Open image from local path
image = PIL.Image.open(source)

def download_image(url):
image = PIL.Image.open(requests.get(url, stream=True).raw)
image = PIL.ImageOps.exif_transpose(image)
image = image.convert("RGB")
return image
Expand All @@ -462,7 +469,7 @@ def main():
gradient_accumulation_steps=args.gradient_accumulation_steps,
mixed_precision=args.mixed_precision,
log_with=args.report_to,
logging_dir=logging_dir,
project_dir=logging_dir,
project_config=accelerator_project_config,
)

Expand Down Expand Up @@ -1075,7 +1082,7 @@ def collate_fn(examples):
pipeline.set_progress_bar_config(disable=True)

# run inference
original_image = download_image(args.val_image_url)
load_image(args.val_image_url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

load_image() doesn't return anything and is neither a closure inside main() so, I am sure about the effectivity of this.

edited_images = []
with torch.autocast(
str(accelerator.device),
Expand Down