tensorflow
tensorflow copied to clipboard
how to solve the exception with "UnboundLocalError: local variable 'batch_index' referenced before assignment"
tensorflow: 1.14.0 keras: 2.2.5 when I run : model.fit(x, y, epochs=epochs, batch_size=batch_size, verbose=2, shuffle=False) and then catch the exception as below: UnboundLocalError: local variable 'batch_index' referenced before assignment
I guess it maybe concern with epochs or batch_size, or shape of my dataset? Can someone tell me what's the relation between epochs and batch_size?Is it the epoches must be divided by batch_size?
Hey! For issues related to general coding questions, stackoverflow is a great resource, this issue tracker is primarily for bugs that directly impact the project
Maybe this post on stackoverflow helps: https://stackoverflow.com/questions/63364588/unboundlocalerror-local-variable-batch-outputs-referenced-before-assignment If it doesn't solve your problem, feel free to reply back and I will try my best to help you
@Roych13, We see that you are using tf version 1.14, 1.x is not actively supported, please update to 2.x and let us know if you are facing the same issue. Could you please provide the complete code to reproduce the issue.
Also the batch size is the number of samples in each batch. Each batch process is referred to as one step and An epoch is completed when all the data in the training set is used for training. The smaller the batch_size is, the larger number of batches is processed per one epoch.
The ideal combination of epochs and batch size depends on your specific dataset, model architecture, and computational resources. Also better way is to start from smaller batches to find wide and plain minima, which are better from the generalization point of view, and then increase batch size for steadier convergence. Thank you!
This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.
Hi @Roych13 ,
UnboundLocalError: local variable 'batch_index' referenced before assignment
In general the above error arises when you are using a variable (here eg. "batch_index") passed as argument or assigning to some other variable before actually assigning a value to it. Search if your code have batch_index anywhere and check whetehr it is instantiated before using somewhere else.
This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.
This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further.