AttributeError:'SequenceGenerator'对象没有属性'shape'自定义序列生成器Keras 2.2.4

时间:2019-04-07 10:53:11

标签: python keras sequence google-colaboratory

我尝试将authState与自定义this.fireAuth.authState.subscribe((user: firebase.User) => { if (user) { this.getUserData(user.uid); } }); 和自定义fit_generator结合使用,但出现以下错误。请告知我应该在哪里更改代码。

1。自定义序列类:

train_sequence_generator

2。 CoLab中的Fit_generator

test_sequence_generator

3。错误

import os
import numpy as np
from keras.utils import Sequence
from batchGenerator import BatchGenerator

from settings import  batch_size, train_folder, test_folder


class SequenceGenerator(Sequence):
    def __init__(self, batches_folder):
        self.batch_generator = BatchGenerator(folder_name=batches_folder)      
        self.names = [f for f in os.listdir(batches_folder) if f.lower().endswith('.jpg')]

    def __len__(self):
        return int(np.ceil(len(self.names) / float(batch_size)))

    def __getitem__(self, idx):
        print('Getting a bacth{0}'.format(idx))
        [X_batch, Y_batch] = self.batch_generator.load_batch_from_disk(idx)

        return X_batch, Y_batch


def train_seq_genenrator():
    return SequenceGenerator(train_folder)


def test_seq_generator():
    return SequenceGenerator(test_folder)

1 个答案:

答案 0 :(得分:0)

在新的anaconda环境中安装Keras和TensorFlow,然后开始培训过程为我解决了这个问题。