首页 > 解决方案 > AttributeError:模块'keras.utils'没有数据生成器的属性'Sequence'

问题描述

我尝试使用 Keras 制作视频帧生成器,但出现上述错误。对于神经网络训练,使用 Keras.model.fit_generator 方法。这需要一个生成器来读取并向 Keras 引擎生成训练数据。

import glob
import os
import sys
#from gtts import utils
import tensorflow as tf
import numpy as np
import pandas as pd
import tensorflow as tf
from sklearn.preprocessing import LabelEncoder
import keras
from frame import files2frames, images_normalize, frames_show


class FramesGenerator(tf.keras.utils.Sequence):
    """Read and yields video frames/optical flow for Keras.model.fit_generator
    Generator can be used for multi-threading.
    Substantial initialization and checks upfront, including one-hot-encoding of labels.
    """

    def __init__(self, sPath: str, \
                 nBatchSize: int, nFrames: int, nHeight: int, nWidth: int, nChannels: int, \
                 liClassesFull: list = None, bShuffle: bool = True):
        """
        Assume directory structure:
        ... / sPath / class / videoname / frames.jpg
        """

        'Initialization'
        self.nBatchSize = nBatchSize
        self.nFrames = nFrames
        self.nHeight = nHeight
        self.nWidth = nWidth
        self.nChannels = nChannels
        self.tuXshape = (nFrames, nHeight, nWidth, nChannels)
        self.bShuffle = bShuffle

标签: pythonvisual-studiotensorflowkerasdeep-learning

解决方案


推荐阅读