Exemplo n.º 1
0
class TestFeatureTrackSet(unittest.TestCase):
    @classmethod
    def setUp(self):
        self.track_state = TrackState(15)
        self.track = Track(23)
        self.track.append(TrackState(1))
        self.track.append(self.track_state)
        self._track_arr = [Track(15), Track(1),
                                    Track(150), Track(9),
                                    self.track]

    def test_construct(self):
      ftset()
      ftset(self._track_arr)

    def test_methods(self):
      test_feat_set = ftset(self._track_arr)
      self.assertEqual(test_feat_set.all_frame_ids(), {1, 15})
      nt.assert_equal(test_feat_set.get_track(1), self._track_arr[1] )
      self.assertEqual(0, test_feat_set.first_frame())
      self.assertEqual(15, test_feat_set.last_frame())
      self.assertEqual(5, len(test_feat_set.tracks()))
      self.assertEqual(len(test_feat_set), 5)
      cloned_test_feat_set = test_feat_set.clone()
      self.assertIsInstance(cloned_test_feat_set, ftset)
      self.assertEqual(cloned_test_feat_set.all_frame_ids(), test_feat_set.all_frame_ids())
      self.assertIsInstance(test_feat_set.last_frame_features(), sfs)
      self.assertIsInstance(test_feat_set.last_frame_descriptors(), DescriptorSet)
      self.assertIsInstance(test_feat_set.frame_features(), sfs)
      self.assertIsInstance(test_feat_set.frame_descriptors(), DescriptorSet)
      track_state_list = test_feat_set.frame_feature_track_states(15)
      self.assertListEqual(track_state_list, [])
      self.assertEqual(test_feat_set.keyframes(), set())
Exemplo n.º 2
0
 def _create_object_track_set(self):
     bbox = BoundingBox(10, 10, 20, 20)
     dot = DetectedObjectType("test", 0.4)
     do = DetectedObject(bbox, 0.4, dot)
     track = Track()
     for i in range(10):
         track.append(ObjectTrackState(i, i, do))
     return ObjectTrackSet([track])
Exemplo n.º 3
0
    def test_iteration(self):
        t = Track()
        t.append(TrackState(0))
        t.append(TrackState(1))
        t.append(TrackState(5))
        t.append(TrackState(9))

        nose.tools.assert_equal([ts.frame_id for ts in t], [0, 1, 5, 9])
Exemplo n.º 4
0
    def test_all_frame_ids_single_track(self):
        # From a single track
        n = 10
        t = Track(1)
        for i in range(n):
            t.append(TrackState(i))
        ts = TrackSet([t])

        nt.assert_equal(ts.all_frame_ids(), set(range(10)))
Exemplo n.º 5
0
 def test_all_frame_ids_multitrack(self):
     # Across multiple tracks
     n = 10
     t1 = Track(1)
     for i in range(0, n):
         t1.append(TrackState(i))
     t2 = Track(2)
     for i in range(n, n + 5):
         t2.append(TrackState(i))
     ts = TrackSet([t1, t2])
     nt.assert_equal(ts.all_frame_ids(), set(range(n + 5)))
Exemplo n.º 6
0
 def _create_track(self):
     """
     Helper function to create a track
     :return: Track with 10 object track state. Every track state has same
                 detected object however the fram number and time varies from
                 [0, 10)
     """
     bbox = BoundingBox(10, 10, 20, 20)
     cm = ClassMap("test", 0.4)
     do = DetectedObject(bbox, 0.4, cm)
     track = Track()
     for i in range(10):
         track.append(ObjectTrackState(i, i, do))
     return track
Exemplo n.º 7
0
 def setUp(self):
     bbox = BoundingBox(10, 10, 20, 20)
     dot = DetectedObjectType("test", 0.4)
     do = DetectedObject(bbox, 0.4, dot)
     track = Track()
     for i in range(10):
         track.append(ObjectTrackState(i, i, do))
     self.track_ = track
     self.time_1 = Timestamp()
     self.time_1.set_time_seconds(1234)
     self.time_2 = Timestamp()
     self.time_2.set_time_seconds(4321)
     self.obj_ts = ObjectTrackSet([self.track_])
     self.act_type = ActivityType("self_act", 0.87)
     self.act = Activity(1, "self_act", 0.87, self.act_type, self.time_1,
                         self.time_2, self.obj_ts)
Exemplo n.º 8
0
    def test_first_frame(self):
        # no tracks
        ts = TrackSet()
        nt.assert_equal(ts.first_frame(), 0)

        # one track
        t = Track(1)
        t.append(TrackState(1))
        t.append(TrackState(2))
        ts = TrackSet([t])
        nt.assert_equal(ts.first_frame(), 1)

        # two tracks
        t2 = Track(2)
        t2.append(TrackState(3))
        ts = TrackSet([t, t2])
        nt.assert_equal(ts.first_frame(), 1)
Exemplo n.º 9
0
    def test_ts_append(self):
        t = Track()
        nose.tools.assert_equal(t.size, 0)
        nose.tools.assert_equal(len(t), 0)

        ts = TrackState(10)
        nose.tools.assert_true(t.append(ts))
        nose.tools.assert_equal(t.size, 1)
        nose.tools.assert_equal(len(t), 1)

        ts = TrackState(11)
        nose.tools.assert_true(t.append(ts))
        nose.tools.assert_equal(t.size, 2)
        nose.tools.assert_equal(len(t), 2)

        # Other properties that should not be different than default
        nose.tools.assert_equal(t.first_frame, 10)
        nose.tools.assert_equal(t.last_frame, 11)
        nose.tools.assert_false(t.is_empty)
Exemplo n.º 10
0
    def test_track_getitem(self):
        # this is the same test as test_track_find, but using the get-item
        # accessor syntax
        t = Track()
        t.append(TrackState(0))
        t.append(TrackState(1))
        t.append(TrackState(5))
        t.append(TrackState(9))

        ts = t[0]
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 0)

        ts = t[1]
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 1)

        ts = t[5]
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 5)

        ts = t[9]
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 9)

        nose.tools.assert_raises(IndexError, t.find_state, 10)
        t.append(TrackState(10))
        nose.tools.assert_is_not_none(t[10])
        nose.tools.assert_equal(t[10].frame_id, 10)
Exemplo n.º 11
0
    def test_track_find(self):
        t = Track()
        t.append(TrackState(0))
        t.append(TrackState(1))
        t.append(TrackState(5))
        t.append(TrackState(9))

        ts = t.find_state(0)
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 0)

        ts = t.find_state(1)
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 1)

        ts = t.find_state(5)
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 5)

        ts = t.find_state(9)
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 9)

        nose.tools.assert_raises(IndexError, t.find_state, 10)
        t.append(TrackState(10))
        nose.tools.assert_is_not_none(t.find_state(10))
        nose.tools.assert_equal(t.find_state(10).frame_id, 10)
Exemplo n.º 12
0
def to_ObjectTrackSet(tracks):
    """Create an ObjectTrackSet from a dict whose keys are track IDs
    and values are lists of pairs of Kwiver timestamps and Kwiver DetectedObjects"""
    # Modeled after similar code in srnn_tracker.py
    result = []
    for tid, states in tracks.items():
        t = Track(id=tid)
        for ts, do in states:
            ots = ObjectTrackState(ts.get_frame(), ts.get_time_usec(), do)
            if not t.append(ots):
                raise ValueError("Unsorted input to to_ObjectTrackSet")
        result.append(t)
    return ObjectTrackSet(result)
Exemplo n.º 13
0
 def test_id(self):
     a = self.act
     self.assertEqual(a.id, 1)
     a.id = 10
     self.assertEqual(a.id, 10)
     self.assertEqual(a.label, "self_act")
     a.label = "second_act"
     self.assertEqual(a.label, "second_act")
     self.assertEqual(a.activity_type.score("self_act"), 0.87)
     a.activity_type = ActivityType()
     self.assertEqual(a.confidence, 0.87)
     a.confidence = 1
     self.assertEqual(a.confidence, 1)
     self.assertEqual(a.start_time.get_time_seconds(), 1234)
     tmp_time = Timestamp().set_time_seconds(1237)
     a.start_time = tmp_time
     self.assertEqual(a.start_time.get_time_seconds(), 1237)
     self.assertEqual(a.end_time.get_time_seconds(), 4321)
     tmp_time = Timestamp()
     tmp_time.set_time_seconds(4322)
     a.end_time = tmp_time
     self.assertEqual(a.end_time.get_time_seconds(), 4322)
     self.assertEqual(a.participants.all_frame_ids(), set(range(10)))
     bbox = BoundingBox(10, 10, 20, 20)
     dot = DetectedObjectType("test", 0.4)
     do = DetectedObject(bbox, 0.4, dot)
     track = Track()
     for i in range(5):
         track.append(ObjectTrackState(i, i, do))
     new_t = track
     new_ots = ObjectTrackSet([new_t])
     a.participants = new_ots
     self.assertEqual(a.participants.all_frame_ids(), set(range(5)))
     self.assertEqual(a.duration[0].get_time_seconds(),
                      a.start_time.get_time_seconds())
     self.assertEqual(a.duration[1].get_time_seconds(),
                      a.end_time.get_time_seconds())
Exemplo n.º 14
0
def subset_tracks(trackset, keep_fraction=0.75):
    """
    randomly drop a fraction of the track states per track in the given set,
    creating and returning new tracks in a new track-set.

    :type trackset: TrackSet
    :type keep_fraction: float
    """
    log = logging.getLogger(__name__)

    new_tracks = []
    for t in trackset.tracks():
        nt = Track(t.id)

        msg = 'track %d:' % t.id,
        for ts in t:
            if numpy.random.rand() < keep_fraction:
                nt.append(ts)
                msg += '.',
            else:
                msg += 'X',
        log.info(' '.join(msg))
        new_tracks.append(nt)
    return TrackSet(new_tracks)
Exemplo n.º 15
0
    def test_ts_append_outoforder(self):
        t = Track()
        nose.tools.assert_true(t.append(TrackState(10)))
        nose.tools.assert_false(t.append(TrackState(10)))
        nose.tools.assert_false(t.append(TrackState(9)))
        nose.tools.assert_false(t.append(TrackState(0)))
        nose.tools.assert_false(t.append(TrackState(-1)))

        nose.tools.assert_true(t.append(TrackState(11)))
        nose.tools.assert_false(t.append(TrackState(11)))

        # After all that there should only be two states in there for frames 10
        # and 11.
        nose.tools.assert_equal(t.size, 2)
        nose.tools.assert_equal(len(t), 2)
        nose.tools.assert_equal(t.all_frame_ids(), {10, 11})
Exemplo n.º 16
0
def create_object_track_set():
    object_track_state = create_object_track_state()
    track = Track()
    track.append(create_track_state())
    return ObjectTrackSet([track])
Exemplo n.º 17
0
def create_track():
    track = Track()
    track.append(create_track_state())
    return track