Skip to content

Commit

Permalink
Merge branch 'main' of github.com:mackelab/labproject
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthijspals committed Feb 22, 2024
2 parents 9360695 + f75b982 commit b259cb3
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 1 deletion.
16 changes: 15 additions & 1 deletion labproject/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,26 @@ def __init__(self, image_model=None, device="cpu"):

def get_embeddings(self, dataloader):
embeddings = []
for batch in dataloader:
if isinstance(batch, (tuple, list)):
batch = batch[0]
if isinstance(batch, dict):
batch = batch["image"]
embeddings += [get_inception_v3_activations(self.embedding_net, batch.to(self.device))]
embeddings = torch.cat(embeddings, dim=0)
return embeddings

def get_embeddings_with_labels(self, dataloader):
embeddings = []
labels = []
for batch in dataloader:
embeddings += [
get_inception_v3_activations(self.embedding_net, batch[0].to(self.device))
]
labels += [batch[1]]
embeddings = torch.cat(embeddings, dim=0)
return embeddings
labels = torch.cat(labels, dim=0)
return embeddings, labels

# optional override of original methods

Expand Down
Loading

0 comments on commit b259cb3

Please sign in to comment.