1
  • I am trying to train a CNN model for an image processing problem statement. - I am facing a major issue in the preprocessing stage, where the train datasets of both train_rain and train_no_rain are not in the order I wish for them to be. This is affecting the performance of my model, as it is important for my model to ID an image with rain streaks and then the same image without them.

  • Any solutions to this issue?

  • Here are the samples of what I am trying to imply -

Say after reading the datasets as shown below:

    path_1 = "gdrive/My Drive/Rain100H/train/rainy"
    train_rain = []
    no_train_rain = 0

    gauss_img = []
    for img in glob.glob(path_1+"/*.png"):
      im = cv.imread(img)
      im = cv.resize(im,(128,128))

    #Gaussian Blur
    im_gb = cv.GaussianBlur(im,(5,5),0)
    gauss_img.append(im_gb)

    cv.waitKey()
    no_train_rain+=1
    train_rain.append(im)

    train_no_rain = []
    no_train_no_rain = 0

    path_2 = "gdrive/My Drive/Rain100H/train/no rain"

    for img in glob.glob(path_2+"/*.png"):
      im = cv.imread(img)
      im = cv.resize(im,(128,128))
    cv.waitKey()
    no_train_no_rain+=1
    train_no_rain.append(im)

Now I want to read the first images from train_rain and train_no_rain, AFTER converting them to numpy arrays. and I did that using this -

    import matplotlib.pyplot as plt

first image from train_rain

click here

    plt.imshow(train_rain[1])

first image from train_no_rain

click here

    plt.imshow(train_no_rain[1])

But ideally, the first image in train_no_rain should be:

this

PS: The datasets have all the images beforehand, it's just that they are not being read in a particular order.

Any sort of help would be much appreciated :)

Bilal
  • 3,191
  • 4
  • 21
  • 49
Vignesh P
  • 11
  • 1
  • @Bilal thanks for the reply, but now the code throws the following error after `for img in imgs:` `TypeError - NoneType object is not iterable` Another thing to note is that `print(type(imgs)` returns `` – Vignesh P Apr 05 '21 at 06:57
  • Found this on the internet - and it perfectly works! Do this: `path_1 = "gdrive/My Drive/real_rain_and_rainfree_1000/train/rain" imgs = glob.glob(path_1+"/*.png") imgs = sorted(imgs)` and then use imgs as: `for img in imgs:` – Vignesh P Apr 05 '21 at 07:40

0 Answers0