Skip to content

Commit 48137ce

Browse files
committed
add png as default format
1 parent 6eb47c1 commit 48137ce

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

shark/examples/shark_inference/stable_diffusion/main.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,16 @@ def end_profiling(device):
283283
}
284284
prompt_slice = re.sub("[^a-zA-Z0-9]", "_", args.prompts[i][:15])
285285
img_name = f"{prompt_slice}_{args.seed}_{run}_{dt.now().strftime('%y%m%d_%H%M%S')}"
286-
pil_images[i].save(
287-
output_path / f"{img_name}.jpg", quality=95, subsampling=0
288-
)
286+
if args.output_img_format == "jpg":
287+
pil_images[i].save(
288+
output_path / f"{img_name}.jpg", quality=95, subsampling=0
289+
)
290+
else:
291+
pil_images[i].save(output_path / f"{img_name}.png", "PNG")
292+
if args.output_img_format not in ["png", "jpg"]:
293+
print(
294+
f"[ERROR] Format {args.output_img_format} is not supported yet."
295+
"saving image as png. Supported formats png / jpg"
296+
)
289297
with open(output_path / f"{img_name}.json", "w") as f:
290298
f.write(json.dumps(json_store, indent=4))

shark/examples/shark_inference/stable_diffusion/stable_args.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ def path_expand(s):
123123
help="other supported schedulers are [PNDM, DDIM, LMSDiscrete, EulerDiscrete, DPMSolverMultistep]",
124124
)
125125

126+
p.add_argument(
127+
"--output_img_format",
128+
type=str,
129+
default="png",
130+
help="specify the format in which output image is save. Supported options: jpg / png",
131+
)
132+
126133
p.add_argument(
127134
"--output_dir",
128135
type=str,

web/models/stable_diffusion/main.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,17 @@ def save_output_img(output_img):
8282
out_img_name = (
8383
f"{prompt_slice}_{args.seed}_{dt.now().strftime('%y%m%d_%H%M%S')}"
8484
)
85-
out_img_path = Path(generated_imgs_path, f"{out_img_name}.jpg")
86-
output_img.save(out_img_path, quality=95, subsampling=0)
85+
if args.output_img_format == "jpg":
86+
out_img_path = Path(generated_imgs_path, f"{out_img_name}.jpg")
87+
output_img.save(out_img_path, quality=95, subsampling=0)
88+
else:
89+
out_img_path = Path(generated_imgs_path, f"{out_img_name}.png")
90+
output_img.save(out_img_path, "PNG")
91+
if args.output_img_format not in ["png", "jpg"]:
92+
print(
93+
f"[ERROR] Format {args.output_img_format} is not supported yet."
94+
"saving image as png. Supported formats png / jpg"
95+
)
8796

8897
new_entry = {
8998
"VARIANT": args.variant,

web/models/stable_diffusion/stable_args.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@
117117
help="other supported schedulers are [PNDM, DDIM, LMSDiscrete, EulerDiscrete, DPMSolverMultistep]",
118118
)
119119

120+
p.add_argument(
121+
"--output_img_format",
122+
type=str,
123+
default="png",
124+
help="specify the format in which output image is save. Supported options: jpg / png",
125+
)
126+
120127
p.add_argument(
121128
"--output_dir",
122129
type=str,

0 commit comments

Comments
 (0)