hms-dbmi / CHIEF

Clinical Histopathology Imaging Evaluation Foundation Model
GNU Affero General Public License v3.0
126 stars 17 forks source link

Wrong Weight Load Method for Patch-level model(CHIEF-Ctranspath) #15

Closed Fuzm7 closed 4 weeks ago

Fuzm7 commented 1 month ago

the method should be below

import torch, torchvision import torch.nn as nn from torchvision import transforms from PIL import Image from models.ctran import ctranspath

mean = (0.485, 0.456, 0.406) std = (0.229, 0.224, 0.225) trnsfrms_val = transforms.Compose( [ transforms.Resize(224), transforms.ToTensor(), transforms.Normalize(mean = mean, std = std) ] )

model = ctranspath() model.head = nn.Identity() model.patch_embed = ConvStem(img_size=224, patch_size=4, in_chans=3, embed_dim=96, norm_layer=nn.LayerNorm, flatten=True) td = torch.load(r'./model_weight/CHIEF_CTransPath.pth') model.load_state_dict(td['model'], strict=True) model.eval()

Xiyue-Wang commented 1 month ago

Hi,If you installed our slightly modified timm (https://drive.google.com/file/d/1JV7aj9rKqGedXY1TdDfi3dP07022hcgZ/view?usp=sharing), our code is fine, if, however, you didn't install it, your code is fine too!