美文网首页
python 批量生成人脸照片

python 批量生成人脸照片

作者: 铁甲依然在人间 | 来源:发表于2021-09-14 18:09 被阅读0次

有一个需求:需要大量的人脸数据
找到一个网站可以拿到生成人脸图片
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()

相关文章

网友评论

      本文标题:python 批量生成人脸照片

      本文链接:https://www.haomeiwen.com/subject/bahlgltx.html