obendidi / Tracking-with-darkflow

Real-time people Multitracker using YOLO v2 and deep_sort with tensorflow
GNU General Public License v3.0
524 stars 174 forks source link

`AttributeError: 'NoneType' object has no attribute 'astype' ` occurs after running run.py #38

Closed Ashniu123 closed 6 years ago

Ashniu123 commented 6 years ago

Here is my traceback:

Traceback (most recent call last):
  File "run.py", line 30, in <module>
    tfnet.camera()
  File "/home/nisheetsinvhal/Desktop/Tracking-with-darkflow/darkflow/darkflow/net/help.py", line 124, in camera
    fps = 1 / self._get_fps(frame)
  File "/home/nisheetsinvhal/Desktop/Tracking-with-darkflow/darkflow/darkflow/net/help.py", line 66, in _get_fps
    processed = self.framework.postprocess(net_out, frame)
  File "/home/nisheetsinvhal/Desktop/Tracking-with-darkflow/darkflow/darkflow/net/yolov2/predict.py", line 107, in postprocess
    detections = detections + extract_boxes(self,mask)
  File "/home/nisheetsinvhal/Desktop/Tracking-with-darkflow/darkflow/darkflow/net/yolov2/predict.py", line 40, in extract_boxes
    new_im=new_im.astype(np.uint8)
AttributeError: 'NoneType' object has no attribute 'astype'

This is my run.py

from darkflow.darkflow.defaults import argHandler #Import the default arguments
import os
from darkflow.darkflow.net.build import TFNet

FLAGS = argHandler()
FLAGS.setDefaults()

FLAGS.demo = "camera" # video file to use, or if camera just put "camera"
FLAGS.model = "darkflow/cfg/yolo-voc.cfg" # tensorflow model
FLAGS.load = "darkflow/bin/yolo-voc.weights" # tensorflow weights
# FLAGS.pbLoad = "tiny-yolo-voc-traffic.pb" # tensorflow model
# FLAGS.metaLoad = "tiny-yolo-voc-traffic.meta" # tensorflow weights
FLAGS.threshold = 0.7 # threshold of decetion confidance (detection if confidance > threshold )
FLAGS.gpu = 0 #how much of the GPU to use (between 0 and 1) 0 means use cpu
FLAGS.track = True # wheither to activate tracking or not
FLAGS.trackObj = ['Bicyclist','Pedestrian','Skateboarder','Cart','Car','Bus'] # the object to be tracked
#FLAGS.trackObj = ["person"]
FLAGS.saveVideo = True  #whether to save the video or not
FLAGS.BK_MOG = True # activate background substraction using cv2 MOG substraction,
                        #to help in worst case scenarion when YOLO cannor predict(able to detect mouvement, it's not ideal but well)
                        # helps only when number of detection < 3, as it is still better than no detection.
FLAGS.tracker = "sort" # wich algorithm to use for tracking deep_sort/sort (NOTE : deep_sort only trained for people detection )
FLAGS.skip = 2 # how many frames to skipp between each detection to speed up the network
FLAGS.csv = False #whether to write csv file or not(only when tracking is set to True)
FLAGS.display = True # display the tracking or not

tfnet = TFNet(FLAGS)

tfnet.camera()
exit('Demo stopped, exit.')

In addition to this I had changed the /darkflow/net/help.py a little bit for the new opencv Line 88: fgbg = cv2.createBackgroundSubtractorMOG2()

Any idea how to solve the traceback error?

hilmandayo commented 6 years ago

Have you checked whether the camera is accessible? Maybe the camera can't be accessed -- that is why you got 'NoneType' object has no attribute 'astype'. Have you tried to open the camera with a normal openCV VideoCapture?

Ashniu123 commented 6 years ago

This error got solved by building opencv (I also did install its submodules) from source. This issue can be closed now

stucksubstitute commented 6 years ago

I set saveVideo = False, and now it's working for me.

mursyidinadnan commented 6 years ago

@Ashniu123 can you explain how to solve this problem? thank you