def test_configuration(self): """ Test standard configuration """ ex_tname = 'test' ex_uuid = 0 inst = MemoryClassificationElement(ex_tname, ex_uuid) configuration_test_helper(inst, {'type_name', 'uuid'}, (ex_tname, ex_uuid))
def test_configuration(self): index_filepath = osp.abspath(osp.expanduser('index_filepath')) para_filepath = osp.abspath(osp.expanduser('param_fp')) i = MRPTNearestNeighborsIndex( descriptor_set=MemoryDescriptorSet(), index_filepath=index_filepath, parameters_filepath=para_filepath, read_only=True, num_trees=9, depth=2, random_seed=8, pickle_protocol=0, use_multiprocessing=True, ) for inst in configuration_test_helper( i): # type: MRPTNearestNeighborsIndex assert isinstance(inst._descriptor_set, MemoryDescriptorSet) assert inst._index_filepath == index_filepath assert inst._index_param_filepath == para_filepath assert inst._read_only == True assert inst._num_trees == 9 assert inst._depth == 2 assert inst._rand_seed == 8 assert inst._pickle_protocol == 0 assert inst._use_multiprocessing == True
def test_configuration(self): inst = DataFileSet(root_directory='/some/dir', uuid_chunk=10, pickle_protocol=-1) for i in configuration_test_helper(inst): # type: DataFileSet assert i._root_dir == '/some/dir' assert i._uuid_chunk == 10 assert i.pickle_protocol == -1
def test_configuration(self, _mock_scd): i = ColorDescriptor_Image_csift( model_directory='test model dir', work_directory='test work dir', model_gen_descriptor_limit=123764, kmeans_k=42, flann_distance_metric='hik', flann_target_precision=0.92, flann_sample_fraction=0.71, flann_autotune=True, random_seed=7, use_spatial_pyramid=True, parallel=3, ) for inst in configuration_test_helper(i): assert inst._model_dir == 'test model dir' assert inst._work_dir == 'test work dir' assert inst._model_gen_descriptor_limit == 123764 assert inst._kmeans_k == 42 assert inst._flann_distance_metric == 'hik' assert inst._flann_target_precision == 0.92 assert inst._flann_sample_fraction == 0.71 assert inst._flann_autotune is True assert inst._rand_seed == 7 assert inst._use_sp is True assert inst.parallel == 3
def test_configuraton(self): """ Test instance standard configuration. """ inst = PostgresKeyValueStore(table_name="data_set0", key_col='key1', value_col='value2', db_name='postgres3', db_host='foobar', db_port=8997, db_user='******', db_pass='******', batch_size=1007, pickle_protocol=2, read_only=True, create_table=False) for i in configuration_test_helper( inst): # type: PostgresKeyValueStore assert i._table_name == 'data_set0' assert i._key_col == 'key1' assert i._value_col == 'value2' assert i._psql_helper.db_name == 'postgres3' assert i._psql_helper.db_host == 'foobar' assert i._psql_helper.db_port == 8997 assert i._psql_helper.db_user == 'Bob' assert i._psql_helper.db_pass == 'flabberghast' assert i._batch_size == 1007 assert i._pickle_protocol == 2 assert i._read_only is True assert i._create_table is False
def test_configuration(self): ex_descr_set = MemoryDescriptorSet() ex_i2u_kvs = MemoryKeyValueStore() ex_u2i_kvs = MemoryKeyValueStore() ex_index_elem = DataMemoryElement() ex_index_param_elem = DataMemoryElement() i = FaissNearestNeighborsIndex( descriptor_set=ex_descr_set, idx2uid_kvs=ex_i2u_kvs, uid2idx_kvs=ex_u2i_kvs, index_element=ex_index_elem, index_param_element=ex_index_param_elem, read_only=True, factory_string=u'some fact str', ivf_nprobe=88, use_gpu=False, gpu_id=99, random_seed=8, ) for inst in configuration_test_helper(i): assert isinstance(inst._descriptor_set, MemoryDescriptorSet) assert isinstance(inst._idx2uid_kvs, MemoryKeyValueStore) assert isinstance(inst._uid2idx_kvs, MemoryKeyValueStore) assert isinstance(inst._index_element, DataMemoryElement) assert isinstance(inst._index_param_element, DataMemoryElement) assert inst.read_only is True assert isinstance(inst.factory_string, six.string_types) assert inst.factory_string == 'some fact str' assert inst._ivf_nprobe == 88 assert inst._use_gpu is False assert inst._gpu_id == 99 assert inst.random_seed == 8
def test_configuration(self): fp = os.path.join(TEST_DATA_DIR, "grace_hopper.png") inst = DataFileElement(filepath=fp, readonly=True, explicit_mimetype='foo/bar') for i in configuration_test_helper(inst): # type: DataFileElement assert i._filepath == fp assert i._readonly is True assert i._explicit_mimetype == 'foo/bar'
def test_configuration(self): """ Test instance standard configuration """ inst = DescriptorMemoryElement('test', 'abcd') for i in configuration_test_helper( inst, {'type_str', 'uuid'}, ('test', 'abcd')): # type: DescriptorMemoryElement assert i.type() == 'test' assert i.uuid() == 'abcd'
def test_configuration(self): """ Test getting and constructing from configuration. """ expected_exmode = 'L' i = PilImageReader(explicit_mode=expected_exmode) for inst in configuration_test_helper(i): # type: PilImageReader assert inst._explicit_mode == expected_exmode
def test_configuration(self): inst = DataMemoryElement( bytes=b'Hello World.', content_type='text/plain', readonly=True, ) for i in configuration_test_helper(inst): # type: DataMemoryElement assert i._bytes == b'Hello World.' assert i._content_type == 'text/plain' assert i._readonly is True
def test_configuration(self): """ Test instance standard configuration """ inst = DescriptorFileElement('test', 'abcd', save_dir='/some/path/somewhere', subdir_split=4) for i in configuration_test_helper(inst, {'type_str', 'uuid'}, ('test', 'abcd')): assert i._save_dir == '/some/path/somewhere' assert i._subdir_split == 4
def test_from_config_full_constructor(self, _mock_authenticate): expected_file_id = '34uhki34gh2345ghjk' expected_api_root = 'https://some.other.server/api/v1' expected_api_key = '1234ghk135hlg23435' inst = GirderDataElement(expected_file_id, api_root=expected_api_root, api_key=expected_api_key) for i in configuration_test_helper(inst): # type: GirderDataElement assert i.file_id == expected_file_id assert i.api_root == expected_api_root assert i.api_key == expected_api_key
def test_configuration(self): """ Test configuration using helper """ expected_load_method = GdalImageReader.LOAD_METHOD_TEMPFILE expected_channel_order = [3, 5, 4] i = GdalImageReader(load_method=expected_load_method, channel_order=expected_channel_order) for inst in configuration_test_helper(i): # type: GdalImageReader assert inst._load_method == expected_load_method assert inst._channel_order == expected_channel_order
def test_config(self): inst = HBaseDataElement(element_key='foobar', binary_column='binary_data', hbase_address="some_address", hbase_table='some_table', timeout=12345) for i in configuration_test_helper(inst): # type: HBaseDataElement assert i.element_key == 'foobar' assert i.binary_column == 'binary_data' assert i.hbase_address == 'some_address' assert i.hbase_table == 'some_table' assert i.timeout == 12345
def test_configuration(self): i = LSHNearestNeighborIndex(lsh_functor=ItqFunctor(), descriptor_set=MemoryDescriptorSet(), hash2uuids_kvstore=MemoryKeyValueStore(), hash_index=LinearHashIndex(), distance_method='euclidean', read_only=True) for inst in configuration_test_helper( i): # type: LSHNearestNeighborIndex assert isinstance(inst.lsh_functor, LshFunctor) assert isinstance(inst.descriptor_set, MemoryDescriptorSet) assert isinstance(inst.hash_index, LinearHashIndex) assert isinstance(inst.hash2uuids_kvstore, MemoryKeyValueStore) assert inst.distance_method == 'euclidean' assert inst.read_only is True
def test_configuration(): """ Test file-based impl's configuration reflection """ expected_typename = 'test' expected_uuid = 235246 expected_save_dir = '/foo/bar/thing' expected_pp = 1 expected_subdir_split = 2 inst = FileClassificationElement(expected_typename, expected_uuid, expected_save_dir, expected_subdir_split, expected_pp) for i in configuration_test_helper(inst, {"type_name", "uuid"}, (expected_typename, expected_uuid)): # type: FileClassificationElement assert i.save_dir == expected_save_dir assert i.pickle_protocol == expected_pp assert i.subdir_split == expected_subdir_split
def test_configuration(self): index_filepath = '/index_filepath' para_filepath = '/param_fp' descr_cache_fp = '/descrcachefp' c = FlannNearestNeighborsIndex( index_uri=index_filepath, parameters_uri=para_filepath, descriptor_cache_uri=descr_cache_fp, distance_method='hik', random_seed=42, ) for inst in configuration_test_helper( c): # type: FlannNearestNeighborsIndex assert inst._index_uri == index_filepath assert inst._index_param_uri == para_filepath assert inst._descr_cache_uri == descr_cache_fp assert inst._distance_method == 'hik' assert inst._rand_seed == 42
def test_configuration(self, m_inst_load_model): """ Test configuration handling for this implementation. Mocking out model loading when given URIs if they happen to point to something. """ ex_model_uri = 'some model uri' ex_labelmap_uri = 'some label map uri' ex_trainparams = {'-s': 8, '-t': -10, '-b': 42, '-c': 7.2} ex_normalize = 2 c = LibSvmClassifier(ex_model_uri, ex_labelmap_uri, train_params=ex_trainparams, normalize=ex_normalize) for inst in configuration_test_helper(c): # type: LibSvmClassifier assert inst.svm_model_uri == ex_model_uri assert inst.svm_label_map_uri == ex_labelmap_uri assert inst.train_params == ex_trainparams assert inst.normalize == ex_normalize
def test_configuration(self): """ Standard configuration test. """ inst = SkLearnLogisticRegression( penalty='l1', dual=True, tol=1e-6, C=2.0, fit_intercept=False, intercept_scaling=3, class_weight={0: 2.0, 1: 3.0}, random_state=456, solver='liblinear', max_iter=99, multi_class='multinomial', verbose=1, warm_start=True, n_jobs=2, ) for inst_i in configuration_test_helper(inst): # type: SkLearnLogisticRegression assert inst.penalty == inst_i.penalty == 'l1' assert inst.dual is inst_i.dual is True assert inst.tol == inst_i.tol == 1e-6 assert inst.C == inst_i.C == 2.0 assert inst.fit_intercept is inst_i.fit_intercept is False assert inst.intercept_scaling == inst_i.intercept_scaling == 3 assert inst.class_weight == inst_i.class_weight == {0: 2.0, 1: 3.0} assert inst.random_state == inst_i.random_state == 456 assert inst.solver == inst_i.solver == 'liblinear' assert inst.multi_class == inst_i.multi_class == 'multinomial' assert inst.verbose == inst_i.verbose == 1 assert inst.warm_start is inst_i.warm_start is True assert inst.n_jobs == inst_i.n_jobs == 2
def test_config_cycle(self, m_cdg_setup_network): """ Test being able to get an instances config and use that config to construct an equivalently parameterized instance. This test initializes all possible parameters to non-defaults. """ # Mocking ``_setup_network`` so no caffe functionality is hit during # this test # When every parameter is provided. g1 = CaffeDescriptorGenerator(self.dummy_net_topo_elem, self.dummy_caffe_model_elem, image_mean=self.dummy_img_mean_elem, return_layer='foobar', batch_size=9, use_gpu=True, gpu_device_id=99, network_is_bgr=False, data_layer='maybe data', load_truncated_images=True, pixel_rescale=(0.2, 0.3), input_scale=8.9, threads=7) for inst in configuration_test_helper( g1): # type: CaffeDescriptorGenerator assert inst.network_prototxt == self.dummy_net_topo_elem assert inst.network_model == self.dummy_caffe_model_elem assert inst.image_mean == self.dummy_img_mean_elem assert inst.return_layer == 'foobar' assert inst.batch_size == 9 assert inst.use_gpu == True assert inst.gpu_device_id == 99 assert inst.network_is_bgr == False assert inst.data_layer == 'maybe data' assert inst.load_truncated_images == True assert inst.pixel_rescale == (0.2, 0.3) assert inst.input_scale == 8.9 assert inst.threads == 7
def test_configuration(self, _mock_Solr): inst = SolrDescriptorElement( 'test', 'a', solr_conn_addr=self.TEST_URL, type_field='type_s', uuid_field='uuid_s', vector_field='vector_fs', timestamp_field='timestamp_f', timeout=101, persistent_connection=True, commit_on_set=False, ) for i in configuration_test_helper( inst, {'type_str', 'uuid'}, ('test', 'abcd')): # type: SolrDescriptorElement assert i.solr_conn_addr == self.TEST_URL assert i.type_field == 'type_s' assert i.uuid_field == 'uuid_s' assert i.vector_field == 'vector_fs' assert i.timestamp_field == 'timestamp_f' assert i.solr_timeout == 101 assert i.solr_persistent_connection is True assert i.solr_commit_on_set is False
def test_configuration(self): """ Test instance standard configuration """ inst = KVSDataSet(self.MEM_STORE) for i in configuration_test_helper(inst): # type: KVSDataSet assert isinstance(i._kvstore, MemoryKeyValueStore) assert i._kvstore.get_config() == self.MEM_STORE.get_config()
def test_get_config(): """ Test that configuration for memory element is empty. """ inst = MemoryDetectionElement(0) for i in configuration_test_helper(inst, {'uuid'}, (0, )): # type: MemoryDetectionElement assert i.uuid == 0
def test_configurable(self): c = IndexLabelClassifier(self.FILEPATH_TEST_LABELS) for inst in configuration_test_helper(c): assert inst.index_to_label_uri == self.FILEPATH_TEST_LABELS
def test_configuration(): """ test standard instance configuration """ inst = AxisAlignedBoundingBox([0, 1], [1, 2]) for i in configuration_test_helper(inst): # type: AxisAlignedBoundingBox numpy.testing.assert_allclose(i.min_vertex, (0, 1)) numpy.testing.assert_allclose(i.max_vertex, (1, 2))
def test_configuration(self, m_req_get): # Mocking requests usage to no actually head into the network. inst = DataUrlElement(self.EXAMPLE_URL) for i in configuration_test_helper(inst): # type: DataUrlElement assert i._url == self.EXAMPLE_URL