def create_evaluation_desc_datastore(orb, kind): storage_client = storage.Client('adina-image-analysis') bucket = storage_client.get_bucket('sampled_social_media_images') datastore_client = datastore.Client('adina-image-analysis') for blob in bucket.list_blobs(): X = [] if not (utils.ext(blob.public_url) == '.jpeg' or utils.ext(blob.public_url) == '.png' or utils.ext(blob.public_url) == '.jpg'): continue try: img = utils.url_to_img(blob.public_url) except: continue k = datastore_client.key(kind, utils.del_ext(blob.name)) entity = datastore_client.get(k) if not entity: entity = datastore.Entity(key=k, exclude_from_indexes=['ORB Descriptors']) try: des = utils.compute_ORB(img, orb, show_image=False) if des.any() != None: for i in range(des.shape[0]): X.append(utils.convert_intList_to_bit(list(des[i]))) des_json = json.dumps(X) entity.update({ 'ORB Descriptors': des_json, 'Indexed(ORB)': "No" }) datastore_client.put(entity) else: continue except: continue return
def eval_compute_xq_cloud(orb, img_url): """compute the query vector of descriptors from the image url""" img = utils.url_to_img(img_url) xq = [] try: des = utils.compute_ORB(img, orb, show_image=False) if des.any() != None: for i in range(des.shape[0]): xq.append(utils.convert_intList_to_bit(list(des[i]))) else: return None except AttributeError: None return np.array(xq).astype('float32')
def sample_social_media_datastore(orb, quantity, kind): storage_client = storage.Client('adina-image-analysis') bucket = storage_client.get_bucket('adina-images') datastore_client = datastore.Client('adina-image-analysis') p = utils.count_storage('adina-images') l = list(range(p)) choseen = random.sample(l, quantity) i = 0 s = 31 for blob in bucket.list_blobs(): i += 1 X = [] if i in choseen: if not (utils.ext(blob.public_url) == '.jpeg' or utils.ext(blob.public_url) == '.png' or utils.ext(blob.public_url) == '.jpg'): continue if not (blob.name.startswith('4C') or blob.name.startswith('RE') or blob.name.startswith('R')): continue try: img = utils.url_to_img(blob.public_url) except: continue try: des = utils.compute_ORB(img, orb, show_image=False) if des.any() != None: for i in range(des.shape[0]): X.append(utils.convert_intList_to_bit(list(des[i]))) des_json = json.dumps(X) name = '333_' + str(s) s += 1 k = datastore_client.key(kind, name) entity = datastore.Entity(key=k, exclude_from_indexes=[ 'ORB Descriptors', 'VGG16 Descriptors' ]) # print("1") # print(entity) entity.update({ 'ORB Descriptors': des_json, 'Indexed(ORB)': "No" }) # print("2") # print(entity) datastore_client.put(entity) # print("3") # print(entity) if s % 1000 == 0: print(s, 'images processed') else: continue except: continue return