def setUp(self): self.set = HNSWFeaturesSet("/tmp/foo.bin", 10, 2)
class TestHNSWSet(unittest.TestCase): def setUp(self): self.set = HNSWFeaturesSet("/tmp/foo.bin", 10, 2) def tearDown(self): try: os.remove("/tmp/foo.bin") except FileNotFoundError: pass try: os.remove("/foo/bar.bin") except FileNotFoundError: pass def test_file_not_created_error(self): with self.assertRaises(FileNotFoundError): HNSWFeaturesSet("/foo/bar.bin", 1, 1) def test_rebuild(self): time_before_modification = os.path.getmtime(self.set.output_path) time.sleep(1) self.set.rebuild(np.array([[1, 1]]), np.asarray([ 1, ])) assert (time_before_modification != os.path.getmtime( self.set.output_path)) def test_wrong_dimensionality(self): with self.assertRaises(RuntimeError): self.set.rebuild(np.array([[1, 1, 1]]), np.asarray([ 1, ])) def test_string_in_vector(self): with self.assertRaises(ValueError): self.set.rebuild(np.array([["I can't be converted to float", 1]]), np.asarray([ 1, ])) def test_string_list_id(self): with self.assertRaises(ValueError): self.set.rebuild(np.array([[1, 1]]), np.asarray([ "I can't be converted to int", ])) def test_unsized_list_ids(self): with self.assertRaises(TypeError): self.set.rebuild(np.array([[1, 1]]), 1) def test_unequal_param_lengths(self): with self.assertRaises(AssertionError): self.set.rebuild(np.array([[1, 1]]), [1, 2]) def test_duplicate_list_ids(self): with self.assertRaises(AssertionError): self.set.rebuild(np.array([[1, 1], [2, 2]]), [1, 1])
from lib.basic_logger import log from lib.yaml_config import YamlConfig as Config from lib.redis_bus import RedisBus #NB! Import before MySQLEngine to avoid SegmentationFault from lib.query_executor.query_executor import QueryDictExecutor from lib.mysql_driver.mysql_engine import MySQLEngine from lib.get_face_hash import Infer from lib.hnsw_features_set import HNSWFeaturesSet from lib.queries.mysql_queries import mysql_queries as query from mysql.connector.errors import ProgrammingError, InterfaceError, OperationalError, IntegrityError # Create global instance of config project_dir = "/opt/projects/mvid" config = Config('/etc/spyspace/mvid_conf.yaml') # Create global instance of basic transport bus = RedisBus(host=config.find('redis_host')) executor = QueryDictExecutor(MySQLEngine, config.find('mysql_host'), user=config.find('mysql_user'), password=config.find('mysql_passwd'), database="mvideo") features_set = HNSWFeaturesSet(config.find('ann_path'), config.find('ann_max_elements')) infer = Infer()
def test_file_not_created_error(self): with self.assertRaises(FileNotFoundError): HNSWFeaturesSet("/foo/bar.bin", 1, 1)
ann_path = config.find('ann_path') ann_max_elements = config.find('ann_max_elements') vino_mode = config.find('vino_mode') cpu_extension = config.find('cpu_extension') detector_model = config.find('intel_fd_model') landmarks_model = config.find('intel_lm_model') reid_model = config.find('intel_ri_model') detection_threshold = config.find('detection_threshold') pedestrian_model = config.find('intel_pedestrian_model') pedestrian_threshold = config.find('pedestrian_threshold') bus = RedisBus(host=host, queue_size=queue_size) ram_bus = RamBus() executor = QueryDictExecutor(MySQLEngine, db_host, user=db_user, password=db_password, database=db_database) features_set = HNSWFeaturesSet(ann_path, ann_max_elements) frame_handler = OpenVinoHandler(mode=vino_mode, cpu_extension=cpu_extension, detection_threshold=detection_threshold, classDetector=FaceDetectorModel, detector_model=detector_model, classLandmarks=LandmarksDetector, landmarks_model=landmarks_model, classReid=FaceReidModel, reid_model=reid_model) pedestrian_frame_handler = OpenVinoHandler(mode=vino_mode, cpu_extension=cpu_extension, detection_threshold=pedestrian_threshold, classDetector=FaceDetectorModel, detector_model=pedestrian_model)