MarkusStoll commited on
Commit
c6a85a5
0 Parent(s):

Duplicate from renumics/cifar10-cleanlab

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 +137 -0
  6. prepare.py +47 -0
  7. requirements.txt +2 -0
  8. run.py +51 -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.0rc3
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: Cleanlab 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/cifar10-cleanlab
18
+ ---
19
+
20
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
layout.json ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "orientation": "horizontal",
3
+ "children": [
4
+ {
5
+ "kind": "split",
6
+ "weight": 24.37657642133775,
7
+ "orientation": "vertical",
8
+ "children": [
9
+ {
10
+ "kind": "tab",
11
+ "weight": 23.652554002465973,
12
+ "children": [
13
+ {
14
+ "kind": "widget",
15
+ "name": "Table",
16
+ "type": "table",
17
+ "config": {
18
+ "tableView": "full",
19
+ "visibleColumns": [
20
+ "fine_label_prediction_str",
21
+ "fine_label_str",
22
+ "label_score",
23
+ "near_duplicate_score",
24
+ "outlier_score"
25
+ ],
26
+ "sorting": null,
27
+ "orderByRelevance": false
28
+ }
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ "kind": "tab",
34
+ "weight": 11.033364782611708,
35
+ "children": [
36
+ {
37
+ "kind": "widget",
38
+ "name": "Issues",
39
+ "type": "IssuesWidget",
40
+ "config": null
41
+ }
42
+ ]
43
+ },
44
+ {
45
+ "kind": "tab",
46
+ "weight": 38.67424218071708,
47
+ "children": [
48
+ {
49
+ "kind": "widget",
50
+ "name": "Inspector",
51
+ "type": "inspector",
52
+ "config": {
53
+ "views": [
54
+ {
55
+ "view": "ImageView",
56
+ "columns": [
57
+ "image"
58
+ ],
59
+ "name": "image",
60
+ "key": "iW3ihwygEHg4QZv5YzJ8ww"
61
+ },
62
+ {
63
+ "view": "TextLens",
64
+ "columns": [
65
+ "fine_label_str"
66
+ ],
67
+ "name": "view",
68
+ "key": "346d7554-5395-44d6-b358-a351901cb02e"
69
+ },
70
+ {
71
+ "view": "TextLens",
72
+ "columns": [
73
+ "fine_label_prediction_str"
74
+ ],
75
+ "name": "view",
76
+ "key": "99761cf8-350a-469d-8dbc-0df7b0db4d48"
77
+ },
78
+ {
79
+ "view": "ScalarView",
80
+ "columns": [
81
+ "label_score"
82
+ ],
83
+ "name": "view",
84
+ "key": "4ae33ae9-919a-4b10-9216-cd7c9448f9ac"
85
+ },
86
+ {
87
+ "view": "ScalarView",
88
+ "columns": [
89
+ "outlier_score"
90
+ ],
91
+ "name": "view",
92
+ "key": "13fb6430-3ffc-422c-92be-243b174b9a15"
93
+ },
94
+ {
95
+ "view": "ScalarView",
96
+ "columns": [
97
+ "near_duplicate_score"
98
+ ],
99
+ "name": "view",
100
+ "key": "daf7c0b7-2185-4e50-9eb0-ffab8d1ff906"
101
+ }
102
+ ],
103
+ "visibleColumns": 8
104
+ }
105
+ }
106
+ ]
107
+ }
108
+ ]
109
+ },
110
+ {
111
+ "kind": "tab",
112
+ "weight": 51.915353562320064,
113
+ "children": [
114
+ {
115
+ "kind": "widget",
116
+ "name": "Similarity Map",
117
+ "type": "similaritymap",
118
+ "config": {
119
+ "placeBy": [
120
+ "embedding_reduced"
121
+ ],
122
+ "reductionMethod": null,
123
+ "colorBy": "fine_label_str",
124
+ "sizeBy": "is_label_issue",
125
+ "filter": true,
126
+ "umapNNeighbors": 20,
127
+ "umapMetric": "cosine",
128
+ "umapMinDist": 0.15,
129
+ "pcaNormalization": null,
130
+ "umapMenuLocalGlobalBalance": 0.5,
131
+ "umapMenuIsAdvanced": false
132
+ }
133
+ }
134
+ ]
135
+ }
136
+ ]
137
+ }
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,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ label_issue_rows = df[df["is_label_issue"]].sort_values("label_score").index.tolist()
21
+ label_issue = DataIssue(severity="medium", title="label-issue", rows=label_issue_rows, description="Label issue found by cleanlab")
22
+
23
+ outlier_issue_row = df[df["outlier_score"]<0.6].sort_values("outlier_score").index.tolist()
24
+ outlier_issue = DataIssue(severity="medium", title="outlier-issue", rows=outlier_issue_row, description="Outlier score < 0.6")
25
+
26
+ near_duplicate_issue_row = df[df["is_near_duplicate_issue"]].sort_values("near_duplicate_score").index.tolist()
27
+ near_duplicate_issue = DataIssue(severity="medium", title="near-duplicate-issue", rows=near_duplicate_issue_row, description="Near duplicate issue found by cleanlab")
28
+
29
+ df = df.drop(["full_image"], axis=1)
30
+ while True:
31
+ dtypes = {
32
+ "image": spotlight.Image,
33
+ "embedding": spotlight.Embedding,
34
+ "embedding_reduced": spotlight.Embedding,
35
+ "probabilities": spotlight.Embedding,
36
+ }
37
+
38
+ view = spotlight.show(
39
+ df,
40
+ dtype=dtypes,
41
+ issues=[label_issue,outlier_issue,near_duplicate_issue],
42
+ layout="layout.json",
43
+ port=7860,
44
+ host="0.0.0.0",
45
+ allow_filebrowsing=False,
46
+ )
47
+
48
+ view.close()
49
+
50
+ else:
51
+ 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}}]}]}