Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/Reorg Descriptors Tests #101

Merged
merged 1 commit into from
Apr 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
153 changes: 29 additions & 124 deletions tests/python/TestDescriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,6 @@ def test_addSet(self):
# Check success
self.assertEqual(response[0]["AddDescriptorSet"]["status"], 0)

def test_addDifferentSets(self):

self.addSet("128-L2-FaissFlat", 128, "L2", "FaissFlat")
self.addSet("128-IP-FaissFlat", 128, "IP", "FaissFlat")
self.addSet("128-L2-FaissIVFFlat", 128, "L2", "FaissIVFFlat")
self.addSet("128-IP-FaissIVFFlat", 128, "IP", "FaissIVFFlat")
self.addSet("128-L2-TileDBDense", 128, "L2", "TileDBDense")
self.addSet("128-L2-TileDBSparse", 128, "L2", "TileDBSparse")

self.addSet("4075-L2-FaissFlat", 4075, "L2", "FaissFlat")
self.addSet("4075-IP-FaissFlat", 4075, "IP", "FaissFlat")
self.addSet("4075-L2-FaissIVFFlat", 4075, "L2", "FaissIVFFlat")
self.addSet("4075-IP-FaissIVFFlat", 4075, "IP", "FaissIVFFlat")
self.addSet("4075-L2-TileDBDense", 4075, "L2", "TileDBDense")

def test_addSetAndDescriptors(self):

db = self.create_connection()
Expand Down Expand Up @@ -130,15 +115,15 @@ def test_addSetAndDescriptors(self):
# Check success
self.assertEqual(response[0]["AddDescriptor"]["status"], 0)

def test_addDescriptorsx1000(self):
def test_addSetAndDescriptorsDimMismatch(self):

db = self.create_connection()

all_queries = []

# Add Set
set_name = "features_128dx1000"
dims = 128
set_name = "features_64d_dim_mismatched"
dims = 64
descriptor_set = {}
descriptor_set["name"] = set_name
descriptor_set["dimensions"] = dims
Expand All @@ -151,153 +136,73 @@ def test_addDescriptorsx1000(self):
response, img_array = db.query(all_queries)
self.assertEqual(response[0]["AddDescriptorSet"]["status"], 0)

# Add Descriptors
all_queries = []
descriptor_blob = []

total = 1000;

for i in range(1,total):
x = np.ones(dims)
x[2] = 2.34 + i*20
x = x.astype('float32')
descriptor_blob.append(x.tobytes())

descriptor = {}
descriptor["set"] = set_name
descriptor["label"] = "classX"

query = {}
query["AddDescriptor"] = descriptor

all_queries.append(query)

response, img_array = db.query(all_queries, [descriptor_blob])

# Check success
for x in range(0,total-1):
self.assertEqual(response[x]["AddDescriptor"]["status"], 0)

def test_addDescriptorsx1000FaissIVFFlat(self):

db = self.create_connection()

all_queries = []
x = np.zeros(dims/2)
x = x.astype('float32')
# print type(x[0])
# print "size: ", len(x.tobytes())/4
descriptor_blob.append(x.tobytes())

# Add Set
set_name = "faissivfflat_ip_128dx1000"
dims = 128
descriptor_set = {}
descriptor_set["name"] = set_name
descriptor_set["dimensions"] = dims
descriptor_set["metric"] = "IP"
descriptor_set["engine"] = "FaissIVFFlat"
descriptor = {}
descriptor["set"] = set_name

query = {}
query["AddDescriptorSet"] = descriptor_set
query["AddDescriptor"] = descriptor

all_queries.append(query)

response, img_array = db.query(all_queries)
self.assertEqual(response[0]["AddDescriptorSet"]["status"], 0)

all_queries = []
descriptor_blob = []

total = 1000;

for i in range(1,total):
x = np.ones(dims)
x[2] = 2.34 + i*20
x = x.astype('float32')
descriptor_blob.append(x.tobytes())

descriptor = {}
descriptor["set"] = set_name
descriptor["label"] = "classX"

query = {}
query["AddDescriptor"] = descriptor

all_queries.append(query)

response, img_array = db.query(all_queries, [descriptor_blob])

# Check success
for x in range(0,total-1):
self.assertEqual(response[x]["AddDescriptor"]["status"], 0)


def test_addDescriptorsx1000TileDBSparse(self):

db = self.create_connection()

all_queries = []

# Add Set
set_name = "tiledbsparse_l2_128dx1000"
dims = 128
descriptor_set = {}
descriptor_set["name"] = set_name
descriptor_set["dimensions"] = dims
descriptor_set["metric"] = "L2"
descriptor_set["engine"] = "TileDBSparse"

query = {}
query["AddDescriptorSet"] = descriptor_set

all_queries.append(query)

response, img_array = db.query(all_queries)
self.assertEqual(response[0]["AddDescriptorSet"]["status"], 0)
self.assertEqual(response[0]["status"], -1)
self.assertEqual(response[0]["info"], "Blob Dimensions Mismatch")

# Add Descriptors
all_queries = []
descriptor_blob = []

total = 1000;

for i in range(1,total):
x = np.ones(dims)
x[2] = 2.34 + i*20
x = x.astype('float32')
descriptor_blob.append(x.tobytes())
x = np.zeros(dims)[:-1]
x = x.astype('float32')
# print type(x[0])
# print "size: ", len(x.tobytes())/4
descriptor_blob.append(x.tobytes())

descriptor = {}
descriptor["set"] = set_name
descriptor["label"] = "classX"
descriptor = {}
descriptor["set"] = set_name

query = {}
query["AddDescriptor"] = descriptor
query = {}
query["AddDescriptor"] = descriptor

all_queries.append(query)
all_queries.append(query)

response, img_array = db.query(all_queries, [descriptor_blob])

# Check success
for x in range(0,total-1):
self.assertEqual(response[x]["AddDescriptor"]["status"], 0)
self.assertEqual(response[0]["status"], -1)
self.assertEqual(response[0]["info"], "Blob Dimensions Mismatch")

def test_addDescriptorsx1000TileDBDense(self):
def test_addDescriptorsx1000(self):

db = self.create_connection()

all_queries = []

# Add Set
set_name = "tiledbdense_l2_128dx1000"
set_name = "features_128dx1000"
dims = 128
descriptor_set = {}
descriptor_set["name"] = set_name
descriptor_set["dimensions"] = dims
descriptor_set["metric"] = "L2"
descriptor_set["engine"] = "TileDBDense"

query = {}
query["AddDescriptorSet"] = descriptor_set

all_queries.append(query)

response, img_array = db.query(all_queries)
# print(json.dumps(all_queries, indent=4, sort_keys=False))
self.assertEqual(response[0]["AddDescriptorSet"]["status"], 0)

all_queries = []
Expand Down
Loading