Custom train_step() in TensorFlow Keras Model not Printing Values Sequentially


class model_sub(tf.keras.Model):
  def __init__(self,modell):
    super().__init__()
    self.model=modell
    self.i=1

  def compile(self,opt,lloss,**kwargs):
    super().compile(**kwargs)
    self.lloss=lloss
    self.opt=opt

  def train_step(self,data):

     
  
    print(self.i)
    self.i+=1






    loss=0.007
    return {"loss":loss}


my_model.fit(train_dataset,epochs=1)

If train_step is called by fit() for every batch of data, why is not the value being printed from 1 to 4 (my no of batches is 4 ).Also what is the purpose of value in the return statement is it just for printing purposes?

Hi @Aaditya_Adhikari ,

Welcome to TensorFlow Forum

As per Understanding there might be a few reasons like might be dataset is not properly batched and the number of batches is not correctly set to 4 so Could you Please verify the dataset preparation and batching process .

The value returned by train_step is used to report the loss and other metrics back to the Keras training loop. This allows Keras to display the progress of training, including the current loss and any other metrics you choose to report. Keras uses these values to update logs and provide feedback during training.

Thank you .