Python 数据生成器(序列)-如何检查批次x和批次y形状?

Python 数据生成器(序列)-如何检查批次x和批次y形状?,python,types,shapes,data-generation,Python,Types,Shapes,Data Generation,我已经创建了这个数据生成器: class DataGenerator(Sequence): def __init__(self, x_set, y_set, batch_size): self.x, self.y = x_set, y_set self.batch_size = batch_size def __len__(self): return math.ceil(len(self.x) / self.batch_size

我已经创建了这个
数据生成器

class DataGenerator(Sequence):

    def __init__(self, x_set, y_set, batch_size):
        self.x, self.y = x_set, y_set
        self.batch_size = batch_size

    def __len__(self):
        return math.ceil(len(self.x) / self.batch_size)

    def __getitem__(self, idx):
        batch_x = self.x[idx*self.batch_size : (idx + 1)*self.batch_size]
        batch_x = np.array([resize(imread(file_name), (224, 224)) for file_name in batch_x])
        batch_x = batch_x * 1./255
        batch_y = self.y[idx*self.batch_size : (idx + 1)*self.batch_size]
        batch_y = np.array(batch_y)

        return batch_x, batch_y

我现在想检查
batch\u x
batch\u y
shape
type
。我该怎么做呢?

只需在
\uuu getitem\uuuu
函数中添加两行
print
,这样每次调用生成器时,您都会看到所需的信息:

print('batch_x : shape = %s, type = %s' % (batch_x.shape, batch_x.dtype) ) # If np.array
print('batch_y : shape = %s, type = %s' % (batch_y.shape, batch_y.dtype) )

我不明白你在这里问的问题。是否要创建一个方法来输出该信息?否,我想获取一批x_集和y_集数据的形状和类型,以检查生成器是否达到预期效果。您的
x_集
y_集
可以具有哪些类型?你可以用吗?是的,numpy可以。通常它们的类型应该是numpy数组。非常感谢:)