Skip to content

Commit

Permalink
maintain_aspect_ratio formula now maintains aspect ratio of loaded im…
Browse files Browse the repository at this point in the history
…ages.
  • Loading branch information
titu1994 committed Nov 28, 2016
1 parent 3d34253 commit 56eed72
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions script_helper/Script/INetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ def preprocess_image(image_path, load_dims=False, read_mode="color"):
aspect_ratio = img_HEIGHT / img_WIDTH

img_width = args.img_size
img_height = int(img_width * aspect_ratio)
if args.maintain_aspect_ratio:
img_height = int(img_width * aspect_ratio)
else:
img_height = args.img_size

img = imresize(img, (img_width, img_height)).astype('float32')

Expand Down Expand Up @@ -581,7 +584,7 @@ def grads(self, x):
if preserve_color and content is not None:
img = original_color_transform(content, img, mask=color_mask)

if maintain_aspect_ratio & (not rescale_image):
if not rescale_image:
img_ht = int(img_width * aspect_ratio)
print("Rescaling Image to (%d, %d)" % (img_width, img_ht))
img = imresize(img, (img_width, img_ht), interp=args.rescale_method)
Expand Down
7 changes: 5 additions & 2 deletions script_helper/Script/Network.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ def preprocess_image(image_path, load_dims=False, read_mode="color"):
aspect_ratio = img_HEIGHT / img_WIDTH

img_width = args.img_size
img_height = int(img_width * aspect_ratio)
if args.maintain_aspect_ratio:
img_height = int(img_width * aspect_ratio)
else:
img_height = args.img_size

img = imresize(img, (img_width, img_height)).astype('float32')

Expand Down Expand Up @@ -557,7 +560,7 @@ def grads(self, x):
if preserve_color and content is not None:
img = original_color_transform(content, img, mask=color_mask)

if maintain_aspect_ratio & (not rescale_image):
if not rescale_image:
img_ht = int(img_width * aspect_ratio)
print("Rescaling Image to (%d, %d)" % (img_width, img_ht))
img = imresize(img, (img_width, img_ht), interp=args.rescale_method)
Expand Down

0 comments on commit 56eed72

Please sign in to comment.