python 批量生成人脸照片

2021-09-14  本文已影响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()

上一篇 下一篇

猜你喜欢

热点阅读