小编Jon*_*nah的帖子

从 tf.keras.utils.Sequence 构建的自定义数据生成器不适用于张量流模型的 fit api

我根据链接的指导实现了一个序列生成器对象。

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)

python sequence-generators keras tensorflow

5
推荐指数
1
解决办法
2517
查看次数

标签 统计

keras ×1

python ×1

sequence-generators ×1

tensorflow ×1