Comments (1)
Since we didn't use a KNN classifier, I believe you're referring to our K-means approach. Unfortunately, we don't have official code for this. However, it can be easily implemented in just a few lines. Let me provide the following code, which is nearly identical to our original approach. The only difference is that we ran it multiple times with different encoder checkpoints and seeds to achieve the best results during the competition period.
The result is as follows:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from train_tools.models import MEDIARFormer
from train_tools.data_utils.datasetter import get_dataloaders_labeled
# Load data and model
dataloaders = get_dataloaders_labeled("/home/gihun/MEDIAR", "./train_tools/data_utils/mapping_labeled.json", "./train_tools/data_utils/mapping_tuning.json")
model = MEDIARFormer().to("cuda:7").eval()
model.load_state_dict(torch.load("./weights/pretrained/phase1.pth", map_location="cpu"))
# Extract and process embeddings
embeddings_all = []
for batch in dataloaders["train"]:
with torch.no_grad():
embeddings = model.encoder(batch["img"].to("cuda:7"))[-1].mean(dim=[2, 3]).cpu()
embeddings_all.append(embeddings)
embeddings_all = torch.cat(embeddings_all, dim=0)
# Cluster embeddings
kmeans = KMeans(n_clusters=40, random_state=0).fit(embeddings_all.numpy())
labels, counts = np.unique(kmeans.labels_, return_counts=True)
sorted_indices = np.argsort(counts)[::-1]
# Plot histogram
plt.figure(figsize=(10, 6))
plt.bar(range(len(counts)), counts[sorted_indices], tick_label=labels[sorted_indices])
plt.xlabel('Cluster Label')
plt.ylabel('Count')
plt.title('KMeans Labels Histogram (Desc. Count)')
plt.show()```
from mediar.
Related Issues (19)
- Running on large jp2 WSI files HOT 6
- ERROR: Could not find a version that satisfies the requirement MEDIAR HOT 1
- KeyError: 'medair'
- RuntimeError: Found no NVIDIA driver on your system. HOT 1
- ModuleNotFoundError: No module named 'train_tools' HOT 2
- Running the predict.py code does not produce segmentation results. HOT 1
- requirements.txt has package version "0.0" for skimage HOT 1
- Please retain the Cellpose copyright as required by the BSD-3 license HOT 7
- Finetuing the "finetuned" model on custom dataset HOT 2
- current Mediar weights HOT 2
- Access to data used for inference HOT 1
- Train on custom dataset HOT 2
- Parameter name mismatches and other issues HOT 2
- Public dataset preprocessing and public data selection strategy for pretraining HOT 4
- What is "classes" parameter in config? HOT 2
- Poor Performance - is my input correctly formated?
- MEDIAR package HOT 1
- Fine-tuning issues HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mediar.