Skip to content

Commit 4ebbcba

Browse files
committed
Fixing dependencies
1 parent 8e05c7d commit 4ebbcba

File tree

4 files changed

+223
-87
lines changed

4 files changed

+223
-87
lines changed

CellViT_Inference.ipynb

Lines changed: 76 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,36 @@
11
{
2-
"nbformat": 4,
3-
"nbformat_minor": 0,
4-
"metadata": {
5-
"colab": {
6-
"provenance": [],
7-
"gpuType": "T4",
8-
"authorship_tag": "ABX9TyNMQZ3sfZxtupkf49q2mk3U",
9-
"include_colab_link": true
10-
},
11-
"kernelspec": {
12-
"name": "python3",
13-
"display_name": "Python 3"
14-
},
15-
"language_info": {
16-
"name": "python"
17-
},
18-
"accelerator": "GPU"
19-
},
202
"cells": [
213
{
224
"cell_type": "markdown",
235
"metadata": {
24-
"id": "view-in-github",
25-
"colab_type": "text"
6+
"colab_type": "text",
7+
"id": "view-in-github"
268
},
279
"source": [
2810
"<a href=\"https://colab.research.google.com/github/TIO-IKIM/CellViT-Inference/blob/main/CellViT_Inference.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
2911
]
3012
},
3113
{
3214
"cell_type": "markdown",
15+
"metadata": {
16+
"id": "G0nASWl5KTeu"
17+
},
3318
"source": [
3419
"# CellViT Inference pipeline in Colab\n",
3520
"\n",
3621
"Here is an example ob how to install CellViT-Inference in Colab using some example slides. For runtime environment, please select a GPU runtime (e.g., T4 GPU)"
37-
],
38-
"metadata": {
39-
"id": "G0nASWl5KTeu"
40-
}
22+
]
4123
},
4224
{
4325
"cell_type": "markdown",
26+
"metadata": {
27+
"id": "aRbdZBJCKmO-"
28+
},
4429
"source": [
4530
"## Setup/Installation\n",
4631
"\n",
4732
"As PyTorch is already installed, we can skip the torch installation commands"
48-
],
49-
"metadata": {
50-
"id": "aRbdZBJCKmO-"
51-
}
33+
]
5234
},
5335
{
5436
"cell_type": "code",
@@ -65,48 +47,53 @@
6547
},
6648
{
6749
"cell_type": "code",
68-
"source": [
69-
"!cellvit-check"
70-
],
50+
"execution_count": null,
7151
"metadata": {
7252
"id": "XVW6LP-mEBdZ"
7353
},
74-
"execution_count": null,
75-
"outputs": []
54+
"outputs": [],
55+
"source": [
56+
"!cellvit-check"
57+
]
7658
},
7759
{
7860
"cell_type": "markdown",
61+
"metadata": {
62+
"id": "sA3IYs8MKB3B"
63+
},
7964
"source": [
8065
"# Example for Inference\n",
8166
"\n",
8267
"Be careful: The free instances just provide 2 CPU cores for your runtime. Thus,we need to set the hardware limits accordingly and overwrite them"
83-
],
84-
"metadata": {
85-
"id": "sA3IYs8MKB3B"
86-
}
68+
]
8769
},
8870
{
8971
"cell_type": "markdown",
90-
"source": [
91-
"First, download the test database"
92-
],
9372
"metadata": {
9473
"id": "xnwQkbeqM8C_"
95-
}
74+
},
75+
"source": [
76+
"First, download the test database"
77+
]
9678
},
9779
{
9880
"cell_type": "code",
99-
"source": [
100-
"!cellvit-download-examples"
101-
],
81+
"execution_count": null,
10282
"metadata": {
10383
"id": "x-6SuMndM-mv"
10484
},
105-
"execution_count": null,
106-
"outputs": []
85+
"outputs": [],
86+
"source": [
87+
"!cellvit-download-examples"
88+
]
10789
},
10890
{
10991
"cell_type": "code",
92+
"execution_count": null,
93+
"metadata": {
94+
"id": "t4zMTE99MVKd"
95+
},
96+
"outputs": [],
11097
"source": [
11198
"!cellvit-inference \\\n",
11299
" --model HIPT \\\n",
@@ -119,24 +106,24 @@
119106
" --wsi_path ./test_database/BRACS/BRACS_1640_N_3_cropped.tiff \\\n",
120107
" --wsi_mpp 0.25 \\\n",
121108
" --wsi_magnification 40"
122-
],
123-
"metadata": {
124-
"id": "t4zMTE99MVKd"
125-
},
126-
"execution_count": null,
127-
"outputs": []
109+
]
128110
},
129111
{
130112
"cell_type": "markdown",
131-
"source": [
132-
"This also works for larger WSI"
133-
],
134113
"metadata": {
135114
"id": "YqYEwTC-MVeA"
136-
}
115+
},
116+
"source": [
117+
"This also works for larger WSI"
118+
]
137119
},
138120
{
139121
"cell_type": "code",
122+
"execution_count": null,
123+
"metadata": {
124+
"id": "33_QyEyYFf9d"
125+
},
126+
"outputs": [],
140127
"source": [
141128
"!cellvit-inference \\\n",
142129
" --model HIPT \\\n",
@@ -146,30 +133,44 @@
146133
" --ray_remote_cpus 1 \\\n",
147134
" process_wsi \\\n",
148135
" --wsi_path ./test_database/x40_svs/JP2K-33003-2.svs"
149-
],
150-
"metadata": {
151-
"id": "33_QyEyYFf9d"
152-
},
153-
"execution_count": null,
154-
"outputs": []
136+
]
155137
},
156138
{
157139
"cell_type": "markdown",
158-
"source": [
159-
"The results can be found in the test_results folder"
160-
],
161140
"metadata": {
162141
"id": "0scuMhU_NmdC"
163-
}
142+
},
143+
"source": [
144+
"The results can be found in the test_results folder"
145+
]
146+
}
147+
],
148+
"metadata": {
149+
"accelerator": "GPU",
150+
"colab": {
151+
"authorship_tag": "ABX9TyNMQZ3sfZxtupkf49q2mk3U",
152+
"gpuType": "T4",
153+
"include_colab_link": true,
154+
"provenance": []
164155
},
165-
{
166-
"cell_type": "code",
167-
"source": [],
168-
"metadata": {
169-
"id": "0S6iMprONplW"
156+
"kernelspec": {
157+
"display_name": "cellvit-visualization",
158+
"language": "python",
159+
"name": "python3"
160+
},
161+
"language_info": {
162+
"codemirror_mode": {
163+
"name": "ipython",
164+
"version": 3
170165
},
171-
"execution_count": null,
172-
"outputs": []
166+
"file_extension": ".py",
167+
"mimetype": "text/x-python",
168+
"name": "python",
169+
"nbconvert_exporter": "python",
170+
"pygments_lexer": "ipython3",
171+
"version": "3.10.12"
173172
}
174-
]
175-
}
173+
},
174+
"nbformat": 4,
175+
"nbformat_minor": 0
176+
}

cellvit/inference/inference.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,12 +667,18 @@ def process_wsi(
667667
filter_patches (bool, optional): Filter patches after processing. Defaults to False.
668668
"""
669669
wsi_path = Path(wsi_path)
670-
self.logger.info(f"Processing WSI: {wsi_path.name}")
670+
if wsi_path.suffix == ".dcm":
671+
self.logger.info(f"Processing WSI: {wsi_path.parent.name}")
672+
else:
673+
self.logger.info(f"Processing WSI: {wsi_path.name}")
671674
self.logger.info(f"Preparing WSI - Loading tissue region and prepare patches")
672675

673676
# create output directory
674677
self.outdir.mkdir(exist_ok=True, parents=True)
675-
wsi_outdir = self.outdir / wsi_path.stem
678+
if wsi_path.suffix == ".dcm":
679+
wsi_outdir = self.outdir / wsi_path.parent.name
680+
else:
681+
wsi_outdir = self.outdir / wsi_path.parent.stem
676682
wsi_outdir.mkdir(exist_ok=True, parents=True)
677683

678684
# load metadata
@@ -899,7 +905,10 @@ def process_wsi(
899905
)
900906

901907
# saving/storing
902-
output_wsi_name = wsi_path.name.split(".")[0]
908+
if wsi_path.suffix == ".dcm":
909+
output_wsi_name = wsi_path.parent.name
910+
else:
911+
output_wsi_name = wsi_path.stem
903912
cell_dict_wsi = {
904913
"wsi_metadata": wsi.metadata,
905914
"type_map": self.label_map,
@@ -987,7 +996,11 @@ def process_wsi(
987996
if (self.outdir / "processed_files.json").exists():
988997
with open(self.outdir / "processed_files.json", "r") as infile:
989998
processed_files = ujson.load(infile)
990-
processed_files.append(wsi_path.name)
999+
1000+
if wsi_path.suffix == ".dcm":
1001+
processed_files.append(wsi_path.parent.name)
1002+
else:
1003+
processed_files.append(wsi_path.name)
9911004
processed_files = list(set(processed_files))
9921005
with open(self.outdir / "processed_files.json", "w") as outfile:
9931006
ujson.dump(processed_files, outfile)

0 commit comments

Comments
 (0)