Spaces:
Runtime error
Runtime error
cakiki
commited on
Commit
•
57d0e79
0
Parent(s):
Duplicate from tti-bias/identities-bovw-knn
Browse files- .gitattributes +34 -0
- README.md +14 -0
- app.py +47 -0
- indexes/knn_10752_65.npy +3 -0
- indexes/knn_1536_65.npy +3 -0
- indexes/knn_768_65.npy +3 -0
- requirements.txt +3 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Identities BOVW k-nn
|
3 |
+
emoji: 📉
|
4 |
+
colorFrom: green
|
5 |
+
colorTo: red
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.16.2
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: apache-2.0
|
11 |
+
duplicated_from: tti-bias/identities-bovw-knn
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from datasets import load_dataset
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
|
6 |
+
gender_labels = ['man', 'non-binary', 'woman', 'no_gender_specified', ]
|
7 |
+
|
8 |
+
ethnicity_labels = ['African-American', 'American_Indian', 'Black', 'Caucasian', 'East_Asian',
|
9 |
+
'First_Nations', 'Hispanic', 'Indigenous_American', 'Latino', 'Latinx',
|
10 |
+
'Multiracial', 'Native_American', 'Pacific_Islander', 'South_Asian',
|
11 |
+
'Southeast_Asian', 'White', 'no_ethnicity_specified']
|
12 |
+
models = ['DallE', 'SD_14', 'SD_2']
|
13 |
+
nos = [1,2,3,4,5,6,7,8,9,10]
|
14 |
+
indexes = [768, 1536, 10752]
|
15 |
+
ds = load_dataset("tti-bias/identities", split="train")
|
16 |
+
|
17 |
+
def get_nearest_64(gender, ethnicity, model, no, index):
|
18 |
+
df = ds.remove_columns(["image","image_path"]).to_pandas()
|
19 |
+
index = np.load(f"indexes/knn_{index}_65.npy")
|
20 |
+
ix = df.loc[(df['ethnicity'] == ethnicity) & (df['gender'] == gender) & (df['no'] == no) & (df['model'] == model)].index[0]
|
21 |
+
image = ds.select([index[ix][0]])["image"][0]
|
22 |
+
neighbors = ds.select(index[ix][1:25])
|
23 |
+
neighbor_images = neighbors["image"]
|
24 |
+
neighbor_captions = [caption.split("/")[-1] for caption in neighbors["image_path"]]
|
25 |
+
neighbor_captions = [' '.join(caption.split("_")[4:-3]) for caption in neighbor_captions]
|
26 |
+
neighbor_models = neighbors["model"]
|
27 |
+
neighbor_captions = [f"{a} {b}" for a,b in zip(neighbor_captions,neighbor_models)]
|
28 |
+
return image, list(zip(neighbor_images, neighbor_captions))
|
29 |
+
|
30 |
+
with gr.Blocks() as demo:
|
31 |
+
gr.Markdown("# BoVW Nearest Neighbors Explorer")
|
32 |
+
gr.Markdown("### TF-IDF index of the _identities_ dataset of images generated by 3 models using a visual vocabulary of 10,752 words.")
|
33 |
+
gr.Markdown("#### Choose one of the generated identity images to see its nearest neighbors according to a bag-of-visual-words model.")
|
34 |
+
with gr.Row():
|
35 |
+
with gr.Column():
|
36 |
+
model = gr.Radio(models, label="Model")
|
37 |
+
index = gr.Radio(indexes, label="Visual vocabulary size")
|
38 |
+
gender = gr.Radio(gender_labels, label="Gender label")
|
39 |
+
with gr.Column():
|
40 |
+
ethnicity = gr.Radio(ethnicity_labels, label="Ethnicity label")
|
41 |
+
no = gr.Radio(nos, label="Image number")
|
42 |
+
button = gr.Button(value="Get nearest neighbors")
|
43 |
+
with gr.Row():
|
44 |
+
image = gr.Image()
|
45 |
+
gallery = gr.Gallery().style(grid=4)
|
46 |
+
button.click(get_nearest_64, inputs=[gender, ethnicity, model, no, index], outputs=[image, gallery])
|
47 |
+
demo.launch()
|
indexes/knn_10752_65.npy
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:47eb9dbb1b403c0533e09336bd592125a0db83f2c122ca267bbc05fc877d05c1
|
3 |
+
size 530528
|
indexes/knn_1536_65.npy
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:fe2929f63867d439eb36f73bf4ad6056a036def14a7176149afddb884f4b9703
|
3 |
+
size 530528
|
indexes/knn_768_65.npy
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f06c06fd8388b6013446468832b1a2087144b651e7c5f065eb9ee6a381c86a8e
|
3 |
+
size 530528
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
datasets[vision]
|
2 |
+
numpy
|
3 |
+
imutils
|