0

Hi after getting solution for: ValueError: Dimension must be 4 but is 3. Now program can run but I am getting the following error after each epoch in training:

Epoch 1/5
18/18 [==============================] - 10s 221ms/step - loss: 1.6059 - f1_score: 0.1769 - val_loss: 0.9308 - val_f1_score: 0.2871

Epoch 00001: val_f1_score improved from -inf to 0.28711, saving model to ./Saved_model/hospital/best_model_checkpoint
2022-01-31 18:24:59.864842: W tensorflow/python/util/util.cc:348] Sets are not currently considered sequences, but this may change in the future, so consider avoiding using them.
WARNING:absl:Found untraced functions such as conv1d_layer_call_and_return_conditional_losses, conv1d_layer_call_fn, conv1d_1_layer_call_and_return_conditional_losses, conv1d_1_layer_call_fn, conv1d_2_layer_call_and_return_conditional_losses while saving (showing 5 of 15). These functions will not be directly callable after loading.
WARNING:absl:Found untraced functions such as conv1d_layer_call_and_return_conditional_losses, conv1d_layer_call_fn, conv1d_1_layer_call_and_return_conditional_losses, conv1d_1_layer_call_fn, conv1d_2_layer_call_and_return_conditional_losses while saving (showing 5 of 15). These functions will not be directly callable after loading.
Epoch 2/5
18/18 [==============================] - 4s 217ms/step - loss: 1.0116 - f1_score: 0.2370 - val_loss: 0.7661 - val_f1_score: 0.3326

Epoch 00002: val_f1_score improved from 0.28711 to 0.33256, saving model to ./Saved_model/hospital/best_model_checkpoint
WARNING:absl:Found untraced functions such as conv1d_layer_call_and_return_conditional_losses, conv1d_layer_call_fn, conv1d_1_layer_call_and_return_conditional_losses, conv1d_1_layer_call_fn, conv1d_2_layer_call_and_return_conditional_losses while saving (showing 5 of 15). These functions will not be directly callable after loading.
WARNING:absl:Found untraced functions such as conv1d_layer_call_and_return_conditional_losses, conv1d_layer_call_fn, conv1d_1_layer_call_and_return_conditional_losses, conv1d_1_layer_call_fn, conv1d_2_layer_call_and_return_conditional_losses while saving (showing 5 of 15). These functions will not be directly callable after loading.
Epoch 3/5
18/18 [==============================] - 4s 231ms/step - loss: 0.9335 - f1_score: 0.2711 - val_loss: 0.7153 - val_f1_score: 0.3425

Epoch 00003: val_f1_score improved from 0.33256 to 0.34253, saving model to ./Saved_model/hospital/best_model_checkpoint
WARNING:absl:Found untraced functions such as conv1d_layer_call_and_return_conditional_losses, conv1d_layer_call_fn, conv1d_1_layer_call_and_return_conditional_losses, conv1d_1_layer_call_fn, conv1d_2_layer_call_and_return_conditional_losses while saving (showing 5 of 15). These functions will not be directly callable after loading.
WARNING:absl:Found untraced functions such as conv1d_layer_call_and_return_conditional_losses, conv1d_layer_call_fn, conv1d_1_layer_call_and_return_conditional_losses, conv1d_1_layer_call_fn, conv1d_2_layer_call_and_return_conditional_losses while saving (showing 5 of 15). These functions will not be directly callable after loading.
Epoch 4/5
18/18 [==============================] - 3s 189ms/step - loss: 0.8747 - f1_score: 0.2908 - val_loss: 0.6657 - val_f1_score: 0.3446

Epoch 00004: val_f1_score improved from 0.34253 to 0.34458, saving model to ./Saved_model/hospital/best_model_checkpoint
WARNING:absl:Found untraced functions such as conv1d_layer_call_and_return_conditional_losses, conv1d_layer_call_fn, conv1d_1_layer_call_and_return_conditional_losses, conv1d_1_layer_call_fn, conv1d_2_layer_call_and_return_conditional_losses while saving (showing 5 of 15). These functions will not be directly callable after loading.
WARNING:absl:Found untraced functions such as conv1d_layer_call_and_return_conditional_losses, conv1d_layer_call_fn, conv1d_1_layer_call_and_return_conditional_losses, conv1d_1_layer_call_fn, conv1d_2_layer_call_and_return_conditional_losses while saving (showing 5 of 15). These functions will not be directly callable after loading.
Epoch 5/5
18/18 [==============================] - 3s 197ms/step - loss: 0.8676 - f1_score: 0.2875 - val_loss: 0.6116 - val_f1_score: 0.3684

Epoch 00005: val_f1_score improved from 0.34458 to 0.36841, saving model to ./Saved_model/hospital/best_model_checkpoint
WARNING:absl:Found untraced functions such as conv1d_layer_call_and_return_conditional_losses, conv1d_layer_call_fn, conv1d_1_layer_call_and_return_conditional_losses, conv1d_1_layer_call_fn, conv1d_2_layer_call_and_return_conditional_losses while saving (showing 5 of 15). These functions will not be directly callable after loading.
WARNING:absl:Found untraced functions such as conv1d_layer_call_and_return_conditional_losses, conv1d_layer_call_fn, conv1d_1_layer_call_and_return_conditional_losses, conv1d_1_layer_call_fn, conv1d_2_layer_call_and_return_conditional_losses while saving (showing 5 of 15). These functions will not be directly callable after loading.
[Step 5] -> Finally loading and testing the trained Model on unseen Data.

Here is code for training:

 input_shape = (train_x.shape[1], train_x.shape[2], train_x.shape[3])
    model = CNN_model(input_shape, total_classes)
    model.summary()
    filepath = './Saved_model'
    tf.keras.utils.plot_model(model, to_file=mod_sum_plt_loc, show_shapes=True)
    freq = 10
    factor = .9
    verbose = 1
    callbacks = ADJUSTLR(model, freq, factor, verbose)

    opt = tf.keras.optimizers.Adam(learning_rate=0.001)

    model.compile(loss="categorical_crossentropy", optimizer=opt,
                  metrics=[tfa.metrics.F1Score(num_classes=total_classes, average='macro')])
    # model.compile(loss="categorical_crossentropy", optimizer=opt, metrics=["acc"])

    path_checkpoint = os.path.join(filepath, dataset, "best_model_checkpoint")
    callback_model_saving = tf.keras.callbacks.ModelCheckpoint(
        filepath=path_checkpoint,
        monitor='val_f1_score', mode='max', verbose=1, save_best_only=True)
    print('[Step 4] -> Model is going to start training')
    model.fit(train_ds_mu, epochs=total_epoch,
              callbacks=[callbacks, callback_model_saving],
              validation_data=test_ds)  
Ahmad
  • 645
  • 2
  • 6
  • 21

0 Answers0