def test_issue_1634(self):
    dataset = foz.load_zoo_dataset('quickstart-video', max_samples=1).select_fields('frames.detections').clone()
    anno_key = 'issue_1634_test'
    results = dataset.annotate(anno_key, label_field='frames.ground_truth', label_type='detections', classes=['test'])
    task_id = results.task_ids[0]
    api = results.connect_to_api()
    _create_annotation(api, task_id, track=(0, 30), _type='polygon', points=[10, 20, 40, 30, 50, 60])
    _create_annotation(api, task_id, track=(20, 40))
    api.close()
    imported_dataset = fo.Dataset()
    with etau.TempDir() as tmp:
        fouc.import_annotations(imported_dataset, task_ids=[task_id], data_path=tmp, download_media=True)
        imported_dataset.compute_metadata()
        self.assertEqual(imported_dataset.first().metadata.total_frame_count, dataset.first().metadata.total_frame_count)
        imported_dataset.export(export_dir=tmp, dataset_type=fo.types.CVATVideoDataset)
        filename = os.path.splitext(os.path.basename(imported_dataset.first().filepath))[0]
        labels_filepath = os.path.join(tmp, 'labels', ('%s.xml' % filename))
        with open(labels_filepath, 'r') as f:
            label_file_info = f.read()
            track_1 = '<track id="1" label="test">'
            track_2 = '<track id="2" label="test">'
            polygon_frame_0 = '<polygon frame="0"'
            polygon_frame_30 = '<polygon frame="30"'
            box_frame_20 = '<box frame="20"'
            box_frame_40 = '<box frame="40"'
            self.assertTrue((track_1 in label_file_info))
            self.assertTrue((track_2 in label_file_info))
            self.assertTrue((polygon_frame_0 in label_file_info))
            self.assertTrue((polygon_frame_30 in label_file_info))
            self.assertTrue((box_frame_20 in label_file_info))
            self.assertTrue((box_frame_40 in label_file_info))
        cvat_video_dataset = fo.Dataset.from_dir(dataset_dir=tmp, dataset_type=fo.types.CVATVideoDataset)
        detections = cvat_video_dataset.values('frames.detections', unwind=True)
        detections = [i for i in detections if (i is not None)]
        self.assertEqual(len(detections), 20)
        polylines = cvat_video_dataset.values('frames.polylines', unwind=True)
        polylines = [i for i in polylines if (i is not None)]
        self.assertEqual(len(polylines), 30)
    dataset.load_annotations(anno_key, cleanup=True)
def test_issue_1634(self):
    dataset = foz.load_zoo_dataset('quickstart-video', max_samples=1).select_fields('frames.detections').clone()
    anno_key = 'issue_1634_test'
    results = dataset.annotate(anno_key, label_field='frames.ground_truth', label_type='detections', classes=['test'])
    task_id = results.task_ids[0]
    api = results.connect_to_api()
    _create_annotation(api, task_id, track=(0, 30), _type='polygon', points=[10, 20, 40, 30, 50, 60])
    _create_annotation(api, task_id, track=(20, 40))
    api.close()
    imported_dataset = fo.Dataset()
    with etau.TempDir() as tmp:
        fouc.import_annotations(imported_dataset, task_ids=[task_id], data_path=tmp, download_media=True)
        imported_dataset.compute_metadata()
        self.assertEqual(imported_dataset.first().metadata.total_frame_count, dataset.first().metadata.total_frame_count)
        imported_dataset.export(export_dir=tmp, dataset_type=fo.types.CVATVideoDataset)
        filename = os.path.splitext(os.path.basename(imported_dataset.first().filepath))[0]
        labels_filepath = os.path.join(tmp, 'labels', ('%s.xml' % filename))
        with open(labels_filepath, 'r') as f:
            label_file_info = f.read()
            track_1 = '<track id="1" label="test">'
            track_2 = '<track id="2" label="test">'
            polygon_frame_0 = '<polygon frame="0"'
            polygon_frame_30 = '<polygon frame="30"'
            box_frame_20 = '<box frame="20"'
            box_frame_40 = '<box frame="40"'
            self.assertTrue((track_1 in label_file_info))
            self.assertTrue((track_2 in label_file_info))
            self.assertTrue((polygon_frame_0 in label_file_info))
            self.assertTrue((polygon_frame_30 in label_file_info))
            self.assertTrue((box_frame_20 in label_file_info))
            self.assertTrue((box_frame_40 in label_file_info))
        cvat_video_dataset = fo.Dataset.from_dir(dataset_dir=tmp, dataset_type=fo.types.CVATVideoDataset)
        detections = cvat_video_dataset.values('frames.detections', unwind=True)
        detections = [i for i in detections if (i is not None)]
        self.assertEqual(len(detections), 20)
        polylines = cvat_video_dataset.values('frames.polylines', unwind=True)
        polylines = [i for i in polylines if (i is not None)]
        self.assertEqual(len(polylines), 30)
    dataset.load_annotations(anno_key, cleanup=True)