Skip to content

Commit de5817e

Browse files
committed
updated detection code, changed detectron2 classes to 2 in prediciton
1 parent 9841c05 commit de5817e

File tree

3 files changed

+291
-253
lines changed

3 files changed

+291
-253
lines changed

source/2_training.ipynb

Lines changed: 283 additions & 230 deletions
Large diffs are not rendered by default.

source/3_inference.ipynb

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,7 @@
128128
"execution_count": 5,
129129
"id": "4122d05f-8153-4dde-9abf-362b8311217b",
130130
"metadata": {},
131-
"outputs": [
132-
{
133-
"name": "stderr",
134-
"output_type": "stream",
135-
"text": [
136-
"Skip loading parameter 'roi_heads.box_predictor.cls_score.weight' to the model due to incompatible shapes: (3, 1024) in the checkpoint but (2, 1024) in the model! You might want to double check if this is expected.\n",
137-
"Skip loading parameter 'roi_heads.box_predictor.cls_score.bias' to the model due to incompatible shapes: (3,) in the checkpoint but (2,) in the model! You might want to double check if this is expected.\n",
138-
"Skip loading parameter 'roi_heads.box_predictor.bbox_pred.weight' to the model due to incompatible shapes: (8, 1024) in the checkpoint but (4, 1024) in the model! You might want to double check if this is expected.\n",
139-
"Skip loading parameter 'roi_heads.box_predictor.bbox_pred.bias' to the model due to incompatible shapes: (8,) in the checkpoint but (4,) in the model! You might want to double check if this is expected.\n",
140-
"Some model parameters or buffers are not found in the checkpoint:\n",
141-
"\u001b[34mroi_heads.box_predictor.bbox_pred.{bias, weight}\u001b[0m\n",
142-
"\u001b[34mroi_heads.box_predictor.cls_score.{bias, weight}\u001b[0m\n"
143-
]
144-
}
145-
],
131+
"outputs": [],
146132
"source": [
147133
"model = Detectron2DetectionPredictor(\n",
148134
" output_dir=output_path,\n",
@@ -227,7 +213,7 @@
227213
},
228214
{
229215
"cell_type": "code",
230-
"execution_count": 8,
216+
"execution_count": 9,
231217
"id": "c9f7e6e3-5bb5-4dd7-a9d4-7097700691de",
232218
"metadata": {
233219
"tags": []
@@ -272,7 +258,7 @@
272258
" ratio = spacing/spacing_min\n",
273259
" with WholeSlideImage(image_path) as wsi:\n",
274260
" spacing = wsi.get_real_spacing(spacing_min)\n",
275-
" print(f\"Spacing: {spacing}\\nSpacing const: {SPACING_CONST}\")\n",
261+
" print(f\"Spacing: {spacing} - Spacing const: {SPACING_CONST} - ratio: {ratio}\")\n",
276262
"\n",
277263
"\n",
278264
" for x_batch, y_batch, info in tqdm(iterator):\n",
@@ -393,7 +379,7 @@
393379
},
394380
{
395381
"cell_type": "code",
396-
"execution_count": 9,
382+
"execution_count": 10,
397383
"id": "7bf43390-c419-4b8a-9f5a-104cb8040592",
398384
"metadata": {},
399385
"outputs": [
@@ -402,8 +388,7 @@
402388
"output_type": "stream",
403389
"text": [
404390
"predicting...\n",
405-
"Spacing: 0.24199951445730394\n",
406-
"Spacing const: 0.24199951445730394\n"
391+
"Spacing: 0.24199951445730394 - Spacing const: 0.24199951445730394 - ratio: 2.0\n"
407392
]
408393
},
409394
{
@@ -421,14 +406,14 @@
421406
" max_size = (max_size + (stride - 1)) // stride * stride\n",
422407
"/venv/lib/python3.8/site-packages/torch/functional.py:445: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:2157.)\n",
423408
" return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]\n",
424-
"100%|██████████| 379/379 [00:44<00:00, 8.43it/s]\n"
409+
"100%|██████████| 379/379 [00:42<00:00, 8.95it/s]\n"
425410
]
426411
},
427412
{
428413
"name": "stdout",
429414
"output_type": "stream",
430415
"text": [
431-
"Predicted 30007 points\n",
416+
"Predicted 14925 points\n",
432417
"saving predictions...\n",
433418
"finished!\n"
434419
]

source/utils/wsdetectron2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(self, output_dir, threshold, nms_threshold, weight_root):
5656
cfg.DATALOADER.NUM_WORKERS = 1
5757

5858
cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 512
59-
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 1
59+
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 2 #was 1!
6060
cfg.MODEL.ANCHOR_GENERATOR.SIZES = [[16, 24, 32]]
6161

6262
cfg.SOLVER.IMS_PER_BATCH = 10

0 commit comments

Comments
 (0)