0
$\begingroup$

I'm loading images from my dataset, which are all of resolution 200x200 and in RGB format.

I'm loading them using OpenCV for Python, with the following code:

images = []
for image in os.listdir(path):
  image = cv2.imread(str(path)+"/"+str(image)) 
  image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB) 
  images.append(image) 
images = np.array(images)

and the code is working just fine. However, what I'm trying to do next is normalize the images by diving their color information by 255, to get numbers between 0 and 1 for later use in CNN.

I tried the following code but I get out of memory errors and it doesn't work:

images = []
for image in os.listdir(path):
  image = cv2.imread(str(path)+"/"+str(image)) 
  image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB) 
  image = image/255
  images.append(image) 
images = np.array(images)

How can I achieve my desired results?

I looked up data preprocessing in tf.keras but not sure how to use it.

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.