Python: Real Time Object Detection (Image, Webcam, Video files) with Yolov3 and OpenCV

Поділитися
Вставка
  • Опубліковано 4 лис 2024

КОМЕНТАРІ • 322

  • @rightOrWrongMyContry
    @rightOrWrongMyContry 4 роки тому +60

    Didn't work with video until i added "if len(indexes)>0:" before "for i in indexes.flatten():".

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 роки тому +21

      Thanks a lot. This is a very good point to cater the null issue. I didn't realize it. Hope you don't mind if I pin your comment.

    • @rightOrWrongMyContry
      @rightOrWrongMyContry 4 роки тому +5

      @@eMasterClassAcademy I don't mind, thanks for the video.

    • @dompower500
      @dompower500 4 роки тому +1

      Thankx E K. Especially for Yoyov3-tiny

    • @kprakash9665
      @kprakash9665 4 роки тому

      @@rightOrWrongMyContry did you got this Object detection by this video..

    • @joshuamawutorklint6046
      @joshuamawutorklint6046 3 роки тому +2

      no rectangular boxes shown anytime video is used any help

  • @GodMouthPiece237
    @GodMouthPiece237 4 роки тому +5

    Thanks very much for this tutorial it save me from failing my continuous Assessment. The expalnations were so clear and the codes were correct. Writing from Cameroon

    • @mzwenkosihlela7989
      @mzwenkosihlela7989 3 роки тому

      Hi do you still have this source code ? I also need it there is something I want to check on it.

  • @shubhampawar3739
    @shubhampawar3739 Рік тому +2

    Great job brother.Thanks a lot
    It helped me for making my first project ❤❤🎉

  • @timotiusleonardo1966
    @timotiusleonardo1966 3 роки тому +1

    Thank you Master class academy for the video, it really helps my Final Project... will be waiting for another tutorial

  • @ajalthomas5070
    @ajalthomas5070 3 роки тому

    opening background score was op...:)

  • @sauravchaudhary3064
    @sauravchaudhary3064 3 роки тому

    It worked for me, Thanks for your content. Appreciate your efforts.

  • @MrModifyman
    @MrModifyman 2 роки тому

    Thank you for this tutorial, this was exactly what I was looking for. Helped me a ton! :D

  • @kwilight319
    @kwilight319 4 роки тому

    Thank you so much. Your explanation is very details. Help me a lot. Recommended Channel !!!

  • @bestchoice6749
    @bestchoice6749 Рік тому +1

    I am getting the error.
    Attribute Error: 'tuple' object has no attribute 'flatten'" even though i have added the code as suggested. How to solve this error, please?

  • @TheBontenbal
    @TheBontenbal 4 роки тому +1

    Very nice! Works really well, thank you.

  • @mohammadzamanzamani9775
    @mohammadzamanzamani9775 Рік тому +1

    Great video , many thanks !

  • @abdulwarissherzad9914
    @abdulwarissherzad9914 3 роки тому

    Thank you at all great work, Keep continuing, appreciate you.

  • @subhashishbagchi3191
    @subhashishbagchi3191 3 роки тому

    Thanks a lot of this video because it help me a lot with the project in my college

  • @yashmistry61
    @yashmistry61 4 роки тому +4

    in video how can we extract more frames? like smooth video
    This is my first practical tutorial in computer vision and i enjoyed very much thank you

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 роки тому +1

      The "Frame per second" (FPS) is somehow limited by the OpenCV function because it's not using any gpu. And the best way to speed up the whole process is using a gpu under darknet, however, it's a bit out of the scope of my channel because it's more related to implementation instead of coding and programming.

  • @Asmelash2023
    @Asmelash2023 4 роки тому +1

    Great video, great explaniation just perfect.

  • @mrian798
    @mrian798 3 роки тому +2

    'cv2.dnn_Net' object has no attribute 'getUnconnectedOutLayersNames'
    how to solve this?

  • @Pankaj-zl8sv
    @Pankaj-zl8sv 4 роки тому

    thank you soo much sir very good explaination love to seee whole implementation very nicely explained

  • @naveedbhuiyan9855
    @naveedbhuiyan9855 4 роки тому

    What an amazing video....very descriptive and useful
    cant seem to make it work with the webcam though

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 роки тому

      Thanks for your comment. Maybe you could try different number in the VideoCapture() function. Sometimes, it doesn't necessary to be 0, especially when you have a few webcam available.

  • @munalatifi3757
    @munalatifi3757 3 роки тому

    works perfectly thank you so much!!!

  • @aqsamalik4262
    @aqsamalik4262 4 роки тому +1

    Great Work Sir

  • @dompower500
    @dompower500 4 роки тому +1

    Execllent video demonstration. Can you pls make one video for custom object detection ? Example: Car number plates detection. May be with or without tensorflow.

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 роки тому

      Appreciate with your great comment. Please check this out.
      ua-cam.com/video/DLngCtsG3bk/v-deo.html

  • @shrikantverma8600
    @shrikantverma8600 3 роки тому

    great... it's working for me.
    But I have a question @eMaster Class Academy .... How to calculate accuracy??? please tell me tomorrow is my presentation I have to show the accuracy too.

  • @theredtree7493
    @theredtree7493 2 роки тому +1

    OMG THANK YOU SOO MUCHHHH!!!

  • @pavancheyutha3228
    @pavancheyutha3228 4 роки тому +1

    Thank you very much Your video helped me very much in my work.

    • @satyamrai8021
      @satyamrai8021 3 роки тому

      Hey bro can you please share this code with me ?

  • @kokomokio1726
    @kokomokio1726 4 роки тому

    Thanks for another great video!

  • @dikshagaonker5958
    @dikshagaonker5958 3 роки тому +1

    Coco dataset has 80 classes. So can it be altered? Like add one label externally? Will that work? I want to detect drone as well in the given input video to the algorithm. Can anyone suggest.. How would it be possible

  • @twinblade02
    @twinblade02 3 роки тому +1

    Question: How would one go about evaluating detections using IoU?

  • @udyaunni8553
    @udyaunni8553 4 роки тому +3

    I got a error 'for i in indexes.flatten():
    AttributeError: ' tuple' object has no attribute ' flatten'
    Can say why this error

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 роки тому

      Please add "if len(indexes)>0:" before "for i in indexes.flatten():"
      This is to avoid flattening a null value, due to nothing being detected.

  • @coenbushwool6968
    @coenbushwool6968 4 роки тому

    Thank you for creating this nice video!

  • @dompower500
    @dompower500 4 роки тому

    Excellent tutorial. Also easy to follow. Only one question. How to play the video without dropping frames in real time??

  • @Kishi1969
    @Kishi1969 3 роки тому

    Beautiful lecture but i had problem but through stack , i found solution ( if len(indexes) > 0:)
    thanks

    • @eMasterClassAcademy
      @eMasterClassAcademy  3 роки тому +1

      Thank you Benya. You are absolutely correct. That would cater the problem that an image doesn’t have any detections.

    • @Kishi1969
      @Kishi1969 3 роки тому

      @@eMasterClassAcademy Thanks 🙏

  • @harsh2014
    @harsh2014 3 роки тому

    Thanks, it helped me a lot.

  • @WisdomWhispers807
    @WisdomWhispers807 Рік тому

    Thank you so much for this video. I keep getting this error: layerOutputs = net.forward(output_layers_names)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    cv2.error: Unknown C++ exception from OpenCV code
    Do you have any solution for this?

  • @chinmayganguly457
    @chinmayganguly457 2 роки тому

    i'm already stuck in the beginning with the darknet installation process. i cloned the git repository, typed in the cd command and then when i typed make, it says unrecognized command. what do i do now?

  • @learncomputersciencewithfaisal
    @learncomputersciencewithfaisal 3 роки тому

    Good explanation

  • @fatemadalal4370
    @fatemadalal4370 3 роки тому

    Hello, I am working on colab and it restricts the use of cv2.imshow. How to see the output img_blob in colab.? Kindly help me with that.

  • @arnabsaha1549
    @arnabsaha1549 4 роки тому

    Thank you for the video sir! If I want to run the video detection program in pyqt5 UI then How can I display the video in Pyqt5 label?
    And also how can I show a counter of a particular object in the UI?

  • @programmingwithguri1454
    @programmingwithguri1454 4 роки тому +3

    hlo bro,this code is not working on videos is not working

  • @christiankurtvalencia2561
    @christiankurtvalencia2561 3 роки тому +4

    hello, i got an error like "AttributeError: 'tuple' object has no attribute 'flatten'" when i do it on video feed, can anyone help me for the fix? thanks.

    • @easwarraja8671
      @easwarraja8671 3 роки тому +1

      Even I got that same error sir!

    • @foldedalpaca4990
      @foldedalpaca4990 3 роки тому

      Havent finished watching the video I'm only 4 min in. But tuples are hard to reshape compared to lists and ndarrays. You might want to do tupleyouhave = np.asarray(tupleyouhave).flatten or .ravel. but if you need to preserve a series of shapes (a sequence of matrices for example) you could use either the xarray library and convert to a DataArray object or make a list object holding each matrix. Indexing on the list is much harder than the DataArray though. Tuples are immutable so they aren't meant to be changed or reshaped. List is mutable and thus can be altered, flattened etc.
      I know I'm late but for anybody possibly having the same issue I hope I helped :)

    • @foldedalpaca4990
      @foldedalpaca4990 3 роки тому

      @@easwarraja8671 and Christian

  • @talhagerginn7672
    @talhagerginn7672 Рік тому +1

    Great videos. I have question. label = str(classes[class_ids[i]])
    IndexError: list index out of range. help please

    • @eMasterClassAcademy
      @eMasterClassAcademy  Рік тому

      Thanks for watching. I think it’s because there is no detection. So you need to add an “if statement” to tackle this issue.
      Please find the answer in the comment section.
      Hope it helps.

  • @j.sgaming1544
    @j.sgaming1544 2 роки тому

    hello sir, please specify name of dataset you have used for those 80 classes

  • @blackpearl3405
    @blackpearl3405 2 роки тому

    Thank you so much for the excellent explanation. I just have one problem if I only want to detect a certain objet ( vehicles for example) how should I modify the code ?

  • @srinidhiganta5937
    @srinidhiganta5937 3 роки тому

    Can't we do this for all the images in openimages dataset...then it will be more efficient to detect all the objects na?...please clarify

  • @akashsahu410
    @akashsahu410 4 роки тому +4

    Please make a video on how to train yolov3 on custom dataset in windows

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 роки тому +1

      Thanks for your comment. Please find details here - ua-cam.com/video/DLngCtsG3bk/v-deo.html

  • @TECH-TOMAS
    @TECH-TOMAS 2 роки тому

    if confidence > 0.5: TypeError: '>' not supported between instances of 'list' and 'float'
    please give me solution

  • @siddhirane7831
    @siddhirane7831 2 роки тому

    I tried all possible ways for Webcam but still getting error for the shape line .Wat should i do for the webcam?

  • @dikshagaonker7877
    @dikshagaonker7877 3 роки тому

    Thank you for the video. But I need the help as inspite of following the full video still my code is not showing the output.It is not showing any error as well. But just showing the same image without detection. Please suggest me what should I do.

  • @nishatansari1633
    @nishatansari1633 2 роки тому

    live video capture detection is not working, the web cam light gets on but nothing is being displayed

  • @rajkumariyer8923
    @rajkumariyer8923 2 роки тому

    Hey there, I was able to detect the object from a video file and was also able to get the confidence level, but could not identify the object by name. Can you please help me with the same. Thanks!!!!

  • @DreamArtsPk
    @DreamArtsPk 3 роки тому

    Hey please help i just followed you and detection is ok its detecting the objects in image but showing rectangles at wrong positions

  • @shahrozi2574
    @shahrozi2574 3 роки тому

    I am getting error at video file at....
    color = colors[i]
    It shows IndexError:index 2949 is out of bounds for axis 0 with size 100
    Help 🙏

  • @gaganagavesh3679
    @gaganagavesh3679 4 роки тому

    Thanks for the nice video, learned a lot.....

  • @AkashKumar-vt9gb
    @AkashKumar-vt9gb 4 роки тому

    THANKYOU SO MUCH

  • @gurmanjotsingh4081
    @gurmanjotsingh4081 4 роки тому +3

    AttributeError: 'tuple' object has no attribute 'flatten'
    in the line " for i in indexes.flatten(): "
    How do i resolve this error?

    • @mrlevo27
      @mrlevo27 3 роки тому +1

      yeah i got the same problem :/
      any solution?

    • @devendratrivedi1630
      @devendratrivedi1630 3 роки тому +2

      @@mrlevo27 add "if len(indexes)>0:" before "for i in indexes.flatten():".

  • @Unreality_3D
    @Unreality_3D 3 роки тому +1

    Hi, I am getting the error "for i in indexes.flatten():
    AttributeError: 'tuple' object has no attribute 'flatten'" even though i have added the code as suggested.
    if len(indexes)>0:
    for i in indexes.flatten():
    x, y, w, h = boxes[i]
    label = str(classes[class_ids[i]])
    confidence = str(round(confidence[i],2))
    colour = colors[i]
    cv2.rectangle(img,(x,y), (x+w, y+h), color, 2)
    cv2.putText(img, label + " " + confidence, (x, y+20), font, 2, (255,255,255), 2)

  • @vishabali8907
    @vishabali8907 2 роки тому

    hi there.. how we can test the performance like accuracy and execution time of this model

  • @amruthabv4240
    @amruthabv4240 4 роки тому

    Why real time object detection vedio is not displayed full screen of laptop instead it displaying in small window in screen?

  • @AtenTetsu
    @AtenTetsu 3 роки тому

    hi, first of all thank you so much for this video tutorial. I want to know, can this code apply to raspberry pi board and add measurement distancing system? Thank you.

  • @eddielo3578
    @eddielo3578 2 роки тому

    cannot keep the "color = ......" line out of the while loop the variable does not exist

  • @insharaaj8259
    @insharaaj8259 2 роки тому

    Can you please make video on real time plant disease and pest detection. This will be a very good project.

  • @mayurmoundekar5252
    @mayurmoundekar5252 3 роки тому

    Hello Sir
    I want to add one feature in this project
    In case screen will empty NO Object are in the screen. So it will display "NO OBJECT DETECTED"
    How we add this feature
    I try some if statement code but it was not succes
    Please help me to add this feature
    Please provide code

  • @matematikvebilgisayarbilim9789
    @matematikvebilgisayarbilim9789 2 роки тому

    Hello Thanks for sharing to this video us ☺️ I want to ask someting before apply this.Can this application recognize stone rocks ? if its possible i want to apply ☺️

  • @ashwinr5078
    @ashwinr5078 4 роки тому +1

    at 22:48 if you check you have used class_id instead of clss_ids but it did nt affect your response... may I know how you managed the same. Mine is showing " NameError: name 'class_id' is not defined "

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 роки тому

      Thanks for watching the video. That's a typo.
      And I manage to correct it at 26:35, please proceed to the time and check this out, ua-cam.com/video/1LCb1PVqzeY/v-deo.html,

  • @muhammadzahirazmibinkhairo8705
    @muhammadzahirazmibinkhairo8705 2 роки тому

    Hi. I have some error when running the code. " DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
    if confidence > 0.5: " . and not detect any object , just show the image only. Pls someone can help me....

  • @jayanthraj6576
    @jayanthraj6576 4 роки тому

    I want to build a model that detects sheds from google maps I already built a yolo model wich detects sheds but problem I am facing is with capturing the screen and feeding it as input to my model any idea or suggestions???

  • @shahriarislam5107
    @shahriarislam5107 3 роки тому +1

    TypeError Traceback (most recent call last)
    in
    28 scores = detection[5:]
    29 class_id = np.argmax(scores)
    ---> 30 confidences = scores(class_id)
    31
    32 if confidence > 0.5:
    TypeError: 'numpy.ndarray' object is not callable
    Why show this error?

    • @felipepacheco2335
      @felipepacheco2335 3 роки тому

      I haave the same problem, does any one know how to fix this?

  • @dhiaeddinedaikhi4604
    @dhiaeddinedaikhi4604 4 роки тому

    hello if i want only to detect 3 of the objects that already pretrained i mean existing in the list but only those objects what you recommend that I do(not customized already pretrained but only I need those objects I don't need the others)

  • @TalhaUs2244
    @TalhaUs2244 3 роки тому

    how can i use this code file with android studio

  • @GhostRider09876
    @GhostRider09876 2 роки тому +1

    can anyone help me it is unable to detect my path

  • @sravan08
    @sravan08 3 роки тому

    Thank you

  • @ibrahimkaiser7961
    @ibrahimkaiser7961 4 роки тому +1

    Thank you for this tutorial. I've learned a lot from this video. I want to implement deep SORT with it. If you've any tutorial or information regarding this, please let me know. I wish you good luck!

  • @dexterchewy
    @dexterchewy 2 роки тому +1

    just curious, is it very slow when using webcam??

    • @eMasterClassAcademy
      @eMasterClassAcademy  2 роки тому +1

      Thanks for watching. This is because the setup is only using CPU.
      Please check this video. ua-cam.com/video/zi-62z-3c4U/v-deo.html
      This video shows you how to implement yolo in tensorflow to speed up the FPS with GPU.

    • @dexterchewy
      @dexterchewy 2 роки тому

      @@eMasterClassAcademy this is great thanks. Tensorflow uses gpu right

  • @kotiba-kutaybaaldibs1054
    @kotiba-kutaybaaldibs1054 5 місяців тому

    it did not work, but thanks for video. i tried to do it step by step, still not working, tried to download the source code from your github and i loaded a video of traffic. there is no boxes drawed. i dont know but there is something wrong could not configure it.

  • @tarekradwan8661
    @tarekradwan8661 3 роки тому

    my confidence scores are very very low --they don't even exceed 0.1 , I have tried with many images but still facing the same issue.

  • @trickypython9928
    @trickypython9928 3 роки тому

    but when we try with hp default cam. Cam will be freeze and automatically quit after some time .please help me to overcome with this problem.

  • @nhatminhle2900
    @nhatminhle2900 3 роки тому

    i've seen that the FPS for videocapture quite slow, so how can we optimize it?

  • @AI913
    @AI913 3 роки тому

    Thank you sir!
    I have a question: I wonder how it is possible if I want to detect objects in videos in a web browser or a mobile phone screen, without downloading the video?
    For example, if I want to detect objects in an Instagram video, without downloading it, how can I achieve it? Is it possible?
    BTW, are you from Hong Kong? lol

    • @humoruniverse6399
      @humoruniverse6399 3 роки тому +1

      You can set your code like this cap = cv2.Videocapture(0) as a webcam and then show your image or video from your phone to webcam then it will work, ı've tried.

    • @shivamverma1117
      @shivamverma1117 3 роки тому

      @@humoruniverse6399 great logic

  • @สุภทัตห่อวโนทยาน

    Thank you for your amazing video
    Actually, I am looking for a good object detection algorithm for my autonomoud driving project.
    Do you think that this YOLO algorithm will be suitable for self-driving cars project?
    Thank you very much

  • @ghumakkadIITianvlogs
    @ghumakkadIITianvlogs 4 роки тому +1

    I have implemented same code but getting all output labels are 0 except first 5? why?

    • @ghostlySmG
      @ghostlySmG 4 роки тому

      were you able to figure it out? Just followed the code today and thats what im getting as well

  • @nagasainattuva1152
    @nagasainattuva1152 2 роки тому

    How can we integrate the result to frontend reactjs to display?

  • @rhalppalanca3273
    @rhalppalanca3273 3 роки тому

    Can i modify Yolov3 codes to light LED after detection is done?

  • @GrigoriKog
    @GrigoriKog Рік тому

    Is it possible to built an interface to display the content ?

  • @notumagansan2513
    @notumagansan2513 3 роки тому

    hello im getting an error that numpy.int64' object has no attribute 'append' pls help

  • @chanhwasheng5454
    @chanhwasheng5454 3 роки тому

    Hi, may I know how to use the external ps3 USB camera for detection instead of using the webcam from the laptop.
    cap = cv2.VideoCapture(0) this is for webcam
    however, I want to use the external USB camera, can I know what should I put inside the bracket.
    I have tried this, but couldn't work out as it said no attribute shape.
    AttributeError: 'NoneType' object has no attribute 'shape'

  • @awaltry77
    @awaltry77 4 роки тому +1

    Hello i want ask a question, can i change the object and just want to detect fruit like an Apple,Orange etc?

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 роки тому +1

      I was thinking the custom object training and detection might help you. ua-cam.com/video/DLngCtsG3bk/v-deo.html

  • @ihebchiha9205
    @ihebchiha9205 2 роки тому

    Hello, does including negative photos to my dataset improve the detection of custom object?

    • @eMasterClassAcademy
      @eMasterClassAcademy  2 роки тому

      hi Iheb, thanks for watching the video. It probably would not improve the detection of custom object if you include "negative" photos. I would rather prefer to have more "positive" photos.

  • @garrisonhustle3289
    @garrisonhustle3289 4 роки тому

    Nice tutorial!

  • @saraamiri2460
    @saraamiri2460 2 роки тому

    when i add net = cv2.dnn.readNet('yolov3.weights', 'yolov3.cfg') i got this error
    Traceback (most recent call last):
    File "", line 1, in
    AttributeError: module 'cv2' has no attribute 'dnn'
    i dont know what is wrong . plz help me someone

  • @RnRSolutions-xp2nh
    @RnRSolutions-xp2nh Рік тому

    Anyway to contact you regarding a facial recog system:?

  • @yolov3237
    @yolov3237 3 роки тому +2

    i'll try this code tomorrow ! I hope it will work. Need Prayers.

  • @gaganagavesh3679
    @gaganagavesh3679 4 роки тому

    How can I increase the fps . I added a video and run ,it runs very slow manner. How can I eliminate the slowness, Please help....

  • @lilianleonidas9565
    @lilianleonidas9565 3 роки тому

    what platform do you use to run python?that appears like gui

  • @lostparlour
    @lostparlour 2 роки тому

    Can't parse 'scores'. Input argument doesn't provide sequence protocol
    can anyone help me with this? thanks alot
    code:
    indexes = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4)

  • @Alpha-hj2ss
    @Alpha-hj2ss 3 роки тому

    Help please! the training process stop here
    "608 x 608
    Create 6 permanent cpu-threads "

  • @haniatarik7454
    @haniatarik7454 3 роки тому

    Great video. Can you also explain how to download the coco dataset for using in this?

    • @eMasterClassAcademy
      @eMasterClassAcademy  3 роки тому

      github.com/pjreddie/darknet/blob/master/data/coco.names
      Go to the above link, right click the raw and choose save link as
      Hope it helps.

    • @haniatarik7454
      @haniatarik7454 3 роки тому

      @@eMasterClassAcademy These are just the labels? I wanted to use the images and the labels for my own object detection task. I'm a beginner and I would really appreciate if you can show me how to download, run or open coco dataset using visual studio or any other IDE.

  • @ravimakwana5290
    @ravimakwana5290 3 роки тому

    Sir can you provide the deployment video for yolo v3 in docker

  • @sivabanu5677
    @sivabanu5677 3 роки тому

    I need to detect the vehicles type and number plate's number ? Can you help me please ??

  • @sarthakkale5188
    @sarthakkale5188 4 роки тому +2

    I need to detect triple rider on a motorbike along with no helmet detection. Can you help?

    • @eMasterClassAcademy
      @eMasterClassAcademy  4 роки тому +1

      Please check out my video in how to implement custom object detection. It definitely can solve your problem. ua-cam.com/video/DLngCtsG3bk/v-deo.html

  • @davejornales4985
    @davejornales4985 3 роки тому

    I want to ask how can it be implemented in tensorflow?

  • @vishvajitviswanathan7970
    @vishvajitviswanathan7970 3 роки тому

    Bro, it's not working for both video and live camera bro. I'm using yolov3.tiny.weight... whenever I try it's says tuple has no attribute flatten()... But when I try this for image I saw the type as np.array... how come the type gets changed when we try in video... Please reply ASAP 🙏🙏😭😭😭😭

    • @eMasterClassAcademy
      @eMasterClassAcademy  3 роки тому +1

      Please add this "if len(indexes)>0:" before "for i in indexes.flatten():".
      This is to handle the "no attribute flatten()".
      Hope it helps.