obendidi / Tracking-with-darkflow

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

error while running the second time #9

Closed sureshbona closed 7 years ago

sureshbona commented 7 years ago

Hi

I have modified run.py by defining a function run(videoPath) which takes video as an input and assign that to FLAGS.demo and runs the original Tracking-with-darkflow.

Now, If I call this run(videoPath) for the first time it runs properly but for the second time, it throws the error.

I have attached code and error to this post. Can you please help in solving this error.

Thanks in advance.

# run.py

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

def run(videoPath):

    FLAGS = argHandler()
    FLAGS.setDefaults()

    FLAGS.demo = videoPath # video file to use, or if camera just put "camera"
    FLAGS.model = "darkflow/cfg/yolo.cfg" # tensorflow model
    FLAGS.load = "darkflow/bin/yolo.weights" # tensorflow weights
    FLAGS.threshold = 0.35 # 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 = "person" # the object to be tracked
    FLAGS.saveVideo = False  #whether to save the video or not
    FLAGS.BK_MOG = False # 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 < 5, as it is still better than no detection.
    FLAGS.tracker = "deep_sort" # wich algorithm to use for tracking deep_sort/sort (NOTE : deep_sort only trained for people detection )
    FLAGS.skip = 0 # how many frames to skipp between each detection to speed up the network
    FLAGS.csv = True #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.')

print("Running for the first time")
run("data/test_1.avi")

print("Running for the second time")
run("data/test_2.avi")

twd-error

obendidi commented 7 years ago

this is because you try to create two graphs with the same name variables :

to

def camera(self,file):
    SaveVideo = self.FLAGS.saveVideo

and then in run.py it will be like this :

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

FLAGS = argHandler()
FLAGS.setDefaults()

FLAGS.model = "darkflow/cfg/yolo.cfg" # tensorflow model
FLAGS.load = "darkflow/bin/yolo.weights" # tensorflow weights
FLAGS.threshold = 0.25 # threshold of decetion confidance (detection if confidance > threshold )
FLAGS.gpu = 0.75 #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 = "person" # the object to be tracked
FLAGS.saveVideo = False  #whether to save the video or not
FLAGS.BK_MOG = False # 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 < 5, as it is still better than no detection.
FLAGS.tracker = "deep_sort" # wich algorithm to use for tracking deep_sort/sort (NOTE : deep_sort only trained for people detection )
FLAGS.skip = 0 # how many frames to skipp between each detection to speed up the network
FLAGS.csv = True #whether to write csv file or not(only when tracking is set to True)
FLAGS.display = False # display the tracking or not

tfnet = TFNet(FLAGS)

print("Running for the first time")
tfnet.camera("data/test_1.avi")

print("Running for the second time")
tfnet.camera("data/test_2.avi")

Hope it helps !

sureshbona commented 7 years ago

Thank you @bendidi. The first method worked for me and the second method gave the same error.