TypeError:“ int”对象不可下标(生成器)

时间:2020-05-06 21:01:54

标签: tensorflow keras imbalanced-data

我正在处理基于文本的不平衡数据集。在训练模型时,我使用了tensorflow平衡批处理生成器来创建平衡批处理:

batch_generator, steps_per_epoch = balanced_batch_generator(training_x, training_y, BATCH,
                                                                random_state=42)

 def build_model():

    model = tf.keras.Sequential([


        tf.keras.layers.Embedding(vocab_size, embedding_dim, input_length=max_seq_len,
                                  embeddings_initializer='glorot_uniform'),
        tf.keras.layers.GlobalAveragePooling1D(),  # average across the vector to flatten it out (faster)



        tf.keras.layers.Dense(16, activation='relu', kernel_initializer='glorot_uniform',
                              kernel_regularizer=tf.keras.regularizers.l2(0.1)),
        tf.keras.layers.Dropout(0.5),
        tf.keras.layers.BatchNormalization(),
        tf.keras.layers.Dense(16, activation='relu', kernel_initializer='glorot_uniform',
                              kernel_regularizer=tf.keras.regularizers.l2(0.1)),
        tf.keras.layers.BatchNormalization(),
        tf.keras.layers.Dropout(0.5),

        tf.keras.layers.Dense(1, activation='sigmoid') 
    ])
    model.compile(loss='binary_crossentropy', optimizer=tf.keras.optimizers.Adam(lr=0.001),
                  metrics=metrics)

    model.summary()
    return model




 callback_history = build_model().fit_generator(batch_generator,
                                                   steps_per_epoch=steps_per_epoch,
                                                   epochs=nu_epochs,
                                                   verbose=1)

但是出现以下错误:

TypeError: 'int' object is not subscriptable

0 个答案:

没有答案