xuebinqin / U-2-Net

The code for our newly accepted paper in Pattern Recognition 2020: "U^2-Net: Going Deeper with Nested U-Structure for Salient Object Detection."
Apache License 2.0
8.52k stars 1.47k forks source link

RescaleT:Why not prioritize maintaining the aspect ratio #356

Closed zhouchengfei closed 1 year ago

zhouchengfei commented 1 year ago
          Yes, it doesn't have to be used. This function is just the legacy of the

previous version, in which we were exploring the resizing while keeping the aspect ratio. In our paper, they are not used. We didn't delete them just in case someone wants to keep the aspect ratio.

On Tue, Jan 18, 2022 at 6:27 AM YangLiuly1 @.***> wrote:

Hi, l have a problem.

class RescaleT(object):

def init(self,output_size): assert isinstance(output_size,(int,tuple)) self.output_size = output_size

def call(self,sample): imidx, image, label = sample['imidx'], sample['image'],sample['label']

  h, w = image.shape[:2]

  if isinstance(self.output_size,int):
      if h > w:
          new_h, new_w = self.output_size*h/w,self.output_size
      else:
          new_h, new_w = self.output_size,self.output_size*w/h
  else:
      new_h, new_w = self.output_size

  new_h, new_w = int(new_h), int(new_w)

  # #resize the image to new_h x new_w and convert image from range [0,255] to [0,1]
  # img = transform.resize(image,(new_h,new_w),mode='constant')
  # lbl = transform.resize(label,(new_h,new_w),mode='constant', order=0, preserve_range=True)

  img = transform.resize(image,(self.output_size,self.output_size),mode='constant')
  lbl = transform.resize(label,(self.output_size,self.output_size),mode='constant', order=0, preserve_range=True)

  return {'imidx':imidx, 'image':img,'label':lbl}

Here, new_h and new_w maybe cannot use.

— Reply to this email directly, view it on GitHub https://github.com/xuebinqin/U-2-Net/issues/284, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADSGORNN4HPTNN6G42IEOYTUWTFZJANCNFSM5MGAAF4A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Xuebin Qin PhD Department of Computing Science University of Alberta, Edmonton, AB, Canada Homepage: https://xuebinqin.github.io/

Originally posted by @xuebinqin in https://github.com/xuebinqin/U-2-Net/issues/284#issuecomment-1015094799