MarkusStoll commited on
Commit
3e94b6c
0 Parent(s):

Duplicate from renumics/navigate-data-issues

Browse files
Files changed (9) hide show
  1. .gitattributes +34 -0
  2. .gitignore +2 -0
  3. Dockerfile +18 -0
  4. README.md +20 -0
  5. layout.json +135 -0
  6. prepare.py +47 -0
  7. requirements.txt +2 -0
  8. run.py +72 -0
  9. spotlight-layout.json +1 -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
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+
2
+ .venv/
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+ ENV HOME=/code
5
+
6
+ RUN apt install curl
7
+ RUN pip install pip -U
8
+
9
+ RUN pip install renumics-spotlight==1.3.0
10
+
11
+ RUN pip install datasets
12
+ COPY prepare.py .
13
+ RUN python prepare.py
14
+
15
+ COPY . .
16
+ RUN mkdir -p /code/.cache
17
+ RUN chmod -R 777 /code
18
+ CMD ["python", "run.py"]
README.md ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Navigate Cleanlab Data Issues in CIFAR-100 with Spotlight
3
+ emoji: 🧐
4
+ colorFrom: gray
5
+ colorTo: blue
6
+ sdk: docker
7
+ pinned: false
8
+ license: gpl-3.0
9
+ app_file: run.py
10
+ datasets:
11
+ - renumics/cifar100-enriched
12
+ - cifar100
13
+ tags:
14
+ - renumics
15
+ - spotlight
16
+ - EDA
17
+ duplicated_from: renumics/navigate-data-issues
18
+ ---
19
+
20
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
layout.json ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "orientation": "horizontal",
3
+ "children": [
4
+ {
5
+ "kind": "split",
6
+ "weight": 44.24966799468792,
7
+ "orientation": "vertical",
8
+ "children": [
9
+ {
10
+ "kind": "tab",
11
+ "weight": 33.54784241752236,
12
+ "children": [
13
+ {
14
+ "kind": "widget",
15
+ "name": "Table",
16
+ "type": "table",
17
+ "config": {
18
+ "tableView": "full",
19
+ "visibleColumns": [
20
+ "label",
21
+ "label_score",
22
+ "near_duplicate_score",
23
+ "pred",
24
+ "outlier_score"
25
+ ],
26
+ "sorting": null,
27
+ "orderByRelevance": false
28
+ }
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ "kind": "tab",
34
+ "weight": 23.686809949341544,
35
+ "children": [
36
+ {
37
+ "kind": "widget",
38
+ "name": "Issues",
39
+ "type": "IssuesWidget",
40
+ "config": null
41
+ }
42
+ ]
43
+ },
44
+ {
45
+ "kind": "tab",
46
+ "weight": 42.765347633136095,
47
+ "children": [
48
+ {
49
+ "kind": "widget",
50
+ "name": "Inspector",
51
+ "type": "inspector",
52
+ "config": {
53
+ "views": [
54
+ {
55
+ "view": "ImageView",
56
+ "columns": [
57
+ "full_image"
58
+ ],
59
+ "name": "full_image",
60
+ "key": "7hA9fgoBXsKTCCFVYZfhRb"
61
+ },
62
+ {
63
+ "view": "TextLens",
64
+ "columns": [
65
+ "label"
66
+ ],
67
+ "name": "view",
68
+ "key": "a7fedf96-f36e-4836-9ffe-7b249c16db46"
69
+ },
70
+ {
71
+ "view": "TextLens",
72
+ "columns": [
73
+ "pred"
74
+ ],
75
+ "name": "view",
76
+ "key": "527a66c2-b3d4-4be0-9879-8749ee4fd0ed"
77
+ }
78
+ ],
79
+ "visibleColumns": 8
80
+ }
81
+ }
82
+ ]
83
+ }
84
+ ]
85
+ },
86
+ {
87
+ "kind": "tab",
88
+ "weight": 55.75033200531208,
89
+ "children": [
90
+ {
91
+ "kind": "widget",
92
+ "name": "Similarity Map",
93
+ "type": "similaritymap",
94
+ "config": {
95
+ "placeBy": [
96
+ "embedding_reduced"
97
+ ],
98
+ "reductionMethod": null,
99
+ "colorBy": "label",
100
+ "sizeBy": "is_label_issue",
101
+ "filter": false,
102
+ "umapNNeighbors": 20,
103
+ "umapMetric": "cosine",
104
+ "umapMinDist": 0.15,
105
+ "pcaNormalization": null,
106
+ "umapMenuLocalGlobalBalance": null,
107
+ "umapMenuIsAdvanced": false
108
+ }
109
+ },
110
+ {
111
+ "kind": "widget",
112
+ "name": "Scatter Plot",
113
+ "type": "scatterplot",
114
+ "config": {
115
+ "xAxisColumn": null,
116
+ "yAxisColumn": null,
117
+ "colorBy": null,
118
+ "sizeBy": null,
119
+ "filter": false
120
+ }
121
+ },
122
+ {
123
+ "kind": "widget",
124
+ "name": "Histogram",
125
+ "type": "histogram",
126
+ "config": {
127
+ "columnKey": null,
128
+ "stackByColumnKey": null,
129
+ "filter": false
130
+ }
131
+ }
132
+ ]
133
+ }
134
+ ]
135
+ }
prepare.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+ import datasets
3
+ import os
4
+ import umap
5
+
6
+
7
+ if __name__ == "__main__":
8
+ cache_file = "dataset_cache.pkl"
9
+ if os.path.exists(cache_file):
10
+ # Load dataset from cache
11
+ with open(cache_file, "rb") as file:
12
+ dataset = pickle.load(file)
13
+ print("Dataset loaded from cache.")
14
+ else:
15
+ # Load dataset using datasets.load_dataset()
16
+ ds = datasets.load_dataset("renumics/cifar100-enriched", split="test")
17
+
18
+ print("Dataset loaded using datasets.load_dataset().")
19
+
20
+ df = ds.to_pandas()
21
+
22
+
23
+ df = ds.rename_columns({"fine_label": "labels"}).to_pandas()
24
+ from tabulate import tabulate
25
+ from cleanlab import Datalab
26
+ import pandas as pd
27
+ import numpy as np
28
+
29
+
30
+ lab = Datalab(data=ds, label_name="fine_label")
31
+ features=np.array([x.tolist() for x in df["embedding"]])
32
+ pred_probs= np.array([x.tolist() for x in df["probabilities"]])
33
+ lab.find_issues(features=features,pred_probs=pred_probs)
34
+ print(tabulate(lab.get_issues().iloc[[0,1,2,3,-3,-2,-1]], headers='keys', tablefmt='psql'))
35
+
36
+
37
+
38
+ df_with_score = pd.concat([df, lab.get_issues()], axis=1)
39
+ df = df_with_score
40
+
41
+
42
+ # Save dataset to cache
43
+ with open(cache_file, "wb") as file:
44
+ pickle.dump(df, file)
45
+
46
+ print("Dataset saved to cache.")
47
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ renumics-spotlight
2
+ datasets
run.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+ from renumics import spotlight
3
+ import os
4
+ import requests
5
+ import pandas as pd
6
+ from renumics import spotlight
7
+ from renumics.spotlight.analysis import DataIssue
8
+
9
+
10
+
11
+ if __name__ == "__main__":
12
+ cache_file = "dataset_cache.pkl"
13
+
14
+ if os.path.exists(cache_file):
15
+ # Load dataset from cache
16
+ with open(cache_file, "rb") as file:
17
+ df = pickle.load(file)
18
+ print("Dataset loaded from cache.")
19
+
20
+
21
+ label_issue_rows = df[df["is_label_issue"]].sort_values("label_score").index.tolist()
22
+ label_issue = DataIssue(
23
+ severity="medium",
24
+ title="label-issue",
25
+ rows=label_issue_rows,
26
+ description="Label issue found by cleanlab - Review and correct if necessary",
27
+ )
28
+
29
+ outlier_issue_row = (
30
+ df[df["outlier_score"] < 0.6].sort_values("outlier_score").index.tolist()
31
+ )
32
+ outlier_issue = DataIssue(
33
+ severity="medium",
34
+ title="outlier-issue",
35
+ rows=outlier_issue_row,
36
+ description="Outlier score < 0.6 - Review and remove or collect more data",
37
+ )
38
+
39
+ near_duplicate_issue_row = (
40
+ df[df["is_near_duplicate_issue"]].sort_values("near_duplicate_score").index.tolist()
41
+ )
42
+ near_duplicate_issue = DataIssue(
43
+ severity="medium",
44
+ title="near-duplicate-issue",
45
+ rows=near_duplicate_issue_row,
46
+ description="Near duplicate issue found by cleanlab - Review and remove if necessary",
47
+ )
48
+
49
+
50
+ while True:
51
+ dtypes = {
52
+ "image": spotlight.Image,
53
+ "image_full": spotlight.Image,
54
+ "embedding": spotlight.Embedding,
55
+ "embedding_reduced": spotlight.Embedding,
56
+ "probabilities": spotlight.Embedding,
57
+ }
58
+
59
+ view = spotlight.show(
60
+ df.rename(columns={"fine_label_str": "label", "fine_label_prediction_str":"pred"}),
61
+ dtype=dtypes,
62
+ issues=[label_issue,outlier_issue,near_duplicate_issue],
63
+ layout="layout.json",
64
+ port=7860,
65
+ host="0.0.0.0",
66
+ allow_filebrowsing=False,
67
+ )
68
+
69
+ view.close()
70
+
71
+ else:
72
+ print(f"Dataset {cache_file} not found. Please run prepare.py first.")
spotlight-layout.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"orientation":"vertical","children":[{"kind":"split","weight":55.52608311229001,"orientation":"horizontal","children":[{"kind":"tab","weight":41.16700201207244,"children":[{"kind":"widget","name":"Table","type":"table","config":{"tableView":"full","visibleColumns":["coarse_label_str","fine_label_prediction_str","fine_label_str","image","__idx__"],"sorting":[["__idx__","DESC"]],"orderByRelevance":false,"columnWidths":{"coarse_label":92,"coarse_label_str":165,"embedding_reduced":128,"fine_label":92,"fine_label_prediction":92,"fine_label_prediction_error":92,"fine_label_prediction_str":244,"fine_label_str":194,"full_image":256,"image":200,"split":256,"__idx__":92,"__last_edited_at__":192,"__last_edited_by__":256}}}]},{"kind":"tab","weight":33.66487769877306,"children":[{"kind":"widget","name":"Similarity Map","type":"similaritymap","config":{"placeBy":null,"reductionMethod":null,"colorBy":"fine_label_str","sizeBy":null,"filter":false,"umapNNeighbors":20,"umapMetric":null,"umapMinDist":0.15,"pcaNormalization":null,"umapMenuLocalGlobalBalance":null,"umapMenuIsAdvanced":false}},{"kind":"widget","name":"Scatter Plot","type":"scatterplot","config":{"xAxisColumn":null,"yAxisColumn":null,"colorBy":null,"sizeBy":null,"filter":false}}]},{"kind":"tab","weight":25.168120289154498,"children":[{"kind":"widget","name":"Histogram","type":"histogram","config":{"columnKey":"fine_label_str","stackByColumnKey":"fine_label_prediction_error","filter":false}}]}]},{"kind":"tab","weight":44.47391688770999,"children":[{"kind":"widget","name":"Inspector","type":"inspector","config":{"views":[{"view":"ImageView","key":"es3NP2fbYeG5TzTQqCzZKL","name":"image","columns":["image"]},{"view":"TextLens","columns":["fine_label_str"],"name":"view","key":"7262001a-1270-467c-bfe8-6b6883adbc7d"},{"view":"TextLens","columns":["fine_label_prediction_str"],"name":"view","key":"f72a8ae9-17c4-4097-b454-79a6f60865db"},{"view":"ScalarView","columns":["fine_label_prediction_error"],"name":"view","key":"be4d6afe-9093-4581-b363-df11d3c6d34a"}],"visibleColumns":4}}]}]}