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 › 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 ...
Author   over-shine
Discussions

layers.Dense - AttributeError: 'tuple' object has no attribute 'rank' " - General Discussion - Google AI Developers Forum
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’): inputs = keras.Input(shape=(length,)) dense = layers.Dense(4, ... More on discuss.ai.google.dev
🌐 discuss.ai.google.dev
0
June 3, 2024
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 - AttributeError: 'tuple' object has no attribute 'rank' when using tensorflow_probability.layers.DenseVariational - Stack Overflow
I'm trying to use bayesian neural networks, adding a bayesian layer to a neural networks model. Here is the code I'm using and it's from the keras website. import numpy as np import tensorflow as t... More on stackoverflow.com
🌐 stackoverflow.com
July 10, 2024
python - tuple has no attribute "rank" error when trying to build bayesian neural net - Data Science Stack Exchange
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 More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
April 6, 2025
🌐
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
🌐
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’): inputs = ...
🌐
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 › 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
Find elsewhere
🌐
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 › 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(
🌐
LearnDataSci
learndatasci.com › solutions › python-attributeerror-tuple-object-has-no-attribute
Python AttributeError: 'tuple' object has no attribute – LearnDataSci
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-5-2f0480fa9e27> in <module> ----> 1 val_1 = create_tuple().val_1 AttributeError: 'tuple' object has no attribute 'val_1'
🌐
GitHub
github.com › tensorflow › ranking › issues › 45
AttributeError: 'tuple' object has no attribute 'dtype' · Issue #45 · tensorflow/ranking
March 25, 2019 - tensorflow / ranking Public archive · Notifications · You must be signed in to change notification settings · Fork 480 · Star 2.8k · This repository was archived by the owner on May 21, 2025. It is now read-only. Copy link · Copy link · Closed · Closed · AttributeError: 'tuple' object has no attribute 'dtype'#45 ·
Author   miguelwon
🌐
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?

🌐
Python.org
discuss.python.org › python help
AttributeError: 'tuple' object has no attribute 'enter' - Python Help - Discussions on Python.org
March 5, 2025 - I’m coding a game program for ... ‘tuple’ object has no attribute ‘enter’ Here’s the code: class Engine(object): def __init__(self, scene_map): self.scene_map = scen......