Skip to content

Instantly share code, notes, and snippets.

@islem-esi
Created February 14, 2021 22:32
Show Gist options
  • Select an option

  • Save islem-esi/c9c742cd5784d90a6e65696ad65bfd38 to your computer and use it in GitHub Desktop.

Select an option

Save islem-esi/c9c742cd5784d90a6e65696ad65bfd38 to your computer and use it in GitHub Desktop.
prepare images for cnn
import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Conv2D, MaxPooling2D
import numpy as np
#reshape images to fit into the CNN model
img_list = np.zeros(shape = (len(images), h,w,1), dtype = np.uint8)
for j in range(len(images)):
img_list[j,:,:,0] = np.reshape(list(images[j]), (h,w))
img_list = img_list.astype('float32')
img_list /= 255
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment