我有一个大数据集,我正在为我的大数据集使用自定义生成器batch_generator()方法,当我拟合模型时,它给了我以下错误
这是我的完整代码
deneme
def batch_generator(Train_df,batch_size,steps):
idx=1
while True:
yield load_data(Train_df,idx-1,batch_size)
if idx<steps:
idx=idx+1
else:
idx=1
import numpy as np
import pandas as pd
from keras.utils import np_utils
from sklearn.preprocessing import LabelEncoder,OneHotEncoder
def load_data(Train_df, idx, batch_size):
integer_encoder = LabelEncoder()
one_hot_encoder = OneHotEncoder(categories='auto')
df = pd.read_csv(
Train_df, skiprows=idx*batch_size,
nrows=batch_size)
sequences = df.iloc[:,1:]
x = []
for sequence in sequences:
integer_encoded = integer_encoder.fit_transform(list(sequence))
integer_encoded = np.array(integer_encoded).reshape(-1,1)
one_hot_encoded = one_hot_encoder.fit_transform(integer_encoded)
x.append(one_hot_encoded.toarray())
y = df.iloc[:,2]
return (np.array(x), np_utils.to_categorical(y))
from tensorflow.keras.layers import Conv1D,Dense,MaxPooling1D,Flatten
from tensorflow.keras.models import Sequential
import tensorflow as tf
model = Sequential()
batch_size=256
nb_epoch = 5
steps_per_epoch = np.ceil(20464150/batch_size)
validation_steps = np.ceil(5116386/batch_size)
my_training_batch_generator = batch_generator('/content/drive/My Drive/Training_set/training.csv',batch_size,steps=steps_per_epoch)
my_validation_batch_generator = batch_generator('/content/drive/My Drive/Training_set/testing.csv',batch_size,steps=validation_steps)
model.add(Conv1D(filters=32,kernel_size=12,input_shape=(256,4)))
model.add(MaxPooling1D(pool_size=4))
model.add(Flatten())
model.add(Dense(16,activation='relu'))
model.add(Dense(2,activation='softmax'))
model.compile(loss='binary_crossentropy',optimizer='adam',metrics=['binary_accuracy'])
model.summary()
我正在google实验室做所有这些工作