Skip to content

Commit

Permalink
Merge pull request #16 from Doer-org/ml/feat/image-resizing
Browse files Browse the repository at this point in the history
feat(ml):リサイズ方法を変更
  • Loading branch information
ryoya0902 authored Nov 4, 2023
2 parents b9517fc + 4f63fcb commit ebdc8fd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
Binary file added ml/data/sample/poor_duck4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions ml/src/configs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class ChatGPTConfig:
@dataclass
class DiffusionConfig:
model: str = "data/stable-diffusion-v1-5"
max_size: int = 500
resize_size: int = 500
threshold: int = 128
dilation_num: int = 5
kernel_size: int = 5
dilation_num: int = 3
kernel_size: int = 3
padding: int = 10
seed: int = 42
device: str = "cuda" if torch.cuda.is_available() else "cpu"
Expand Down
21 changes: 7 additions & 14 deletions ml/src/image_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,13 @@ def resize_image(self, image):
width, height = image.size

if width > height:
if width > self.config.max_size:
ratio = self.config.max_size / width
new_width = self.config.max_size
new_height = int(height * ratio)
else:
new_width, new_height = width, height
ratio = self.config.max_size / width
new_width = self.config.max_size
new_height = int(height * ratio)
else:
if height > self.config.max_size:
ratio = self.config.max_size / height
new_height = self.config.max_size
new_width = int(width * ratio)
else:
new_width, new_height = width, height

ratio = self.config.max_size / height
new_height = self.config.max_size
new_width = int(width * ratio)
image = image.resize((new_width, new_height))
return image

Expand Down Expand Up @@ -69,8 +62,8 @@ def crop_image(self, image):
def convert(self, prompt: str, image, strength: float = 0.8):
image = image.convert("RGB")
image = self.crop_image(image)
image = self.dilate_line(image)
image = self.resize_image(image)
image = self.dilate_line(image)
image = self.model(
prompt=prompt,
image=image,
Expand Down

0 comments on commit ebdc8fd

Please sign in to comment.