import glob
import tempfile
from decimal import Decimal
from pathlib import Path
from typing import List, Dict, Any
import gradio as gr
from PIL import Image
import open_clip
import torch
import os
import pandas as pd
import numpy as np
from gradio import processing_utils, utils
from download_example_images import read_actor_files, save_images_to_folder
DEFAULT_INITIAL_NAME = "John Doe"
PROMPTS = [
'{0}',
'an image of {0}',
'a photo of {0}',
'{0} on a photo',
'a photo of a person named {0}',
'a person named {0}',
'a man named {0}',
'a woman named {0}',
'the name of the person is {0}',
'a photo of a person with the name {0}',
'{0} at a gala',
'a photo of the celebrity {0}',
'actor {0}',
'actress {0}',
'a colored photo of {0}',
'a black and white photo of {0}',
'a cool photo of {0}',
'a cropped photo of {0}',
'a cropped image of {0}',
'{0} in a suit',
'{0} in a dress'
]
OPEN_CLIP_MODEL_NAMES = ['ViT-B-32', 'ViT-B-16', 'ViT-L-14']
NUM_TOTAL_NAMES = 1_000
SEED = 42
MIN_NUM_CORRECT_PROMPT_PREDS = 1
EDAMPLE_IMAGE_DIR = './example_images/'
IMG_BATCHSIZE = 16
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
EXAMPLE_IMAGE_URLS = read_actor_files(EDAMPLE_IMAGE_DIR)
save_images_to_folder(os.path.join(EDAMPLE_IMAGE_DIR, 'images'), EXAMPLE_IMAGE_URLS)
MODELS = {}
for model_name in OPEN_CLIP_MODEL_NAMES:
dataset = 'LAION400M'
model, _, preprocess = open_clip.create_model_and_transforms(
model_name,
pretrained=f'{dataset.lower()}_e32'
)
model = model.eval()
MODELS[f'OpenClip {model_name} trained on {dataset}'] = {
'model_instance': model,
'preprocessing': preprocess,
'model_name': model_name,
'prompt_text_embeddings': torch.load(f'./prompt_text_embeddings/{model_name}_prompt_text_embeddings.pt')
}
FULL_NAMES_DF = pd.read_csv('full_names.csv', index_col=0)
LAION_MEMBERSHIP_OCCURENCE = pd.read_csv('laion_membership_occurence_count.csv', index_col=0)
EXAMPLE_ACTORS_BY_MODEL = {
"ViT-B-32": ["T._J._Thyne"],
"ViT-B-16": ["Barbara_Schöneberger", "Carolin_Kebekus"],
"ViT-L-14": ["Max_Giermann", "Nicole_De_Boer"]
}
EXAMPLES = []
for model_name, person_names in EXAMPLE_ACTORS_BY_MODEL.items():
for name in person_names:
image_folder = os.path.join("./example_images/images/", name)
for dd_model_name in MODELS.keys():
if model_name not in dd_model_name:
continue
EXAMPLES.append([
dd_model_name,
name.replace("_", " "),
[[x.format(name.replace("_", " ")) for x in PROMPTS]],
[os.path.join(image_folder, x) for x in os.listdir(image_folder)]
])
LICENSE_DETAILS = """
Example Images License Information
### Barbara Schöneberger
| Image Name | Image Url | Author | License |
|----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|--------------|
| Barbara_Schöneberger_0.jpg | [https://upload.wikimedia.org/wikipedia/commons/1/1d/Barbara_Sch%C3%B6neberger_-_Deutscher_Radiopreis_Hamburg_2016_13.jpg](https://upload.wikimedia.org/wikipedia/commons/1/1d/Barbara_Sch%C3%B6neberger_-_Deutscher_Radiopreis_Hamburg_2016_13.jpg) | Frank Schwichtenberg | CC-BY-SA-3.0 |
| Barbara_Schöneberger_1.jpg | [https://upload.wikimedia.org/wikipedia/commons/9/9d/Barbara_Sch%C3%B6neberger_%282007%29.jpg](https://upload.wikimedia.org/wikipedia/commons/9/9d/Barbara_Sch%C3%B6neberger_%282007%29.jpg) | Pottschalk | CC-BY-SA-3.0 |
| Barbara_Schöneberger_2.jpg | [https://upload.wikimedia.org/wikipedia/commons/f/f0/Barbara_Sch%C3%B6neberger_-_Deutscher_Radiopreis_Hamburg_2016_03.jpg](https://upload.wikimedia.org/wikipedia/commons/f/f0/Barbara_Sch%C3%B6neberger_-_Deutscher_Radiopreis_Hamburg_2016_03.jpg) | Frank Schwichtenberg | CC-BY-SA-3.0 |
| Barbara_Schöneberger_3.jpg | [https://upload.wikimedia.org/wikipedia/commons/f/fa/Barbara_Sch%C3%B6neberger_-_Deutscher_Radiopreis_Hamburg_2016_12.jpg](https://upload.wikimedia.org/wikipedia/commons/f/fa/Barbara_Sch%C3%B6neberger_-_Deutscher_Radiopreis_Hamburg_2016_12.jpg) | Frank Schwichtenberg | CC-BY-SA-3.0 |
| Barbara_Schöneberger_4.jpg | [https://upload.wikimedia.org/wikipedia/commons/0/0a/Barbara_Sch%C3%B6neberger_-_Deutscher_Radiopreis_Hamburg_2016_01.jpg](https://upload.wikimedia.org/wikipedia/commons/0/0a/Barbara_Sch%C3%B6neberger_-_Deutscher_Radiopreis_Hamburg_2016_01.jpg) | Frank Schwichtenberg | CC-BY-SA-3.0 |
### Carolin Kebekus
| Image Name | Image Url | Author | License |
|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------|--------------|
| Carolin_Kebekus_0.jpg | [https://upload.wikimedia.org/wikipedia/commons/c/ce/Carolin_Kebekus_-_2019102193318_2019-04-12_Radio_Regenbogen_Award_2019_-_Sven_-_1D_X_MK_II_-_0905_-_AK8I0075.jpg](https://upload.wikimedia.org/wikipedia/commons/c/ce/Carolin_Kebekus_-_2019102193318_2019-04-12_Radio_Regenbogen_Award_2019_-_Sven_-_1D_X_MK_II_-_0905_-_AK8I0075.jpg) | Sven Mandel | CC-BY-SA-4.0 |
| Carolin_Kebekus_1.jpg | [https://upload.wikimedia.org/wikipedia/commons/4/45/Carolin-Kebekus-Bonn.jpg](https://upload.wikimedia.org/wikipedia/commons/4/45/Carolin-Kebekus-Bonn.jpg) | Superbass | CC-BY-SA-3.0 |
| Carolin_Kebekus_2.jpg | [https://upload.wikimedia.org/wikipedia/commons/4/45/Carolin-Kebekus-Bonn.jpg](https://upload.wikimedia.org/wikipedia/commons/4/45/Carolin-Kebekus-Bonn.jpg) | Sven Mandel | CC-BY-SA-4.0 |
| Carolin_Kebekus_3.jpg | [https://upload.wikimedia.org/wikipedia/commons/0/02/Carolin_Kebekus-5848.jpg](https://upload.wikimedia.org/wikipedia/commons/0/02/Carolin_Kebekus-5848.jpg) | Harald Krichel | CC-BY-SA-3.0 |
| Carolin_Kebekus_4.jpg | [https://upload.wikimedia.org/wikipedia/commons/e/e1/2021-09-16-Carolin_Kebekus_Deutscher_Fernsehpreis_2021_-3757.jpg](https://upload.wikimedia.org/wikipedia/commons/e/e1/2021-09-16-Carolin_Kebekus_Deutscher_Fernsehpreis_2021_-3757.jpg) | Superbass | CC-BY-SA-4.0 |
### Max Giermann
| Image Name | Image Url | Author | License |
|--------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|--------------|
| Max_Giermann_0.jpg | [https://upload.wikimedia.org/wikipedia/commons/4/4b/2018-01-26-DFP_2018-7513.jpg](https://upload.wikimedia.org/wikipedia/commons/4/4b/2018-01-26-DFP_2018-7513.jpg) | Superbass | CC-BY-SA-4.0 |
| Max_Giermann_1.jpg | [https://upload.wikimedia.org/wikipedia/commons/f/f6/Deutscher_Fernsehpreis_2012_-_Max_Giermann.jpg](https://upload.wikimedia.org/wikipedia/commons/f/f6/Deutscher_Fernsehpreis_2012_-_Max_Giermann.jpg) | JCS | CC-BY-3.0 |
| Max_Giermann_2.jpg | [https://upload.wikimedia.org/wikipedia/commons/1/1c/Hessischer_Filmpreis_2017_-_Max_Giermann_2.JPG](https://upload.wikimedia.org/wikipedia/commons/1/1c/Hessischer_Filmpreis_2017_-_Max_Giermann_2.JPG) | JCS | CC-BY-3.0 |
| Max_Giermann_3.jpg | [https://upload.wikimedia.org/wikipedia/commons/1/1d/Max_Giermann_%28extra_3%29_01.jpg](https://upload.wikimedia.org/wikipedia/commons/1/1d/Max_Giermann_%28extra_3%29_01.jpg) | Frank Schwichtenberg | CC-BY-SA-3.0 |
| Max_Giermann_4.jpg | [https://upload.wikimedia.org/wikipedia/commons/8/85/Max_Giermann_%28extra_3%29_03.jpg](https://upload.wikimedia.org/wikipedia/commons/8/85/Max_Giermann_%28extra_3%29_03.jpg) | Frank Schwichtenberg | CC-BY-SA-3.0 |
### Nicole De Boer
| Image Name | Image Url | Author | License |
|----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|--------------|
| Nicole_De_Boer_0.jpg | [https://upload.wikimedia.org/wikipedia/commons/0/03/Praha%2C_Lhotka%2C_KC_Novodvorsk%C3%A1%2C_CzechTREK_2013_%2827%29.jpg](https://upload.wikimedia.org/wikipedia/commons/0/03/Praha%2C_Lhotka%2C_KC_Novodvorsk%C3%A1%2C_CzechTREK_2013_%2827%29.jpg) | Harold | CC-BY-SA-3.0 |
| Nicole_De_Boer_1.jpg | [https://upload.wikimedia.org/wikipedia/commons/d/db/Nicole_DeBoer_at_Toronto_Comicon_1.jpg](https://upload.wikimedia.org/wikipedia/commons/d/db/Nicole_DeBoer_at_Toronto_Comicon_1.jpg) | Tabercil | CC-BY-SA-3.0 |
| Nicole_De_Boer_2.jpg | [https://upload.wikimedia.org/wikipedia/commons/4/4b/Nicole_de_Boer_at_Toronto_Comicon_2_%28cropped%29.jpg](https://upload.wikimedia.org/wikipedia/commons/4/4b/Nicole_de_Boer_at_Toronto_Comicon_2_%28cropped%29.jpg) | Tabercil | CC-BY-SA-3.0 |
| Nicole_De_Boer_3.jpg | [https://upload.wikimedia.org/wikipedia/commons/b/b9/Nicole_de_boer_LFCC2015.jpg](https://upload.wikimedia.org/wikipedia/commons/b/b9/Nicole_de_boer_LFCC2015.jpg) | Dazzoboy | CC-BY-SA-4.0 |
| Nicole_De_Boer_4.jpg | [https://upload.wikimedia.org/wikipedia/commons/9/90/Nicole_de_Boer_at_Toronto_Comicon_2.jpg](https://upload.wikimedia.org/wikipedia/commons/9/90/Nicole_de_Boer_at_Toronto_Comicon_2.jpg) | Tabercil | CC-BY-SA-3.0 |
### T. J. Thyne
| Image Name | Image Url | Author | License |
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------|--------------|
| T._J._Thyne_0.jpg | [https://live.staticflickr.com/7036/6837850246_c09a148d70_o.jpg](https://live.staticflickr.com/7036/6837850246_c09a148d70_o.jpg) | Genevieve | CC-BY-2.0 |
| T._J._Thyne_1.jpg | [https://live.staticflickr.com/3273/5705869811_d9ff808383_o.jpg](https://live.staticflickr.com/3273/5705869811_d9ff808383_o.jpg) | Genevieve | CC-BY-2.0 |
| T._J._Thyne_2.jpg | [https://upload.wikimedia.org/wikipedia/commons/d/d8/TJThyneFanExpo2017.jpg](https://upload.wikimedia.org/wikipedia/commons/d/d8/TJThyneFanExpo2017.jpg) | Christian Dahl-Lacroix | CC-BY-SA-4.0 |
| T._J._Thyne_3.jpg | [https://live.staticflickr.com/7041/6984629777_8a415b72d9_b.jpg](https://live.staticflickr.com/7041/6984629777_8a415b72d9_b.jpg) | Genevieve | CC-BY-2.0 |
| T._J._Thyne_4.jpg | [https://live.staticflickr.com/7042/6837821654_d65ab80913_b.jpg](https://live.staticflickr.com/7042/6837821654_d65ab80913_b.jpg) | Genevieve | CC-BY-2.0 |
Want to know whether you were used to train a CLIP model? Below you can choose a model, enter your name and upload some pictures.
If the model correctly predicts your name for multiple images, it is very likely that you were part of the training data.
Pick some of the examples below and try it out!
Details and further analysis can be found in the paper
Does CLIP Know My Face?
.
Created by Dominik Hintersdorf at AIML Lab.