【发布时间】:2022-01-15 01:41:31
【问题描述】:
import glob
import os
from mtcnn.mtcnn import MTCNN
import warnings
import time
from numpy import asarray
from PIL import Image
#warnings.filterwarnings("ignore")
#os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
directory = input("insert input path \n")
output_directory = input("insert output path \n")
#mode=input("do you want to conver the outputs to Grayscale ?")
img_names=glob.glob(os.path.join(directory+"/*.jpg"))
detector = MTCNN()
def process_image(img_name,mode='L',output_size=(160,160)):
img = Image.open(directory+img_name)
img.thumbnail((160,160))
pixels=asarray(img)
results = detector.detect_faces(pixels)
if results:
# extract the bounding box from the requested face
x1 ,y1,width,height=results[0]['box']
x1,y1=abs(x1),abs(y1)
x2,y2=x1 + width,y1 + height
# extract the face by slicing
face_boundary = pixels[y1:y2, x1:x2]
# resize pixels to the model size
#image1 = Image.fromarray(face_boundary)
#image1 = image.resize(required_size)
image=Image.fromarray(face_boundary)
#if mode=='L':
# image=image.convert('L')
image = image.resize(output_size)
#image.thumbnail((160,160))
#image = image.resize(())
#face_array = asarray(image)
#image.save(f"/kaggle/input/rashaa/rasha{img_name}")
image.save(f'{output_directory}{img_name}')
print(f'{img_name} was processed...')
#for img in img_names:
# x.append(img.replace(directory,""))
x=[img.replace(directory,"") for img in img_names]
t1 = time.perf_counter()
y=[process_image(img) for img in x]
t2=time.perf_counter()
print(t2-t1)
代码通过检测和提取输入文件夹中的人脸并将提取的人脸放入输出文件夹来完成这项工作,没有任何问题 但我想知道为什么这个警告首先出现,有什么办法可以“正确”修复它而不是抑制它
详情
-
TensorFlow 版本(CPU):2.7.0
-
python 版本 3.8.4
警告消息是 WARNING:tensorflow:5 out of the last 9 calls to
【问题讨论】:
-
您使用的是哪个 TensorFlow 版本?我在 Tensorflow 2.4.1 上尝试了您的代码 sn-p,但没有收到该警告。
-
我现在用的是TensorFlow 2.7.0,你用的是GPU还是CPU版本?
-
我也尝试了 2.7.0 以及 CPU 和 GPU 版本。仍然没有错误消息。
标签: python tensorflow computer-vision warnings face-detection