Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deep_sort/tools/generate_detections leads to Tensorflow builtins.KeyError #313

Open
jvkloc opened this issue Jun 8, 2023 · 0 comments
Open

Comments

@jvkloc
Copy link

jvkloc commented Jun 8, 2023

I'm trying to write a code for implementing YOLOv8 detection and DeepSORT tracking to mp4 video opened with OpenCV (if I get this working, I'll move to real time RealSense video stream). However, when using DeepSORT tracking tools I end up getting a Tensorflow builtins.KeyError in tensorflow/python/framework/ops.py:

 File "/home/jvkloc/Documents/TKT/Python/Sonify/realsense_main.py", line 22, in <module>
  tracker = Tracker()
File "/home/jvkloc/Documents/TKT/Python/Sonify/Tracker.py", line 22, in __init__
  self.encoder = gdet.create_box_encoder(encoder_model_filename, batch_size=1)
File "/home/jvkloc/Documents/TKT/Python/Sonify/deep_sort/tools/generate_detections.py", line 100, in create_box_encoder
  image_encoder = ImageEncoder(model_filename, input_name, output_name)
File "/home/jvkloc/Documents/TKT/Python/Sonify/deep_sort/tools/generate_detections.py", line 80, in __init__
  self.input_var = tf.compat.v1.get_default_graph().get_tensor_by_name(
File "/home/jvkloc/.local/lib/python3.8/site-packages/tensorflow/python/framework/ops.py", line 4188, in get_tensor_by_name
  return self.as_graph_element(name, allow_tensor=True, allow_operation=False)
File "/home/jvkloc/.local/lib/python3.8/site-packages/tensorflow/python/framework/ops.py", line 4012, in as_graph_element
  return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
File "/home/jvkloc/.local/lib/python3.8/site-packages/tensorflow/python/framework/ops.py", line 4052, in _as_graph_element_locked
  raise KeyError("The name %s refers to a Tensor which does not "

builtins.KeyError: "The name 'net/images:0' refers to a Tensor which does not exist. The operation, 'net/images', does not exist in the graph."

This is the Tracker class I'm trying to use:

# Tracker class for realsense_main.py object tracking script
from deep_sort.deep_sort.tracker import Tracker as DeepSortTracker
from deep_sort.tools import generate_detections as gdet
from deep_sort.deep_sort.detection import Detection
from deep_sort.deep_sort import nn_matching
import numpy as np

class Tracker():
    tracker = None
    encoder = None
    tracks = None
    
    def __init__(self):
        max_cosine_distance = 0.4
        nn_budget = None
        encoder_model_filename = 'mars-small128.pb'
        metric = nn_matching.NearestNeighborDistanceMetric('cosine', max_cosine_distance, nn_budget)
        self.tracker = DeepSortTracker(metric)
        self.encoder = gdet.create_box_encoder(encoder_model_filename, batch_size=1)
    
    def update(self, frame, detections):
        bboxes = np.asarray([d[:-1] for d in detections])
        bboxes[:, 2:] = bboxes[:, 2:] - bboxes[:, 0:2]
        scores = [d[-1] for d in detections]
        features = self.encoder(frame, bboxes)
        dets = []
        for bbox_id, bbox in enumerate(bboxes):
            dets.append(Detection(bbox, scores[bbox_id], features[bbox_id]))
        self.tracker.predict()
        self.tracker.update(dets)
        self.update_tracks()

    def update_tracks(self):
        tracks = []
        for track in self.tracker.tracks:
            if not track.is_confirmed() or track.time_since_update > 1:
                continue
            bbox = track.to_tlbr()
            id = track.track_id
            tracks.append(Track(id, bbox))
        self.tracks = tracks

class Track:
    track_id = None
    bbox = None

    def __init__(self, id, bbox):
        self.track_id = id
        self.bbox = bbox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant