From 6996bbd7847c42eddecaf7ca7d88492f8e7ca7e7 Mon Sep 17 00:00:00 2001 From: Alishba Imran Date: Thu, 17 Oct 2024 20:23:44 -0700 Subject: [PATCH] merging bugs fixed --- viscy/data/hcs.py | 11 ++++++++--- viscy/representation/contrastive.py | 3 +-- viscy/representation/evalutation/clustering.py | 6 +++--- .../evalutation/dimensionality_reduction.py | 1 + 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/viscy/data/hcs.py b/viscy/data/hcs.py index db518a3c..54837bb3 100644 --- a/viscy/data/hcs.py +++ b/viscy/data/hcs.py @@ -3,6 +3,7 @@ import os import re import tempfile +import warnings from pathlib import Path from typing import Callable, Literal, Sequence @@ -25,8 +26,12 @@ from torch.utils.data import DataLoader, Dataset from viscy.data.typing import ChannelMap, DictTransform, HCSStackIndex, NormMeta, Sample -import warnings -warnings.filterwarnings("ignore", category=UserWarning, message="To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).") + +warnings.filterwarnings( + "ignore", + category=UserWarning, + message="To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).", +) _logger = logging.getLogger("lightning.pytorch") @@ -551,7 +556,7 @@ def predict_dataloader(self): self.predict_dataset, batch_size=self.batch_size, num_workers=self.num_workers, - shuffle=False, + shuffle=False, ) def _fit_transform(self) -> tuple[Compose, Compose]: diff --git a/viscy/representation/contrastive.py b/viscy/representation/contrastive.py index dd89d4cf..dd4186fc 100644 --- a/viscy/representation/contrastive.py +++ b/viscy/representation/contrastive.py @@ -1,3 +1,4 @@ +import warnings from typing import Literal import timm @@ -5,7 +6,6 @@ from torch import Tensor from viscy.unet.networks.unext2 import StemDepthtoChannels -import warnings warnings.filterwarnings("ignore", category=UserWarning, module="torch") @@ -84,7 +84,6 @@ def __init__( ) # Append modified encoder. self.encoder = encoder - self.intermediate_projection = intermediate_projection # Append modified projection head. self.projection = projection diff --git a/viscy/representation/evalutation/clustering.py b/viscy/representation/evalutation/clustering.py index 051ac965..b7065339 100644 --- a/viscy/representation/evalutation/clustering.py +++ b/viscy/representation/evalutation/clustering.py @@ -1,14 +1,15 @@ """Methods for evaluating clustering performance.""" +import numpy as np from sklearn.cluster import DBSCAN from sklearn.metrics import ( accuracy_score, adjusted_rand_score, normalized_mutual_info_score, ) -from sklearn.neighbors import KNeighborsClassifier from sklearn.mixture import GaussianMixture -import numpy as np +from sklearn.neighbors import KNeighborsClassifier + class GMMClustering: def __init__(self, features_data, n_clusters_range=np.arange(2, 10)): @@ -78,7 +79,6 @@ def predict_clusters(self): return cluster_labels - def knn_accuracy(embeddings, annotations, k=5): """ Evaluate the k-NN classification accuracy. diff --git a/viscy/representation/evalutation/dimensionality_reduction.py b/viscy/representation/evalutation/dimensionality_reduction.py index 047ee3b0..130c8634 100644 --- a/viscy/representation/evalutation/dimensionality_reduction.py +++ b/viscy/representation/evalutation/dimensionality_reduction.py @@ -37,6 +37,7 @@ def compute_pca(embedding_dataset, n_components=None, normalize_features=False): return PCA_features, PCA_projection, pca_df + def _fit_transform_umap( embeddings: NDArray, n_components: int = 2, normalize: bool = True ) -> tuple[umap.UMAP, NDArray]: