You need to convert all the individual objects returned by both the training and validation generators to Numpy arrays:

    yield [np.array(imgs), np.array(cols)], np.array(targets)

Alternatively, a simpler and much more efficient solution is to not iterate over the data batch at all; instead, we can take advantage of the fact that these objects are already Numpy arrays when returned by ImageDataGenerator, so we can write:

    imgs = data[0]
    cols = data[1][:,:-1]
    targets = data[1][:,-1:]
    yield [imgs, cols], targets
Answer from today on Stack Overflow
🌐
GitHub
github.com › tensorflow › agents › issues › 363
AttributeError: 'tuple' object has no attribute 'rank' · Issue #363 · tensorflow/agents
May 3, 2020 - The code in tf agents gets the 'shape' from the action_spec, which is a tuple in my case. Then it tries to retrieve key "rank" from a tuple.
Author   AndreyBulezyuk
Discussions

training keras Sequential model with python generator raise error: AttributeError: 'tuple' object has no attribute 'rank'
Describe the current behavior When training a Sequential model by fit function with python generator as inputs, it raise AttributeError: 'tuple' object has no attribute 'rank'. The python generator yield a tuple (x, y), which follows the tf document of fit function. More on github.com
🌐 github.com
13
October 24, 2020
C5 W4 A1: Scaled_dot_product_attention AttributeError: 'tuple' object has no attribute 'rank'
C5 W4 A1: Scaled_dot_product_attention AttributeError: 'tuple' object has no attribute 'rank' · AttributeError Traceback (most recent call last) in 1 # UNIT TEST ----> 2 scaled_dot_product_attention_test(scaled_dot_product_attention) · Also, in “output = …”, you should consider using ... More on community.deeplearning.ai
🌐 community.deeplearning.ai
0
1
September 9, 2021
tensorflow - RuntimeError: 'tuple' object has no attribute 'rank'—custom DenseVariational prior/posterior functions are returning a tuple instead of a tensor - Stack Overflow
I implemented custom prior and posterior functions for tfp.layers.DenseVariational and expected the model to compile and train without issues. However, when building the model, I received a runtime error stating that a 'tuple' object has no attribute 'rank', indicating that my functions are ... More on stackoverflow.com
🌐 stackoverflow.com
'tuple' object has no attribute 'rank' while using feature pyramid network
Current Behavior: 'tuple' object has no attribute 'rank' while using feature pyramid network Expected Behavior: Steps To Reproduce: https://colab.sandbox.google.com/gist/sineeli/488... More on github.com
🌐 github.com
1
November 7, 2023
🌐
Google AI
discuss.ai.google.dev › tensorflow › general discussion
layers.Dense - AttributeError: 'tuple' object has no attribute 'rank' " - General Discussion - Google AI Developers Forum
June 3, 2024 - I am getting the error "AttributeError: ‘tuple’ object has no attribute ‘rank’ " on the line : dense = layers.Dense(4, activation=act_func)(inputs), in the following function : def gen_model(act_func = ‘relu’): input…
🌐
GitHub
github.com › tensorflow › tensorflow › issues › 44285
training keras Sequential model with python generator raise error: AttributeError: 'tuple' object has no attribute 'rank' · Issue #44285 · tensorflow/tensorflow
October 24, 2020 - Describe the current behavior When training a Sequential model by fit function with python generator as inputs, it raise AttributeError: 'tuple' object has no attribute 'rank'. The python generator yield a tuple (x, y), which follows the tf document of fit function.
Author   over-shine
🌐
DeepLearning.AI
community.deeplearning.ai › course q&a › deep learning specialization › sequence models
C5 W4 A1: Scaled_dot_product_attention AttributeError: 'tuple' object has no attribute 'rank' - Sequence Models - DeepLearning.AI
September 9, 2021 - C5 W4 A1: Scaled_dot_product_attention AttributeError: 'tuple' object has no attribute 'rank' · AttributeError Traceback (most recent call last) in 1 # UNIT TEST ----> 2 scaled_dot_product_attention_test(scaled_dot_product_attention) · Also, in “output = …”, you should consider using ...
🌐
Stack Overflow
stackoverflow.com › questions › 79448077 › runtimeerror-tuple-object-has-no-attribute-rank-custom-densevariational-pri
tensorflow - RuntimeError: 'tuple' object has no attribute 'rank'—custom DenseVariational prior/posterior functions are returning a tuple instead of a tensor - Stack Overflow
This indicates that one of my custom functions—either prior_trainable or posterior_mean_field—is returning a tuple instead of a TensorFlow tensor or a distribution object with proper tensor attributes. My custom functions are intended to create trainable probability distributions for the weights and biases of the variational layer, but it appears that somewhere in the process, a tuple is being passed or returned. This causes the internal input compatibility checks (which try to access .rank) in TensorFlow Probability to fail.
🌐
GitHub
github.com › keras-team › keras-cv › issues › 2133
'tuple' object has no attribute 'rank' while using feature pyramid network · Issue #2133 · keras-team/keras-cv
November 7, 2023 - Current Behavior: 'tuple' object has no attribute 'rank' while using feature pyramid network Expected Behavior: Steps To Reproduce: https://colab.sandbox.google.com/gist/sineeli/48885c70cac00415b953e46db8cdaa44/untitled10.ipynb Version: ...
Author   sineeli
🌐
LearnDataSci
learndatasci.com › solutions › python-attributeerror-tuple-object-has-no-attribute
Python AttributeError: 'tuple' object has no attribute – LearnDataSci
The underscore conveys to readers of your code that you intend not to use the index value. The error AttributeError: 'tuple' object has no attribute is caused when treating the values within a tuple as named attributes.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 78732706 › attributeerror-tuple-object-has-no-attribute-rank-when-using-tensorflow-pro
tensorflow - AttributeError: 'tuple' object has no attribute 'rank' when using tensorflow_probability.layers.DenseVariational - Stack Overflow
July 10, 2024 - File "/Users/S/Documents/B/Prediction/test1.py", line 148, in <module> bnn_model_small = create_bnn_model(train_sample_size) File "/Users/S/Documents/B/Prediction/test1.py", line 131, in create_bnn_model features = tfp.layers.DenseVariational( File "/Users/S/.local/share/virtualenvs/B-hz56sUDM/lib/python3.9/site-packages/tf_keras/src/utils/traceback_utils.py", line 70, in error_handler raise e.with_traceback(filtered_tb) from None File "/Users/S/.local/share/virtualenvs/B-hz56sUDM/lib/python3.9/site-packages/tf_keras/src/engine/input_spec.py", line 251, in assert_input_compatibility ndim = x.shape.rank AttributeError: 'tuple' object has no attribute 'rank'
🌐
Stack Exchange
datascience.stackexchange.com › questions › 131698 › tuple-has-no-attribute-rank-error-when-trying-to-build-bayesian-neural-net
python - tuple has no attribute "rank" error when trying to build bayesian neural net - Data Science Stack Exchange
April 6, 2025 - I'm trying to build a BNN but am encountering the error in the title. I tried to ensure I'm not passing a tuple to .shape.rank by : using the functional API with explicit Input (should make first
🌐
Stack Overflow
stackoverflow.com › questions › 78564659 › layers-dense-attributeerror-tuple-object-has-no-attribute-rank
tensorflow - layers.Dense - AttributeError: 'tuple' object has no attribute 'rank' " - Stack Overflow
Getting the error "AttributeError: ‘tuple’ object has no attribute ‘rank’ " on the line : dense = layers.Dense(4, activation=act_func)(inputs), in the following function : def gen_model(
🌐
Stack Overflow
stackoverflow.com › questions › 78902144 › model-definition-in-keras-tutorial-probabilistic-bayesian-neural-networks-lead
python - Model definition in Keras tutorial "Probabilistic Bayesian Neural Networks" leads to error "AttributeError: 'tuple' object has no attribute 'rank'" - Stack Overflow
AttributeError Traceback (most recent call last) <ipython-input-11-c94aabf54886> in <cell line: 5>() 3 small_train_dataset = train_dataset.unbatch().take(train_sample_size).batch(batch_size) 4 ----> 5 bnn_model_small = create_bnn_model(train_sample_size) 6 run_experiment(bnn_model_small, mse_loss, small_train_dataset, test_dataset) 2 frames /usr/local/lib/python3.10/dist-packages/tf_keras/src/engine/input_spec.py in assert_input_compatibility(input_spec, inputs, layer_name) 249 ) 250 if spec.min_ndim is not None: --> 251 ndim = x.shape.rank 252 if ndim is not None and ndim < spec.min_ndim: 253 raise ValueError( AttributeError: 'tuple' object has no attribute 'rank'
🌐
Stack Overflow
stackoverflow.com › questions › 70812641 › deep-shap-problem-exception-encountered-when-calling-layer-sequential-1-type
python - deep shap problem: Exception encountered when calling layer "sequential_1" (type Sequential), 'tuple' object has no attribute 'rank' - Stack Overflow
explainer = shap.DeepExplainer(model3,y_train) shap_values = explainer.shap_values(x_train) ss = pd.DataFrame(shap_values) shap.summary_plot(shap_values, x_train) error: 1)Exception encountered when calling layer "sequential_1" (type Sequential). 2)'tuple' object has no attribute 'rank'
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-tuple-object-has-no-attribute
AttributeError: 'tuple' object has no attribute X in Python | bobbyhadz
April 8, 2024 - The Python "AttributeError: 'tuple' object has no attribute" occurs when we access an attribute that doesn't exist on a tuple.
🌐
Reddit
reddit.com › r/learnpython › getting attributeerror: 'tuple' object has no attribute 'items'
r/learnpython on Reddit: Getting AttributeError: 'tuple' object has no attribute 'items'
February 1, 2021 -
from kubernetes import client, config

config.load_kube_config()

v1 = client.CoreV1Api()
print("Listing services with their IPs:")
ret = v1.list_service_for_all_namespaces_with_http_info(watch=False)
for i in ret.items:
    print("%s\t%s\t%s" % (i.status.pod_ip, i.metadata.namespace, i.metadata.name))    

This throws this error: File "filename.py", line 8, in <module> for i in ret.items: AttributeError: 'tuple' object has no attribute 'items'

But when I simply print(ret), it certainly LOOKS like a tuple, which means I should be able to iterate through with tuple.items, no?