Spaces:
Runtime error
Runtime error
Download src/pathoverse/classification/embedding_dataset.py from KondetiAravind/PathoVerse-AI: direct link, hf CLI and curl.
- Browser
- Download file 1.11 kB
-
https://huggingface.co/spaces/KondetiAravind/PathoVerse-AI/resolve/main/src/pathoverse/classification/embedding_dataset.py
- Command line
-
hf download hf://spaces/KondetiAravind/PathoVerse-AI/src/pathoverse/classification/embedding_dataset.py
-
curl -L -o embedding_dataset.py https://huggingface.co/spaces/KondetiAravind/PathoVerse-AI/resolve/main/src/pathoverse/classification/embedding_dataset.py
1.11 kB
| from __future__ import annotations | |
| from pathlib import Path | |
| import numpy as np | |
| class EmbeddingDataset: | |
| def __init__( | |
| self, | |
| embedding_path: str | Path, | |
| label_path: str | Path, | |
| ): | |
| self.embedding_path = Path( | |
| embedding_path | |
| ) | |
| self.label_path = Path( | |
| label_path | |
| ) | |
| if not self.embedding_path.exists(): | |
| raise FileNotFoundError( | |
| self.embedding_path | |
| ) | |
| if not self.label_path.exists(): | |
| raise FileNotFoundError( | |
| self.label_path | |
| ) | |
| self.embeddings = np.load( | |
| self.embedding_path | |
| ) | |
| self.labels = np.load( | |
| self.label_path | |
| ) | |
| if len(self.embeddings) != len( | |
| self.labels | |
| ): | |
| raise ValueError( | |
| "Embedding/label mismatch." | |
| ) | |
| def __len__(self): | |
| return len(self.labels) | |
| def __getitem__(self, index): | |
| return ( | |
| self.embeddings[index], | |
| self.labels[index], | |
| ) |