- TensorFlow Version: 2.16.1
- Keras Version: 3.3.3
- tf_keras Version: 2.16.0
Issue Description:
I encountered an error while running my training script training_holdout.py with the following command:
export TF_USE_LEGACY_KERAS=1
python3 training_holdout.py
Note: It’s crucial to use export TF_USE_LEGACY_KERAS=1 to ensure that TensorFlow utilizes Keras version 2.* for compatibility reasons.
The script failed and produced the following traceback:
Traceback (most recent call last):
File "/media/fernando/B0EA304AEA300EDA/Dados/Fernando/CODE/PESQUISA/programs-tese/SYSTEM-TRAINING/cnn_emotion4/create/training_holdout.py", line 184, in <module>
model, target_size = mpp.create_model(model_type=model_type, load_weights=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/media/fernando/B0EA304AEA300EDA/Dados/Fernando/CODE/PESQUISA/programs-tese/SYSTEM-TRAINING/cnn_emotion4/create/../library/BodyEmotion4Lib/lib_model.py", line 58, in create_model
modelo = tf.keras.Sequential([
^^^^^^^^^^^^^^^^^^^^^
File "/home/fernando/.local/lib/python3.12/site-packages/tensorflow/python/trackable/base.py", line 204, in _method_wrapper
result = method(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/fernando/.local/lib/python3.12/site-packages/tf_keras/src/utils/traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/usr/lib/python3.12/random.py", line 336, in randint
return self.randrange(a, b+1)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/random.py", line 312, in randrange
istop = _index(stop)
^^^^^^^^^^^^
TypeError: 'float' object cannot be interpreted as an integer
Cause of the Error:
The error originates from the randint function in Python’s random module, which is being passed a float instead of an integer. This causes a TypeError because the randrange function expects integer inputs.
Solution:
To resolve this issue, I modified line 336 in the file /usr/lib/python3.12/random.py from:
return self.randrange(a, b+1)
to:
return self.randrange(int(a), int(b+1))
This ensures that the arguments passed to randrange are integers, thereby preventing the TypeError.
Recommendation:
It would be beneficial to implement a type check or cast within the relevant parts of the TensorFlow or Keras codebase to handle such cases where float inputs might be passed inadvertently.
I would like to report this issue to the appropriate bug tracking system, but I am uncertain whether it falls under TensorFlow, Keras, or the Python random module. Could you please advise where to submit this bug report to ensure it reaches the correct library maintainers?
Fernando Pujaico Rivera is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.