I don't know if you solved this already. You have to check for 0 length indexes before the for loop like this:

if len(indexes) > 0:
    for i in indexes.flatten():
        ....

That way it won't enter the for loop when indexes length is 0 which is causing the error.

Regards!

Answer from andrestascon on Stack Overflow
🌐
GitHub
github.com › open-mmlab › mmdetection › issues › 6141
AttributeError: 'tuple' object has no attribute 'flatten' · Issue #6141 · open-mmlab/mmdetection
September 20, 2021 - Describe the bug I'm trying to train a Mask-RCNN-r50 on a custom dataset of type COCODataset with 5 classes. The config file is very simple: the only differences from the base config mask_rcnn/mask_rcnn_r50_fpn_1x_coco.py are the number of classes and the usage of a custom dataset . Even so, the train fails with an AttributeError.
Author   AndreaPi
Discussions

python - I'm getting an attribute error using tensorflow - Stack Overflow
I'm pretty new to python and this code is for object detection, it works fine on my webcam but has an error when using an external camera This is what I have: for classId, confidence,box in zip(cla... More on stackoverflow.com
🌐 stackoverflow.com
I'm getting an attribute error using tensorflow - D Programming Language Discussion Forum
D Programming Language More on forum.dlang.org
🌐 forum.dlang.org
AttributeError: 'tuple' object has no attribute 't'
Hi all, I am using a feature extraction module as given below: class FeatureExtractionModule(nn.Module): def __init__(self,feature_dimension,input_channels, kernel_size = 5, dropout_p = 0.3,leakiness = 0.01): super(FeatureExtractionModule,self).__init__() # Defining the hyperparameters of the ... More on discuss.pytorch.org
🌐 discuss.pytorch.org
1
0
May 11, 2020
python - AttributeError: 'tuple' object has no attribute - Stack Overflow
I'm a beginner in python. I'm not able to understand what the problem is? def list_benefits(): s1 = "More organized code" s2 = "More readable code" s3 = "Easier code reuse... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › ml-explore › mlx-examples › issues › 31
Whisper AttributeError: 'tuple' object has no attribute 'flatten'
December 7, 2023 - (venv) (base) ➜ whisper git:(main) ✗ python app.py Traceback (most recent call last): File "/Users/adrian/Developer/mlx-examples/whisper/app.py", line 5, in <module> text = whisper.transcribe(speech_file)["text"] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/adrian/Developer/mlx-examples/whisper/whisper/transcribe.py", line 303, in transcribe timestamps = tokens[timestamp_tokens.nonzero().flatten()] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'tuple' object has no attribute 'flatten' 👍React with 👍1JRWSP ·
Author   adriangalilea
🌐
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.
🌐
Stack Overflow
stackoverflow.com › questions › 63949273 › im-getting-an-attribute-error-using-tensorflow
python - I'm getting an attribute error using tensorflow - Stack Overflow
I'm pretty new to python and this code is for object detection, it works fine on my webcam but has an error when using an external camera This is what I have: for classId, confidence,box in zip(classIds.flatten(),confs.flatten(),bbox): cv2.rectangle(img,box,color=(0,255,0),thickness=2) cv2.putText(img,classNames[classId-1].upper(),(box[0]+10,box[1]+30), cv2.FONT_HERSHEY_COMPLEX,1,(0,255,0),2)
🌐
YouTube
youtube.com › watch
Resolving the AttributeError: 'tuple' object has no attribute 'flatten' in Python - YouTube
Discover effective solutions for the `AttributeError: 'tuple' object has no attribute 'flatten'` error in Python, particularly in NumPy and OpenCV contexts.-...
Published   July 24, 2025
Views   4
Find elsewhere
🌐
PyTorch Forums
discuss.pytorch.org › vision
AttributeError: 'tuple' object has no attribute 't' - vision - PyTorch Forums
May 11, 2020 - Hi all, I am using a feature extraction module as given below: class FeatureExtractionModule(nn.Module): def __init__(self,feature_dimension,input_channels, kernel_size = 5, dropout_p = 0.3,leakiness = 0.01): super(FeatureExtractionModule,self).__init__() # Defining the hyperparameters of the ...
🌐
Free Python Source Code
freepythonsourcecode.com › post › 117
With Examples Fix attributeerror: 'tuple' object has no attribute ...
September 29, 2024 - The AttributeError: 'tuple' object has no attribute, which occurs when accessing an attribute or method that doesn't exist for a tuple object in Python.
🌐
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 ?
🌐
Initial Commit
initialcommit.com › blog › numpy-ndarray-flatten
ndarray.flatten() function | NumPy.matrix.flatten - Initial Commit
August 7, 2022 - >>> twoDArray = np.array([[1, 2, 3, 4], ... [5, 6, 7]]) <stdin>:1: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. >>> twoDArray array([list([1, 2, 3, 4]), list([5, 6, 7])], dtype=object) The resulting ndarray will not be proper as it will just be an ndarray containing lists, and you won't be able to use all the numpy ndarray features correctly. To flatten an array in numpy means to convert a multi-dimensional array into a 1-dimensional array.
🌐
Johnnn
johnnn.tech › home › questions › attributeerror: ‘tuple’ object has no attribute ‘flatten’
AttributeError: 'tuple' object has no attribute 'flatten' - Johnnn
May 17, 2021 - can I know how to solve this error. AttributeError: 'tuple' object has no attribute 'flatten' for i in indexes.flatten(): x, y, w, h = boxes[i] label = str(classes[class_ids[i]]) confidence = str(round(confidences[i],2)) color = colors[i]...
🌐
PyTorch Forums
discuss.pytorch.org › vision
Error: AttributeError: 'tuple' object has no attribute 'size' - vision - PyTorch Forums
January 4, 2023 - Hi, I am working on Age and Gender prediction. I get this error "AttributeError: ‘tuple’ object has no attribute ‘size’ ". ‘’’ Combine Gender and Age y_gender_age = np.stack((y_gender, y_age), axis=1) y_gender_age[0:5…
🌐
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.
🌐
GitHub
github.com › keras-team › keras › issues › 13943
please help to resolve the problem: 'tuple' object has no attribute 'layer' in line : x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img) · Issue #13943 · keras-team/keras
April 7, 2020 - import numpy as np #import keras import tensorflow.keras #from keras.datasets import mnis from sklearn.model_selection import train_test_split from tensorflow.keras.layers import Dense, Dropout, Flatten from tensorflow.keras.layers import Conv2D, MaxPooling2D, Conv2DTranspose, Reshape , UpSampling2D from keras.models import Model, Input from keras.layers import Concatenate, concatenate from keras.backend.tensorflow_backend import set_session from keras.backend.tensorflow_backend import clear_session from keras.backend.tensorflow_backend import get_session import tensorflow from PIL import Image from array import array import gc import os from keras.utils import np_utils
Author   usthbstar