It's a two part question,
import face_recognition
import os
import json
loadarr=[]
encodearr=[]
for i in range(0, 4):
loadarr.append(face_recognition.load_image_file( "brad"+str(i+1)+".jpg"))
encodearr.append(face_recognition.face_encodings(loadarr[i])[0])
encodearr = encodearr.tolist()
# print(encodearr)
encodedDic = {"des": encodearr}
with open("sample.json", "w") as outfile:
json.dump(encodedDic,outfile)
When I tried to convert the list encodearr
as value of the key "des"
(without .tolist()) it shows
TypeError: Object of type ndarray is not JSON serializable
.Then I added .tolist() to encode arr as show. it shows AttributeError: 'list' object has no attribute 'tolist'
, brad1 to brad5 are the jpg files in the directory.