MarkusStoll commited on
Commit
bc08e7a
0 Parent(s):

Duplicate from renumics/cifar10-outlier

Browse files
Files changed (8) hide show
  1. .gitattributes +34 -0
  2. .gitignore +2 -0
  3. Dockerfile +18 -0
  4. README.md +20 -0
  5. prepare.py +42 -0
  6. requirements.txt +2 -0
  7. run.py +37 -0
  8. 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.2.0rc2
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: Explore Outliers in CIFAR-10 with Spotlight
3
+ emoji: 📊
4
+ colorFrom: gray
5
+ colorTo: blue
6
+ sdk: docker
7
+ pinned: false
8
+ license: mit
9
+ app_file: run.py
10
+ datasets:
11
+ - renumics/cifar10-outlier
12
+ - cifar10
13
+ tags:
14
+ - renumics
15
+ - spotlight
16
+ - EDA
17
+ duplicated_from: renumics/cifar10-outlier
18
+ ---
19
+
20
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
prepare.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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/cifar10-outlier", split="train")
17
+ print("Dataset loaded using datasets.load_dataset().")
18
+
19
+ df = ds.rename_columns({"img": "image", "label": "labels"}).to_pandas()
20
+ df["label_str"] = df["labels"].apply(lambda x: ds.features["label"].int2str(x))
21
+
22
+ # df = df[:1000]
23
+
24
+ # precalculate umap embeddings
25
+ df["embedding_ft_precalc"] = umap.UMAP(
26
+ n_neighbors=70, min_dist=0.5, random_state=42
27
+ ).fit_transform(df["embedding_ft"].tolist()).tolist()
28
+ print("Umap for ft done")
29
+
30
+
31
+ df["embedding_foundation_precalc"] = umap.UMAP(
32
+ n_neighbors=70, min_dist=0.5, random_state=42
33
+ ).fit_transform(df["embedding_foundation"].tolist()).tolist()
34
+
35
+ print("Umap for base done")
36
+
37
+ # Save dataset to cache
38
+ with open(cache_file, "wb") as file:
39
+ pickle.dump(df, file)
40
+
41
+ print("Dataset saved to cache.")
42
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ renumics-spotlight
2
+ datasets
run.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+ from renumics import spotlight
3
+ import os
4
+
5
+ if __name__ == "__main__":
6
+ cache_file = "dataset_cache.pkl"
7
+ if os.path.exists(cache_file):
8
+ # Load dataset from cache
9
+ with open(cache_file, "rb") as file:
10
+ df = pickle.load(file)
11
+ print("Dataset loaded from cache.")
12
+
13
+
14
+ while True:
15
+ dtypes = {
16
+ "nn_image": spotlight.Image,
17
+ "image": spotlight.Image,
18
+ "embedding_ft": spotlight.Embedding,
19
+ "embedding_foundation": spotlight.Embedding,
20
+ "embedding_ft_precalc": spotlight.Embedding,
21
+ "embedding_foundation_precalc": spotlight.Embedding,
22
+ }
23
+ view = spotlight.show(
24
+ df,
25
+ dtype=dtypes,
26
+ layout="https://spotlight.renumics.com/resources/layout_pre_post_ft_hf.json",
27
+ port=7860,
28
+ host="0.0.0.0",
29
+ allow_filebrowsing=False
30
+ )
31
+
32
+ view.close()
33
+
34
+ else:
35
+ print(f"Dataset {cache_file} not found. Please run prepare.py first.")
36
+
37
+
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}}]}]}