Reputation: 441
i am trying to crop out the faces from instagram avatars by first detecting the faces and then resizing the image. i am reading all the images which have been stored in a dataframe and then creating a numpy array. Then i am running a frontal face detector which returns me an object but when i call the object it returns me the error stated. i tried giving only colored images as input but that did not work neither did try and except. Here is the code:
df = pd.read_csv('/home/instaurls2.csv')
img_width, img_height = 139, 139
confidence = 0.8
#graph = K.get_session().graph
data1 = np.array([io.imread(row[1]) for row in df.itertuples()])
#print(data1)
detector = dlib.get_frontal_face_detector()
print (detector)
dets=detector(data1,1) # **error arrives here**
print (dets)
output=None
for i, d in enumerate(dets):
data1 = data1[d.top():d.bottom(), d.left():d.right()]
data1 = resize(data1, (img_width, img_height))
output = np.expand_dims(data1, axis=0)
print (output)
Upvotes: 7
Views: 18607
Reputation: 1
This worked for me: uninstall numpy >=2
pip uninstall numpy
pip install numpy==1.25.1
Upvotes: 0
Reputation: 87
This error is due to numpy 2. I reinstalled numpy with the following commands:
pip uninstall -y numpy
pip install numpy==1.23.5
and it started working properly!!
Upvotes: 2
Reputation: 589
This is an old thread but if anyone has recently encountered this error, this could very much be due to Numpy 2.0 major update; https://numpy.org/devdocs/release/2.0.0-notes.html
This was released couple of days ago and for the moment Dlib does not support it and throws the above error. I was setting up a new VM and spent hours investigating why the same code works in a previous one and not in the new one… hopefully Dlib will release an update supporting this new version soon, but in the meantime if you see this error - use an older Numpy version (1.X.X)
Upvotes: 12
Reputation: 1463
Opencv reads image as BGR per default.
You can read images with cv2:
import cv2
cv2.imread(image_filepath)
Upvotes: 3