Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
idonahum1 committed May 22, 2024
1 parent 8f8763a commit 2db6504
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
parser.add_argument("--negative_prompt", type=str, default=None, help="Prompt template for negative images")


def preprocess_image_for_inference(image_path, tokenizer, template="a photo of a {}", placeholder_token="*", size=512, interpolation="bicubic"):
def preprocess_image_for_inference(image_path, tokenizer, template="a photo of a {}", placeholder_token="*",negative_prompt=None, size=512, interpolation="bicubic"):
"""Preprocess an image for inference.
Args:
Expand All @@ -49,7 +49,7 @@ def preprocess_image_for_inference(image_path, tokenizer, template="a photo of a
raw_image = Image.open(image_path)
if (raw_image.mode != "RGB"):
raw_image = raw_image.convert("RGB")
example = prepare_prompt(tokenizer, template, placeholder_token)
example = prepare_prompt(tokenizer, template, placeholder_token, negative_prompt=negative_prompt)
example["pixel_values_clip"] = CLIPImageProcessor()(images=raw_image, return_tensors="pt").pixel_values
example["pixel_values"] = preprocess_image(raw_image, size=size, interpolation=interpolation).unsqueeze(0)
return example
Expand All @@ -70,7 +70,7 @@ def preprocess_image_for_inference(image_path, tokenizer, template="a photo of a
image_adapter.to(device)
text_adapter.to(device)

example = preprocess_image_for_inference(args.input_image_path, tokenizer, template=args.text)
example = preprocess_image_for_inference(args.input_image_path, tokenizer, template=args.text, negative_prompt=args.negative_prompt)

with torch.no_grad():
generated_images = run_inference(
Expand Down

0 comments on commit 2db6504

Please sign in to comment.