Skip to content

Commit

Permalink
pngs w alpha channel now work (convert to RGB)
Browse files Browse the repository at this point in the history
  • Loading branch information
zsxkib committed Jun 19, 2024
1 parent c7b2543 commit d5b0b98
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ def download_weights(url: str, dest: str) -> None:
class Predictor(BasePredictor):
def setup(self) -> None:
"""Load the model into memory to make running multiple predictions efficient"""

if not os.path.exists(MODEL_CACHE):
os.makedirs(MODEL_CACHE)

model_files = [
"models--InstantX--SD3-Controlnet-Canny.tar",
"models--stabilityai--stable-diffusion-3-medium-diffusers.tar",
Expand Down Expand Up @@ -154,9 +154,13 @@ def predict(

print(f"Using seed: {seed}")

# Preprocess the input image
input_image = Image.open(str(image_in))
if input_image.mode != "RGB":
input_image = input_image.convert("RGB")

# Canny preprocessing
image_to_canny = load_image(str(image_in))
image_to_canny = np.array(image_to_canny)
image_to_canny = np.array(input_image)
image_to_canny = cv2.Canny(image_to_canny, 100, 200)
image_to_canny = image_to_canny[:, :, None]
image_to_canny = np.concatenate(
Expand All @@ -182,6 +186,7 @@ def predict(
image = image.resize((w, h), Image.LANCZOS)

# Save the image with the specified format and quality
image = image.convert("RGB")
extension = output_format.lower()
extension = "jpeg" if extension == "jpg" else extension
output_path = f"output.{extension}"
Expand Down

0 comments on commit d5b0b98

Please sign in to comment.