python 批量生成人脸照片

有一个需求:需要大量的人脸数据
找到一个网站可以拿到生成人脸图片
https://thispersondoesnotexist.com/image


import requests
from faker import Faker
import requests
import threading
import time
from datetime import datetime


faker = Faker (locale='zh_CN')

def thread_func():  # 线程函数
    image_path = "image/{}.jpg".format(faker.name())
    req = requests.get("https://thispersondoesnotexist.com/image")
    file = open(image_path, 'wb')
    file.write(req.content)
    file.close()

def many_thread():
    threads = []
    for _ in range(50):  # 循环创建线程
        t = threading.Thread(target=thread_func)
        threads.append(t)
        t.setDaemon(True)  # 给每个子线程添加守护线程
    for t in threads:  # 循环启线程
        t.start()
    for t in threads:
        t.join(2)  # 设置子线程超时2秒

if __name__ == '__main__':
    for i in range(4):
        many_thread()

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容