Skip to content

Instantly share code, notes, and snippets.

@jurand71
Created November 15, 2022 18:05
Show Gist options
  • Save jurand71/b5d17b599a1c0c6ad220a9067fa090e4 to your computer and use it in GitHub Desktop.
Save jurand71/b5d17b599a1c0c6ad220a9067fa090e4 to your computer and use it in GitHub Desktop.
def prepare_image_Xy(df):
train_image_X = []
train_image_y = []
for n in range(len(df) - 1):
img = cv2.imread(str(df.iloc[n].path), cv2.IMREAD_GRAYSCALE)
height, width = img.shape
ratio = float(height/width)
if ratio > 0.6:
img_pred = cv2.resize(img, (81,81), interpolation=cv2.INTER_AREA)
img_pred = img_to_array(img_pred)
img_pred = img_pred / 255
train_image_X.append(img_pred)
train_image_y.append(df.iloc[n].label)
X = np.array(train_image_X)
y = np.array(train_image_y)
return X,y
X_train, y_train = prepare_image_Xy(train)
X_test, y_test = prepare_image_Xy(test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment