我根据链接的指导实现了一个序列生成器对象。
import tensorflow as tf
from cv2 import imread, resize
from sklearn.utils import shuffle
from cv2 import imread, resize
import numpy as np
from tensorflow.keras import utils
import math
import keras as ks
class reader(tf.keras.utils.Sequence):
def __init__(self, x, y, batch_size, n_class):
self.x, self.y = x, y
self.batch_size = batch_size
self.n_class = n_class
def __len__(self):
return math.ceil(len(self.x) / self.batch_size)
def __getitem__(self, idx):
print('getitem', idx)
batch_x = self.x[idx * self.batch_size:(idx + 1) *
self.batch_size]
batch_y = self.y[idx * self.batch_size:(idx + …Run Code Online (Sandbox Code Playgroud)