Skip to content

Commit

Permalink
refactor: Update ConchModel and Phikon to use logging
Browse files Browse the repository at this point in the history
The ConchModel and Phikon classes in the conch.py and phikon.py files respectively have been updated to use log for indicating that weights are not used for these models.
  • Loading branch information
loic-lb committed Aug 12, 2024
1 parent 2897280 commit 8a84531
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/prismtoolbox/wsiemb/models/conch_model/conch.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import json
import torch
import torch.nn as nn
Expand All @@ -6,6 +7,7 @@
from huggingface_hub import hf_hub_download
from .coca_model import CoCa, resize_pos_embed

log = logging.getLogger(__name__)
CFG_FILE = Path(__file__).parent / "config.json"


Expand Down Expand Up @@ -37,6 +39,8 @@ def forward(self, x):


def create_conch_embedder(weights=None):
if weights is not None:
log.warning("Weights are not used in this model, they will be ignored.")
checkpoint_path = "hf_hub:MahmoodLab/conch"
with open(CFG_FILE, "r") as f:
model_cfg = json.load(f)
Expand Down
4 changes: 4 additions & 0 deletions src/prismtoolbox/wsiemb/models/phikon.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import logging
import torch.nn as nn
from functools import partial
from transformers import AutoImageProcessor, ViTModel

log = logging.getLogger(__name__)

class Phikon(nn.Module):
def __init__(self) -> None:
Expand All @@ -15,6 +17,8 @@ def forward(self, x):


def create_phikon_embedder(weights=None):
if weights is not None:
log.warning("Weights are not used in this model, they will be ignored.")
model = Phikon()
pretrained_transforms = partial(
AutoImageProcessor.from_pretrained("owkin/phikon"), return_tensors="pt"
Expand Down

0 comments on commit 8a84531

Please sign in to comment.