'input problem of tensorflow model while doing audio classification

Env:

tensorflow version: 2.4rc

numpy version: 1.19.5

os: mac os M1 arch / ubuntu 16.4

description:

I'm new to tensorflow and i am doing audio classification using LSTM and CNN with it, but these two models seem to meet the same problem while training. The training process stucks because of incorrect inputs which i can't figure out how to fix it. Take LSTM as example:

model information:

    input_shape = (SEGMENT_DUR,N_MEL_BANDS)
    model=Sequential()
    model.add(Input(input_shape))
    model.add(LSTM(96, return_sequences=True,name = 'lstm-96',input_shape = input_shape))
    model.add(LSTM(218, name = 'lstm-218'))
    model.add(Dense(n_classes, activation='softmax',name = 'prediction'))
    model.summary()

image link: model summary

training set

        early_stopping = EarlyStopping(monitor='val_loss', patience=EARLY_STOPPING_EPOCH)
        save_clb = ModelCheckpoint(
            "{weights_basepath}/{model_path}/".format(
                weights_basepath=MODEL_WEIGHT_BASEPATH,
                model_path=self.model_module.BASE_NAME) +
            "epoch.{epoch:02d}-val_loss.{val_loss:.3f}-acc.{val_accuracy:.3f}"+"-{key}.hdf5".format(
                key=self.model_module.MODEL_KEY),
            monitor='val_loss',
            save_best_only=True)
        lrs = LearningRateScheduler(lambda epoch_n: self.init_lr / (2**(epoch_n//SGD_LR_REDUCE)))

        model.compile(optimizer='adam',
                      loss='categorical_crossentropy',
                      metrics=['accuracy'])

        # train_input, train_val = self.load_data(self.X_train), self.y_train
        history = model.fit(
                            self._batch_generator(self.X_train, self.y_train,batch_size=BATCH_SIZE),
                            validation_data=self._batch_generator(self.X_val, self.y_val,batch_size=BATCH_SIZE),
                            batch_size=BATCH_SIZE,
                            epochs=MAX_EPOCH_NUM,
                            steps_per_epoch=2,
                            verbose=1,
                            callbacks=[save_clb, early_stopping, lrs]
                            # workers=1,
                        )

self-defined batch generator provide a batch_size of (input,label) data,

result

image link: run result seems that it's doing nothing after the first batch, and i trace into the training detail found the input shapes are unclear: image link: shape problem

these warnings are no big deal, they appear in simple success demos as well. and for convenience here is the link of relavant docs: model.fit really need HELP! Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source