|
@@ -1,16 +1,20 @@
|
|
import unittest
|
|
import unittest
|
|
import numpy as np
|
|
import numpy as np
|
|
import os
|
|
import os
|
|
|
|
+import uuid
|
|
|
|
|
|
from tests.configs import config
|
|
from tests.configs import config
|
|
from os.path import *
|
|
from os.path import *
|
|
|
|
|
|
|
|
+from abc import ABC, abstractproperty
|
|
|
|
+
|
|
|
|
|
|
from nabirds import BaseAnnotations, _MetaInfo
|
|
from nabirds import BaseAnnotations, _MetaInfo
|
|
from nabirds.utils import read_info_file
|
|
from nabirds.utils import read_info_file
|
|
|
|
|
|
class MockAnnotation(BaseAnnotations):
|
|
class MockAnnotation(BaseAnnotations):
|
|
name = "MOCK"
|
|
name = "MOCK"
|
|
|
|
+ index_offset = 0
|
|
|
|
|
|
@property
|
|
@property
|
|
def meta(self):
|
|
def meta(self):
|
|
@@ -35,21 +39,20 @@ class MockAnnotation(BaseAnnotations):
|
|
]
|
|
]
|
|
return info
|
|
return info
|
|
|
|
|
|
-
|
|
|
|
-class AnnotationTests(unittest.TestCase):
|
|
|
|
-
|
|
|
|
- def setUp(self):
|
|
|
|
- self.info = read_info_file(config.INFO_FILE)
|
|
|
|
- # self.annot = MockAnnotation()
|
|
|
|
|
|
+class BaseAnnotationTest(unittest.TestCase, ABC):
|
|
|
|
|
|
def tearDown(self):
|
|
def tearDown(self):
|
|
# clear mock data folder?
|
|
# clear mock data folder?
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
+ def setUp(self):
|
|
|
|
+ self.info = read_info_file(config.INFO_FILE)
|
|
|
|
+
|
|
def create_annotations(self, images, labels, split,
|
|
def create_annotations(self, images, labels, split,
|
|
bboxes=False,
|
|
bboxes=False,
|
|
index_offset=0,
|
|
index_offset=0,
|
|
- n_parts=None):
|
|
|
|
|
|
+ n_parts=None,
|
|
|
|
+ annot_params={}):
|
|
|
|
|
|
data_root = join(self.info.BASE_DIR, self.info.DATA_DIR)
|
|
data_root = join(self.info.BASE_DIR, self.info.DATA_DIR)
|
|
dataset_info = self.info.DATASETS.MOCK
|
|
dataset_info = self.info.DATASETS.MOCK
|
|
@@ -64,8 +67,8 @@ class AnnotationTests(unittest.TestCase):
|
|
open(fname("labels.txt"), "w") as labels_f,\
|
|
open(fname("labels.txt"), "w") as labels_f,\
|
|
open(fname("tr_ID.txt"), "w") as split_f:
|
|
open(fname("tr_ID.txt"), "w") as split_f:
|
|
|
|
|
|
- for i, (im, lab, sp) in enumerate(zip(images, labels, split), index_offset):
|
|
|
|
- print(i, im, file=images_f)
|
|
|
|
|
|
+ for im, lab, sp in zip(images, labels, split):
|
|
|
|
+ print(*im, file=images_f)
|
|
print(lab, file=labels_f)
|
|
print(lab, file=labels_f)
|
|
print(sp, file=split_f)
|
|
print(sp, file=split_f)
|
|
|
|
|
|
@@ -85,20 +88,38 @@ class AnnotationTests(unittest.TestCase):
|
|
for i in range(n_parts):
|
|
for i in range(n_parts):
|
|
print(i, "part_{}".format(i), file=part_names_f)
|
|
print(i, "part_{}".format(i), file=part_names_f)
|
|
|
|
|
|
- for i in range(index_offset, len(images) + index_offset):
|
|
|
|
|
|
+ for i, imname in images:
|
|
for p in range(n_parts):
|
|
for p in range(n_parts):
|
|
- print(i, 10*p, 10*p, 1, file=part_locs_f)
|
|
|
|
|
|
+ print(i, p, 10*(p+1), 10*(p+1), 1, file=part_locs_f)
|
|
|
|
|
|
|
|
|
|
- def test_foo(self):
|
|
|
|
- self.create_annotations(
|
|
|
|
- ["images{}.jpg".format(i) for i in range(10)],
|
|
|
|
- [i % 5 for i in range(10)],
|
|
|
|
- [int(i < 5) for i in range(10)],
|
|
|
|
- bboxes=False, n_parts=5
|
|
|
|
- )
|
|
|
|
|
|
+ return MockAnnotation(
|
|
|
|
+ root_or_infofile=config.INFO_FILE,
|
|
|
|
+ **annot_params)
|
|
|
|
+
|
|
|
|
|
|
- annot = MockAnnotation(config.INFO_FILE)
|
|
|
|
|
|
+class AnnotationTest(BaseAnnotationTest):
|
|
|
|
+
|
|
|
|
+ # @unittest.skip
|
|
|
|
+ def test_simple(self):
|
|
|
|
+ _annotation_params = dict(
|
|
|
|
+ images=[(i, "images{}.jpg".format(i)) for i in range(10)],
|
|
|
|
+ labels=[i % 5 for i in range(10)],
|
|
|
|
+ split=[int(i < 5) for i in range(10)],
|
|
|
|
+ bboxes=True,
|
|
|
|
+ n_parts=5
|
|
|
|
+ )
|
|
|
|
+ annot = self.create_annotations(**_annotation_params)
|
|
|
|
+
|
|
|
|
+ # @unittest.skip
|
|
|
|
+ def test_with_uuids(self):
|
|
|
|
+ _annotation_params = dict(
|
|
|
|
+ images=[(uuid.uuid4(), "images{}.jpg".format(i)) for i in range(10)],
|
|
|
|
+ labels=[i % 5 for i in range(10)],
|
|
|
|
+ split=[int(i < 5) for i in range(10)],
|
|
|
|
+ bboxes=True,
|
|
|
|
+ n_parts=5
|
|
|
|
+ )
|
|
|
|
+ annot = self.create_annotations(**_annotation_params)
|
|
|
|
|
|
- def test_bar(self):
|
|
|
|
self.assertFalse(0)
|
|
self.assertFalse(0)
|