Python Keras导入训练集验证集测试集,并进行数据预处理

import os

import numpy as np

from tqdm import tqdm #进度条

from glob import glob

from scipy import ndimage

from keras.preprocessing.image import ImageDataGeneratior

import keras

img_size = 255 # 自行更改

train_path = r'D:\CVML\Project\Heartchallenge_sound\Peter_HeartSound\Train_Valid_Test\train'

num_train = len( glob (train_path + r'**.jpg') ) #图片数量

x_train = np.zeros( (num_train, img_size, img_size, 3), dtype=np.uint8) #训练集

y_train = np.zeros( (num_train,), dtype=np.uint8) #训练集label

i=0

for img_path in tqdm( glob(train_path + r'**.jpg) ):

    img = ndimage.imread(img_path)

    x_train[i, :, :, :] = img #赋值

    
    if img_path.split('//')[-2] == 'normal':

            y_train[i] = 0  #赋值label

    else:

            y_train[i] = 1

    i += 1

datagen = ImageDataGenerator(rescale = 1.0/255.0, featurewise_center = True, featurewise_std_normalization= True)

datagen.fit(x_train) #图片预处理

待解决问题: 如何输入??

你可能感兴趣的:(Python Keras导入训练集验证集测试集,并进行数据预处理)