Keras model.fit 返回 NoneType 对象

问题描述 投票:0回答:0

我正在处理大量图片数据集 (1920x1088),这就是我决定使用 tf.keras.utils.Sequence() 加载它的原因 这是它的样子:

class Pictures(keras.utils.Sequence):
    
    def __init__(self, x_set, y_set, batch_size):
        self.x, self.y = x_set, y_set
        self.batch_size = batch_size
      
    def load_sample(self, file):
        image = Image.open(file)    # Открываем изображение
        image.load()    # Загружаем его
        return image
  
    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_y = self.y[idx * self.batch_size:(idx + 1) *
        self.batch_size]
        
        return np.array([cv2.resize(cv2.imread(file_name), (1920, 1088)) for file_name in batch_x]).astype('float32') / 255.0, np.array([cv2.resize(cv2.imread(file_name), (1920, 1088)) for file_name in batch_y]).astype('float32') / 255.0 

我的模型看起来像:

              metrics = ['acc'])
model.fit(Pictures(high_q, low_q, 1), epochs = 7)```

high_q and low_q are lists of paths to the pictures

I keep getting an error: TypeError: 'NoneType' object is not callable

The code works fine without tf.keras.utils.Sequence(), but I need to keep it

What I'm doing wrong...

P.s. I was asked to do it on Keras, if I could, I would rather do it with Torch

I tried different files, different formats etc.
It works if I'll delete the class, but I need it
python keras deep-learning dataset
© www.soinside.com 2019 - 2024. All rights reserved.