from your definition, population is a tuple. I'd suggest two options, the first is converting it to an array, i.e.

population = np.asarray(population)

Alternatively, you can use the DataFrame column .values attribute, which is essentially a numpy array:

X = np.concatenate((np.ones(len(population)).reshape(len(population), 1), df['Population'].values.reshape(len(population),1)), axis=1)
Answer from Tarifazo on Stack Overflow
Discussions

python - AttributeError: 'tuple' object has no attribute 'shape' - Stack Overflow
AttributeError: 'tuple' object has no attribute 'shape' More on stackoverflow.com
🌐 stackoverflow.com
AttributeError: 'tuple' object has no attribute 'shape' error while using Google colab
Based on research and understanding of the issue its looks to me as a bug as i tried different things suggested by other users for similar issues. but it doesn't resolve. System information Usi... More on github.com
🌐 github.com
20
April 13, 2020
'tuple' object has no attribute 'x'
What does your imports look like? More on reddit.com
🌐 r/AskProgramming
4
3
March 22, 2021
python - AttributeError: 'tuple' object has no attribute 'reshape' - Stack Overflow em Português
É porque o .reshape é um método apenas da array do NumPy. Então por algum motivo você armazenou as predições do algoritmo dentro de uma tupla ao invés de um array do numpy. você pode fazer o seguinte procedimento e tentar de novo. More on pt.stackoverflow.com
🌐 pt.stackoverflow.com
August 2, 2018
🌐
GitHub
github.com › cvnlab › GLMsingle › issues › 68
AttributeError: 'tuple' object has no attribute 'reshape' · Issue #68 · cvnlab/GLMsingle
June 2, 2022 - AttributeError: 'tuple' object has no attribute 'reshape'#68 · Copy link · LukasNeugebauer · opened · on Jun 2, 2022 · Issue body actions · Hey there, I just tried your toolbox for the first time. Since my data is too large, the toolbox is taking a subset.
Author   LukasNeugebauer
🌐
Google Groups
groups.google.com › g › keras-users › c › rrZlWwLk6hc
"AttributeError: 'tuple' object has no attribute 'shape'" in Keras Model
In the following sample code from the website " https://ai-leader.com/2020/05/09/using-lstm-with-1d-2d-and-3d-array/ ", I face with an error displaying "AttributeError: 'tuple' object has no attribute 'shape'". How can I get rid of that error ?
🌐
GitHub
github.com › tensorflow › tensorflow › issues › 38503
AttributeError: 'tuple' object has no attribute 'shape' error while using Google colab · Issue #38503 · tensorflow/tensorflow
April 13, 2020 - I checked if there are any references to keras instaed of tensoflw.keras and corrected them. I also converted the datagenerator output to a tuple instead of list · AttributeError Traceback (most recent call last) in () 7 epochs=nb_epoch, 8 steps_per_epoch=nb_train_samples, ----> 9 validation_data=gen_valid)
Author   mkpisk
🌐
Reddit
reddit.com › r/askprogramming › 'tuple' object has no attribute 'x'
r/AskProgramming on Reddit: 'tuple' object has no attribute 'x'
March 22, 2021 -

working on an assignment and I've been getting this error a lot with the codes our professor is giving us. Here is an example of a code given:

a = np.random.normal(0, 1, 9).reshape(3, 3)

and it returns:

AttributeError                            Traceback (most recent call last)
<ipython-input-10-d5ba530a56da> in <module>
----> 1 a = np.random.normal(0, 1, 9).reshape(3, 3)

AttributeError: 'tuple' object has no attribute 'random'

so I'm not sure what I'm doing wrong. Any ideas?

*RESOLVED* thank you u/FunkyDoktor

Find elsewhere
🌐
LearnDataSci
learndatasci.com › solutions › python-attributeerror-tuple-object-has-no-attribute
Python AttributeError: 'tuple' object has no attribute – LearnDataSci
The error AttributeError: 'tuple' object has no attribute is caused when treating the values within a tuple as named attributes.
🌐
GitHub
github.com › DLR-RM › stable-baselines3 › issues › 1594
[Bug]: AttributeError: 'tuple' object has no attribute 'shape' · Issue #1594 · DLR-RM/stable-baselines3
July 5, 2023 - 🐛 Bug I'm getting an AttributeError: 'tuple' object has no attribute 'shape' error when running my code as described below. This is using PPO CnnPolicy on the CarRacing-v2 environment. When I evaluate_policy(model, env, n_eval_episodes=1...
Author   zapcity
🌐
Python Forum
python-forum.io › thread-13879.html
'list' object has no attribute 'reshape'
November 4, 2018 - Hi All, I've just joined this forum, also new to Python, with background in other languages. I've been trying a small piece of code below using jupyter ipython in notebooks.azure.com, the error is coming from the last call for np.reshape function w...
🌐
GitHub
github.com › taigw › brats17 › issues › 5
AttributeError: 'tuple' object has no attribute 'shape' · Issue #5 · taigw/brats17
April 14, 2018 - AttributeError: 'tuple' object has no attribute 'shape'#5 · Copy link · Sylviayixin · opened · on Apr 14, 2018 · Issue body actions · I wonder why it always has this error: AttributeError: 'tuple' object has no attribute 'shape' No one assigned · No labels · No labels ·
Author   Sylviayixin
🌐
GitHub
github.com › pbhatia243 › Neural_Conversation_Models › issues › 7
AttributeError: 'tuple' object has no attribute 'get_shape' · Issue #7 · pbhatia243/Neural_Conversation_Models
December 7, 2016 - /prj/Neural_Conversation_Models$ python neural_conversation_model.py --train_dir ubuntu/ --en_vocab_size 60000 --size 512 --data_path ubuntu/train.tsv --dev_data ubuntu/valid.tsv --vocab_path ubuntu/60k_vocan.en --attention --decode --beam_search --beam_size 25 I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so locally I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so locally I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so locally I tensorflow/stream_executor/dso_l
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-list-object-has-no-attribute-shape
AttributeError: 'list' object has no attribute 'shape' | bobbyhadz
April 8, 2024 - The np.reshape() method takes an array-like object as an argument and an int or tuple of integers that represent the new shape.
🌐
Stack Overflow
stackoverflow.com › questions › 53379422 › reshape-image-error-tuple-object-cannot-be-interpreted-as-an-integer
numpy - reshape image error: 'tuple' object cannot be interpreted as an integer - Stack Overflow
November 19, 2018 - Traceback (most recent call last) ... object cannot be interpreted as an integer ... The error is in the resize method, not reshape, That's a Image issue, not a numpy one....
🌐
GitHub
github.com › explosion › spaCy › issues › 1874
python -m spacy init-model throws AttributeError: 'tuple' object has no attribute 'shape' · Issue #1874 · explosion/spaCy
January 22, 2018 - I've created word2vec and brown clusters along with word freqs. I'm trying to build the model and getting following error: Counting frequencies... 475883it [00:01, 254354.35it/s] Reading vectors... 102454it [00:06, 15625.38it/s] Reading ...
Top answer
1 of 3
9

The selected answer is inaccurate. The reason why the code is failing is not because the tuples are of the ((input1,output1), (input2,output2)), ...), but because they are of the type (((input1, class1), (input2, class2), ...), ((output1, class1), (output2, class2), ...)).

You could have fixed your problem by simply adding class_mode=None to your flow_from_directory calls.

2 of 3
7

So, since your model has only one output, you cannot join two generators like that.

  • A generator must output things like (input,output) in a tuple.
  • Yours is outputting ((input1,output1), (input2,output2)), tuples inside a tuple.

When your model gets a batch from the generator, it's trying to get the shape of what it thinks is the input, but it finds (input,output) instead.

Working the generator:

You can probably create your own generator like this:

def myGenerator(train_generator,train_generator1):

    while True:

        xy = train_generator.next() #or next(train_generator)
        xy1 = train_generator1.next() #or next(train_generator1)
        yield (xy[0],xy1[0])

Instantiate it with:

train_generator2 = myGenerator(train_generator,train_generator1)

Now, you're going to have real trouble with the output shapes. If you're working from image to image, I recommend you work with a purely convolutional model.

A convolutional layer outputs (Batch, Side1, Side2, channels), which is the shape you are working with in your images.

But a dense layer outputs (Batch, size). This can only work if you reshape it later with Reshape((200,150,3)) to match your "true images".

Hint: a Dense 20 in the middle of the model may be too little to represent an entire image. (But of course it depends on your task).

A possible model from this task is:

Conv
... Maybe more convs
MaxPooling
Conv
... Maybe more convs
MaxPooling
Conv

......

UpSampling
Conv
...
UpSampling
Conv
....

Every convolution with padding='same' to make your life easier. (But since you have one dimension being 150, you will have to manage padding the values at some point, because when you reach 75, the MaxPooling will remove/add one pixel (75 cannot be divided by two).

🌐
GitHub
github.com › serengil › deepface › issues › 1120
Error on verfiy function call: AttributeError: 'tuple' object has no attribute 'shape' · Issue #1120 · serengil/deepface
March 18, 2024 - AttributeError Traceback (most ... > 0: 199 if grayscale is True: 200 current_img = cv2.cvtColor(current_img, cv2.COLOR_BGR2GRAY) AttributeError: 'tuple' object has no attribute 'shape'...
Author   sanket-valani-tss
🌐
Lightning AI
lightning.ai › trainer
'tuple' object has no attribute 'trainer' - Trainer - Lightning AI
August 1, 2023 - Hello, I bump into this error while trying to train my network: Traceback (most recent call last): File "TrainMain.py", line 229, in <module> trainer.fit(model, dataloader) File "/usr/local/lib/python3.8/dist-p…