Getting images in bulk from thispersondoesnotexist.com

Nandhugp

Power Member
Joined
Jan 24, 2013
Messages
578
Reaction score
286
So recently I saw thispersondoesnotexist.com where computer generates a person face that doesn't even exist. I told some of my friends and they didn't even believe it. So I wanted to share something that this community may find useful. Even though I don't have any method to make money:p, I wanted to contribute something to this community for everything that I learned here.

This is a simple code any python noob can do. ;)

Make sure you enter the directory in this format
E:/images/
If you put E:/images it wont work
To make this work you need to have urllib3 module installed on python.
Code:
import urllib.request
import random


n=input("How many images do you need?")
val=int(n)
dir=input("Enter the directory you want to save")
for i in range(val):
   file_name = random.randrange(1,10000)
   full_file_name = dir + str(file_name) + '.jpg' #Insert your
   def downloader(image_url,full_file_name):


     urllib.request.urlretrieve(image_url,full_file_name)

   downloader("https://www.thispersondoesnotexist.com/",full_file_name)

I actually wanted to do something more like detecting gender and age. i couldn't because I was unable to install tensorflow in my PC:weep:. Tensorflow requires 64 bit PC but mine only have 32 bit. I also looked for trial VPS but couldn't find any, However I found an idea on how to make it work.

So py-agender is an python module that can detect gender and age from a photo.
Code:
from pyagender import PyAgender

agender = PyAgender()
# see available options in __init__() src

faces = agender.detect_genders_ages(cv2.imread(MY_IMAGE))
# [
#   {left: 34, top: 11, right: 122, bottom: 232, width:(r-l), height: (b-t), gender: 0.67, age: 23.5},
#   ...
# ]

This is the base code for using this module. It requires cv2 and tensorflow. I don't know what output we get after executing the code but certainly we will get the probability of gender.

We can use that to save the image file with the gender and age on the image file.

This code can be further modified to get image of specified gender and age group by saving those files in another folder.

This might help people who are creating bulk accounts and such. :)
 
Thanks for the share, I saw this before and now I started a project where I need a lot of faces and remembered I saw this somewhere.
Can this be done for php as its much easier to find place to host your -php scripts .
 
Thanks for the replay, that should work but the gender recognition is I guess only Python library (as far as I searched about alternative)
The problem is that I can not restrict the pictures by gender at least....
 
after the php tag add $a=0;

inside the while loop add while($a<50)

and after 'echo $fn;'
add '$a++;'
 
Where do I define how many loops to do? For example 50 loops .
Instead of while, use a for loop.. e.g.
Code:
for($i = 0; $i < 50; $i++){

$fn = time().md5(rand()).'.jpg';
file_put_contents(getcwd().'/img/'.$fn, file_get_contents('https://thispersondoesnotexist.com/image'));
echo $fn;

}
 
Instead of while, use a for loop.. e.g.
Code:
for($i = 0; $i < 50; $i++){

$fn = time().md5(rand()).'.jpg';
file_put_contents(getcwd().'/img/'.$fn, file_get_contents('https://thispersondoesnotexist.com/image'));
echo $fn;

}
this works too
 
Back
Top