An interactive web-based tool for visualizing high-dimensional features (e.g., deep‐learning embeddings or softmax outputs) using 3D t-SNE.
Users can rotate, zoom, and click on individual points to view the corresponding original image.
This repository provides both a FastAPI backend (Python) that computes t-SNE and serves image files, and a minimal front-end (HTML + Three.js) for rendering the 3D scatter plot.
Python 3.8+fastapinumpyscikit-learnuvicorn
-
Clone this repository
git clone https://github.com/soribido/3D-TSNE-web-visualization.git cd 3D-TSNE-web-visualization -
Create & activate a virtual environment (recommended)
conda activate venv # (your environment) -
Prepare pickle file (Refer to Data Preparation)
python -c "import fastapi, numpy, sklearn; print('Dependencies OK!')" -
Run server
python main.py
-
Interact with the Visualization
-
On the 3D t-SNE plot in your browser:
-
Use the mouse wheel (scroll) to rotate and zoom the plot.
-
Click on any point to display its corresponding image in the bottom-left corner.
-
Before running the server, you must create a pickle file that contains:
features: AList[List[float]]of shape(N_samples, D_features)labels: AList[str]of lengthN_samples, one string label per featureimage_paths: AList[str]of lengthN_samples, each entry being an “absolute file path” to that sample’s image on your filesystem
You can use the provided save_data.py script as a template. For example:
# save_data.py
import os
import pickle
# 1) Specify the base folder containing your images
base_folder = "/home/user/dataset/images"
# 2) Collect all image filenames (e.g., .jpg/.png)
filenames = [
fname for fname in os.listdir(base_folder)
if fname.lower().endswith((".jpg", ".jpeg", ".png", ".bmp", ".tif", ".tiff"))
]
# 3) Example: Dummy features & labels
# In practice, you should replace this with your actual feature-extraction pipeline.
features = [
[0.1, 0.9, 0.0], # Example 3-dim softmax output or embedding
[0.3, 0.1, 0.6],
# …
]
labels = [
"cat",
"dog",
# …
]
# 4) Build absolute paths (must correspond 1:1 with `features` and `labels`)
assert len(features) == len(labels) == len(filenames), "All three lists must have equal length."
image_paths = [
os.path.abspath(os.path.join(base_folder, fname))
for fname in filenames
]
# 5) Dump to pickle
data = {
"features": features,
"labels": labels,
"image_paths": image_paths
}
with open("saved_features_with_abs_paths.pickle", "wb") as f:
pickle.dump(data, f)
print("Pickle saved to: saved_features_with_abs_paths.pickle")- Rename or move
saved_features_with_abs_paths.pickleinto the root of this project. - Confirm that Python can read each absolute path and load the image file (e.g.,
os.path.isfile(path)returnsTrue).
