Answers.Body: <p>You can rescale images to same size based on the classification model you are using (preferably 300x300). Also for preprocessing you can try some morphological operations and some brightness removal techniques from OpenCV-Python. One more factor that could have affected your accuracy might be the number of images, if you are having less number of images you can augment your dataset to come up with enough samples for training.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-20T07:52:46.180Z
Answers.LastActivityDate: 2021-05-20T07:52:46.180Z
Answers.UserDisplayName: Gourav Singh Bais
Answers.Body: <p>Why do not simply perform some bilinear or bicubic interpolation?</p>
  <p>Tensorflow and PyTorch deep learning frameworks have dedicated function to do this - <a href="https://pytorch.org/vision/stable/transforms.html#torchvision.transforms.Resize" rel="nofollow noreferrer">https://pytorch.org/vision/stable/transforms.html#torchvision.transforms.Resize</a> and <a href="https://www.tensorflow.org/api_docs/python/tf/image/resize" rel="nofollow noreferrer">https://www.tensorflow.org/api_docs/python/tf/image/resize</a> .</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-20T08:08:07.010Z
Answers.LastActivityDate: 2021-05-20T08:08:07.010Z
Answers.UserDisplayName: spiridon_the_sun_rotator
Answers.Body: <p>I would use the ImageDataGenerator.flow_from_directory. Documentation is <a href="https://keras.io/api/preprocessing/image/" rel="nofollow noreferrer">here</a>.  Make a train directory. Within it create 5 subdirectories one for each class and give them the desired class name. Place the associated images into the 5 class sub directories. Then use something like the code below. Set the image size to something standard particularly is you are using transfer learning. For MobileNet standard size is 224 X 224. You can use the Image Data Generator to augment your data for example set horizontal flip =True. You can also vary the brightness and rotation of the images.</p>
  <pre><code>tf.keras.preprocessing.image.ImageDataGenerator(
      featurewise_center=False,
      samplewise_center=False,
      featurewise_std_normalization=False,
      samplewise_std_normalization=False,
      zca_whitening=False,
      zca_epsilon=1e-06,
      rotation_range=0,
      width_shift_range=0.0,
      height_shift_range=0.0,
      brightness_range=None,
      shear_range=0.0,
      zoom_range=0.0,
      channel_shift_range=0.0,
      fill_mode=&quot;nearest&quot;,
      cval=0.0,
      horizontal_flip=True,
      vertical_flip=False,
      rescale=None,
      preprocessing_function=None,
      data_format=None,
      validation_split=0.0,
      dtype=None)
  #for flow from directory
  .flow_from_directory(
      directory,
      target_size=(256, 256),
      color_mode=&quot;rgb&quot;,
      classes=None,
      class_mode=&quot;categorical&quot;,
      batch_size=32,
      shuffle=True,
      seed=None,
      save_to_dir=None,
      save_prefix=&quot;&quot;,
      save_format=&quot;png&quot;,
      follow_links=False,
      subset=None,
      interpolation=&quot;nearest&quot;,
  )
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-08-23T04:06:52.457Z
Answers.LastActivityDate: 2022-10-31T05:59:10.533Z
Answers.LastEditDate: 2022-10-31T05:59:10.533Z
Answers.UserDisplayName: Gerry P
Body: <p>I am practicing with an image dataset which is having different dimensions. <a href="https://i.sstatic.net/FnnVo.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/FnnVo.png" alt="here is the sample images
  " /></a>
  If I simply crop and pad them to 1024X1024(the original images having smallest width is around 300 and largest is around 2400 and widths and heights of the images are not the same) I am not getting good val_accuracy. It's just giving 49% accuracy.
  How to do image processing to these images because the brightness of the images is also changing. My task is to classify them into 5 classes.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-08-21T21:06:04.483Z
Comments.Text: why don‘t you simply rescale the original image to some value, e.g. 300x300. Did you check for this?
Comments.UserDisplayName: Peter
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-08-23T10:06:43.543Z
Comments.Text: trained with images making them to size of 358X358(smallest size is having 358 as the width) and got the val_accuracy around 57%.
Comments.UserDisplayName: Ravi Teja
Tags: <deep-learning><computer-vision>
Title: How to train the images of various sizes?
UserDisplayName: Ravi Teja
ThreadText: # How to train the images of various sizes?
  
  (Asked by: username_0 on 2020-08-21)
  
  I am practicing with an image dataset which is having different dimensions. [![here is the sample images
  ](https://i.sstatic.net/FnnVo.png)](https://i.sstatic.net/FnnVo.png)
  If I simply crop and pad them to 1024X1024(the original images having smallest width is around 300 and largest is around 2400 and widths and heights of the images are not the same) I am not getting good val\_accuracy. It's just giving 49% accuracy.
  How to do image processing to these images because the brightness of the images is also changing. My task is to classify them into 5 classes.
  
  **Tags:** deep-learning, computer-vision
  > **Comments:**
  > **username_1**: why don‘t you simply rescale the original image to some value, e.g. 300x300. Did you check for this?  
  > **username_0**: trained with images making them to size of 358X358(smallest size is having 358 as the width) and got the val_accuracy around 57%.  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_2 on 2021-05-20. Score: 1
  
  You can rescale images to same size based on the classification model you are using (preferably 300x300). Also for preprocessing you can try some morphological operations and some brightness removal techniques from OpenCV-Python. One more factor that could have affected your accuracy might be the number of images, if you are having less number of images you can augment your dataset to come up with enough samples for training.
  
  
  ---
  
  ### Answer by username_3 on 2021-05-20. Score: 1
  
  Why do not simply perform some bilinear or bicubic interpolation?
  
  Tensorflow and PyTorch deep learning frameworks have dedicated function to do this - <https://pytorch.org/vision/stable/transforms.html#torchvision.transforms.Resize> and <https://www.tensorflow.org/api_docs/python/tf/image/resize> .
  
  
  ---
  
  ### Answer by username_4 on 2020-08-23. Score: 1
  
  I would use the ImageDataGenerator.flow_from_directory. Documentation is here.  Make a train directory. Within it create 5 subdirectories one for each class and give them the desired class name. Place the associated images into the 5 class sub directories. Then use something like the code below. Set the image size to something standard particularly is you are using transfer learning. For MobileNet standard size is 224 X 224. You can use the Image Data Generator to augment your data for example set horizontal flip =True. You can also vary the brightness and rotation of the images.
  tf.keras.preprocessing.image.ImageDataGenerator(
      featurewise_center=False,
      samplewise_center=False,
      featurewise_std_normalization=False,
      samplewise_std_normalization=False,
      zca_whitening=False,
      zca_epsilon=1e-06,
      rotation_range=0,
      width_shift_range=0.0,
      height_shift_range=0.0,
      brightness_range=None,
      shear_range=0.0,
      zoom_range=0.0,
      channel_shift_range=0.0,
      fill_mode="nearest",
      cval=0.0,
      horizontal_flip=True,
      vertical_flip=False,
      rescale=None,
      preprocessing_function=None,
      data_format=None,
      validation_split=0.0,
      dtype=None)
  #for flow from directory
  .flow_from_directory(
      directory,
      target_size=(256, 256),
      color_mode="rgb",
      classes=None,
      class_mode="categorical",
      batch_size=32,
      shuffle=True,
      seed=None,
      save_to_dir=None,
      save_prefix="",
      save_format="png",
      follow_links=False,
      subset=None,
      interpolation="nearest",
  )
  
  
  ---
  
  