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) #图片预处理

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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容