I am facing this issue, but I couldn't figure out why because I don't know where something changes to str. I am using python 3.6 . This function is supposed to detect a face.
The error is detected in this line
person_name = os.path.basename(os.path.normpath(path(path)))
Code:
def extract_face(path_to_filename, detector, required_size=(160, 160), save_faces=True):
image = Image.open(path_to_filename)
image = image.convert('RGB')
pixels = asarray(image)
results = detector.detect_faces(pixels)
x1, y1, width, height = results[0]['box']
x1, y1 = abs(x1), abs(y1)
x2, y2 = x1 + width, y1 + height
face = pixels[y1:y2, x1:x2]
image = Image.fromarray(face)
image = image.resize(required_size)
if save_faces:
path = os.path.split(os.path.abspath(path_to_filename))[0]
file_name = os.path.split(os.path.abspath(path_to_filename))[1]
person_name = os.path.basename(os.path.normpath(path(path)))
project_folder = path(path).parent.parent
print(person_name)
target_folder = os.path.join(project_folder, 'faces_mini_dataset', person_name)
if not os.path.exists(target_folder):
os.makedirs(target_folder)
target_face_file_path = os.path.join(target_folder, file_name)
print(target_face_file_path)
image.save(target_face_file_path)
face_array = asarray(image)
return face_array
error:
TypeError: 'str' object is not callable
fulltrace:
WARNING:tensorflow:From /home/mani/Downloads/dip_1/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:74: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.
WARNING:tensorflow:From /home/mani/Downloads/dip_1/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:517: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.
WARNING:tensorflow:From /home/mani/Downloads/dip_1/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:4138: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.
WARNING:tensorflow:From /home/mani/Downloads/dip_1/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:3976: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.
WARNING:tensorflow:From /home/mani/Downloads/dip_1/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:174: The name tf.get_default_session is deprecated. Please use tf.compat.v1.get_default_session instead.
WARNING:tensorflow:From /home/mani/Downloads/dip_1/venv/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py:181: The name tf.ConfigProto is deprecated. Please use tf.compat.v1.ConfigProto instead.
2020-12-30 01:02:58.905653: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-12-30 01:02:58.926680: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2299965000 Hz
2020-12-30 01:02:58.927412: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x484d980 executing computations on platform Host. Devices:
2020-12-30 01:02:58.927467: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): <undefined>, <undefined>
2020-12-30 01:02:59.110157: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set. If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU. To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.
Extracting faces from /home/mani/Downloads/dip_1/persons_dataset/zakir/ .....
Traceback (most recent call last):
File "/home/mani/Downloads/dip_1/face_detector.py", line 85, in <module>
faces, labels = generate_faces_from_images(persons_dataset_path)
File "/home/mani/Downloads/dip_1/face_detector.py", line 74, in generate_faces_from_images
faces1 = extract_faces(path)
File "/home/mani/Downloads/dip_1/face_detector.py", line 59, in extract_faces
face = extract_face(path, detector, save_faces=True)
File "/home/mani/Downloads/dip_1/face_detector.py", line 38, in extract_face
person_name = os.path.basename(os.path.normpath(path(path)))
TypeError: 'str' object is not callable
Process finished with exit code 1