To avoid the issue: Invaliid __array_struct__ , you can easely bypass the filtering function with a try and extracting only the embedding array in the embedding function:
to get only the embeddings array with insight face:
emb_res = app.get(rgb_arr)
res = emb_res[0].embedding
Then the function will be :
def generate_embs(img_fpaths: List[str]):
embs_set = list()
embs_label = list()
for img_fpath in img_fpaths:
print('tratamento: ',img_fpath)
# read grayscale img
img = Image.open(os.path.join(YALE_DIR, img_fpath))
img_arr = np.asarray(img)
# convert grayscale to rgb
im = Image.fromarray((img_arr * 255).astype(np.uint8))
rgb_arr = np.asarray(im.convert('RGB'))
# generate Insightface embedding
emb_res = app.get(rgb_arr)
try:
res = emb_res[0].embedding
# append emb to the eval set
embs_set.append(res)
# append label to eval_label set
embs_label.append(img_fpath.split("_")[0])
except:
print('no embedding found for this image')
return embs_set, embs_label
this way no need for filtering the set is updated only if the embedding exist.
Thanks a lot for your work Dr. Varshita Sher!
To avoid the issue: Invaliid __array_struct__ , you can easely bypass the filtering function with a try and extracting only the embedding array in the embedding function:
to get only the embeddings array with insight face:
Then the function will be :
this way no need for filtering the set is updated only if the embedding exist.
Then replace these 2 lines:
with
or rename the variables name
Check my answer on stackoverflow:
https://stackoverflow.com/questions/69618467/numpy-np-array-valueerror-invalid-array-struct/70909945#70909945