AttributeError: 'module' object has no attribute 'get_frontal_face_detector'
<p>I was trying to use python's dlib library to detect the facial landmarks. I was using the example given on <a href="http://dlib.net/face_landmark_detection.py.html" rel="nofollow">face detector</a>. I have installed all the dependencies before installing dlib.</p>

<p>First I installed cmake and libboost using "sudo apt-get install libboost-python-dev cmake" as given on the link above. I then installed dlib using "pip install dlib".</p>

<p>My code:</p>

<pre><code>import sys
import os
import dlib
import glob
from skimage import io

predictor_path = 'shape_predictor_68_face_landmarks.dat'
faces_folder_path = './happy'
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(predictor_path)
win = dlib.image_window()

for f in glob.glob(os.path.join(faces_folder_path, "*.jpg")):
    print("Processing file: {}".format(f))
    img = io.imread(f)

    win.clear_overlay()
    win.set_image(img)

    # Ask the detector to find the bounding boxes of each face. The 1 in the
    # second argument indicates that we should upsample the image 1 time. This
    # will make everything bigger and allow us to detect more faces.
    dets = detector(img, 1)
    print("Number of faces detected: {}".format(len(dets)))
    for k, d in enumerate(dets):
        print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(
            k, d.left(), d.top(), d.right(), d.bottom()))
        # Get the landmarks/parts for the face in box d.
        shape = predictor(img, d)
        print("Part 0: {}, Part 1: {} ...".format(shape.part(0),
                                                  shape.part(1)))
        # Draw the face landmarks on the screen.
        win.add_overlay(shape)

    win.add_overlay(dets)
    dlib.hit_enter_to_continue() 
</code></pre>

<p>But when I run the program, I get the following error:</p>

<pre><code>Traceback (most recent call last):
  File "dlib.py", line 2, in &lt;module&gt;
    import dlib
  File "/home/shivam/musicplayer/dlib.py", line 6, in &lt;module&gt;
    detector = dlib.get_frontal_face_detector() #Face detector
AttributeError: 'module' object has no attribute 'get_frontal_face_detector'
</code></pre>

<p>Here is the directory structure of my project:
<a href="http://i.stack.imgur.com/oYGuE.png" rel="nofollow"><img src="http://i.stack.imgur.com/oYGuE.png" alt="enter image description here"></a></p>

<p>Rename your file from <code>dlib.py</code> to something else, say <code>dlib_project.py</code>. </p>

<p>Your file, named so, is shadowing the <code>dlib</code> library that has all of the functionality you need, as it is imported instead of the library, being first in the hierarchy.</p>

python opencv dlib