Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use your own model #221

Open
Nazim0001 opened this issue Mar 17, 2024 · 8 comments
Open

Use your own model #221

Nazim0001 opened this issue Mar 17, 2024 · 8 comments

Comments

@Nazim0001
Copy link

Hi,
I would like to use my own model with WSInfer. But I don't know how I need to do, and what kind of information I need to add in JSON file?
Could you please help me?
Best
Nazim

@kaczmarj
Copy link
Member

hi @Nazim0001 - you can use one of the JSON files in the model zoo as a starting point, and replace things specific to your model. i have pasted the JSON for the pancancer lymphocyte classification model.

please note that the architecture key is unused but because i included it in the json schema, you need to include it. the value isn't used, so fill that in with anything you want.

you can validate your JSON against our schema using the following command:

wsinfer-zoo validate-config config.json

once you have the JSON file, you will also need to have your model in torchscript format. when you have your model and the config JSON, run the model using the following command:

wsinfer run --wsi-dir slides/ --results-dir results/ --model-path path/to/torchscript.pt --config config.json

here is an example config JSON:

{
  "spec_version": "1.0",
  "architecture": "inception_v4nobn",
  "num_classes": 2,
  "class_names": [
    "Other",
    "Lymphocytes"
  ],
  "patch_size_pixels": 100,
  "spacing_um_px": 0.5,
  "transform": [
    {
      "name": "Resize",
      "arguments": {
        "size": 299
      }
    },
    {
      "name": "ToTensor"
    },
    {
      "name": "Normalize",
      "arguments": {
        "mean": [
          0.5,
          0.5,
          0.5
        ],
        "std": [
          0.5,
          0.5,
          0.5
        ]
      }
    }
  ]
}

@Nazim0001
Copy link
Author

Nazim0001 commented Mar 17, 2024 via email

@kaczmarj
Copy link
Member

kaczmarj commented Mar 17, 2024 via email

@Nazim0001
Copy link
Author

Nazim0001 commented Mar 17, 2024 via email

@kaczmarj
Copy link
Member

if you have a patch classification model that can do this, then yes, you could use wsinfer to run that on slides. the wsinfer model zoo does not include any models that count cells, so you would have to provide your own model.

but counting cells is not usually a patch classification task. you might want to consider other methods.

@ajr82
Copy link

ajr82 commented Apr 11, 2024

Hi Jakub @kaczmarj
I have used Wsinfer (built-in models) on QuPath and it is great. We would like to train and use custom models.

Would pytorch models trained using Yolov8 be compatible with Wsinfer? These models have a .pt format. They can also be converted into Torchscript models. https://docs.ultralytics.com/modes/export/#arguments

@kaczmarj
Copy link
Member

hi @ajr82 - if the models do multi-class classification or multi-label classification, then yes, they would be compatible. the YOLOv8 classification models might work after being converted to torchscript. wsinfer expects that the forward pass outputs a tensor of logits per patch.

from my experience with yolo models, some might also return a bounding boxes or segmentations. in that case, the wsinfer code would have to be modified.

do you only need classification? or are you trying to perform other tasks too?

@ajr82
Copy link

ajr82 commented Apr 11, 2024

Thank you for getting back!
Yes, Yolo models either return segmentations or bounding boxes. We were hoping to use these models to annotate specific structures in renal biopsies (like glomeruli, tubules) and eventually do morphometric analyzes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants