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

shape error when generating heatmap using template #153

Closed
kaczmarj opened this issue Sep 29, 2022 · 1 comment
Closed

shape error when generating heatmap using template #153

kaczmarj opened this issue Sep 29, 2022 · 1 comment

Comments

@kaczmarj
Copy link

hi I am trying to generate the sample heatmap and I get a shape error. here is the command:

CUDA_VISIBLE_DEVICES=1 python create_heatmaps.py --config config_template.yaml

and here is the traceback

Traceback (most recent call last):
  File "/mnt/data08/shared/jkaczmarzyk/mtl/CLAM/create_heatmaps.py", line 371, in <module>
    compute_from_patches(wsi_object=wsi_object, clam_pred=Y_hats[0], model=model, feature_extractor=feature_extractor, batch_size=exp_args.batch_size, **wsi_kwargs, 
  File "/mnt/data08/shared/jkaczmarzyk/mtl/CLAM/vis_utils/heatmap_utils.py", line 77, in compute_from_patches
    A[score_idx] = score2percentile(A[score_idx], ref_scores)
ValueError: could not broadcast input array from shape (195,) into shape (1,)

I did not change the create_heatmaps.py script. how can i solve this issue?

All console output from the command:
exp_arguments
n_classes : 2
save_exp_code : HEATMAP_OUTPUT
raw_save_dir : heatmaps/heatmap_raw_results
production_save_dir : heatmaps/heatmap_production_results
batch_size : 384

data_arguments
data_dir : heatmaps/demo/slides/
data_dir_key : source
process_list : heatmap_demo_dataset.csv
preset : presets/bwh_biopsy.csv
slide_ext : .svs
label_dict : {'LUAD': 0, 'LSCC': 1}

patching_arguments
patch_size : 256
overlap : 0.5
patch_level : 0
custom_downsample : 1

model_arguments
ckpt_path : heatmaps/demo/ckpts/s_0_checkpoint.pt
model_type : clam_sb
initiate_fn : initiate_model
model_size : small
drop_out : True

heatmap_arguments
vis_level : 1
alpha : 0.4
blank_canvas : False
save_orig : True
save_ext : jpg
use_ref_scores : True
blur : False
use_center_shift : True
use_roi : False
calc_heatmap : True
binarize : False
binary_thresh : -1
custom_downsample : 1
cmap : jet

sample_arguments
samples : [{'name': 'topk_high_attention', 'sample': True, 'seed': 1, 'k': 15, 'mode': 'topk'}]
Continue? Y/N y
patch_size: 256 x 256, with 0.50 overlap, step size is 128 x 128

list of slides to process: 
       slide_id label  process status  seg_level  sthresh  ...  a_h  max_n_holes  vis_level line_thickness use_padding  contour_fn
0  C3L-03262-22  LUAD        1    tbp         -1       15  ...  1.0            2         -1             50        True     four_pt
1  C3L-01663-21  LSCC        1    tbp         -1       15  ...  1.0            2         -1             50        True     four_pt

[2 rows x 18 columns]

initializing model from checkpoint

ckpt path: heatmaps/demo/ckpts/s_0_checkpoint.pt
Init Model
CLAM_SB(
  (attention_net): Sequential(
    (0): Linear(in_features=1024, out_features=512, bias=True)
    (1): ReLU()
    (2): Dropout(p=0.25, inplace=False)
    (3): Attn_Net_Gated(
      (attention_a): Sequential(
        (0): Linear(in_features=512, out_features=256, bias=True)
        (1): Tanh()
        (2): Dropout(p=0.25, inplace=False)
      )
      (attention_b): Sequential(
        (0): Linear(in_features=512, out_features=256, bias=True)
        (1): Sigmoid()
        (2): Dropout(p=0.25, inplace=False)
      )
      (attention_c): Linear(in_features=256, out_features=1, bias=True)
    )
  )
  (classifiers): Linear(in_features=512, out_features=2, bias=True)
  (instance_classifiers): ModuleList(
    (0): Linear(in_features=512, out_features=2, bias=True)
    (1): Linear(in_features=512, out_features=2, bias=True)
  )
  (instance_loss_fn): CrossEntropyLoss()
)
Total number of parameters: 790791
Total number of trainable parameters: 790791
Done!

processing:  C3L-03262-22.svs
slide id:  C3L-03262-22
top left:  None  bot right:  None
seg_level: -1
sthresh: 15
mthresh: 11
close: 2
use_otsu: False
keep_ids: []
exclude_ids: []
a_t: 1
a_h: 1
max_n_holes: 2
vis_level: -1
line_thickness: 50
Initializing WSI object
Done!
Y_hat: LUAD, Y: LUAD, Y_prob: ['0.9962', '0.0038']
sampling topk_high_attention
coord: [5732 3396] score: 100.000
coord: [3172 3652] score: 99.487
coord: [4964 5444] score: 98.974
coord: [4964 3908] score: 98.462
coord: [3684 3396] score: 97.949
coord: [3172 3908] score: 97.436
coord: [5988 4932] score: 96.923
coord: [5988 4676] score: 96.410
coord: [5988 3396] score: 95.897
coord: [4964 5188] score: 95.385
coord: [6244 4676] score: 94.872
coord: [3172 4420] score: 94.359
coord: [5476 3396] score: 93.846
coord: [5732 4164] score: 93.333
coord: [4196 4164] score: 92.821

creating heatmap for: 
top_left:  (0, 0) bot_right:  (9959, 9023)
w: 2489, h: 2255
scaled patch size:  [64 64]

computing foreground tissue mask
detected 899730/5612695 of region as tissue

computing heatmap image
total of 195 patches
progress: 38/195
progress: 77/195
progress: 116/195
progress: 155/195
progress: 194/195
Done

computing blend
using block size: 1024 x 1024
processing 0/2 contours
Bounding Box: 5681 6038 1842 1077
Contour Area: 628940.0
Extracted 13 coordinates
processing 1/2 contours
Bounding Box: 2404 2884 4847 3951
Contour Area: 13722139.0
Extracted 760 coordinates
filtered a total of 773 coordinates
total number of patches to process:  773
number of batches:  3
/mnt/data08/shared/jkaczmarzyk/mtl/CLAM/utils/utils.py:37: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at  /opt/conda/conda-bld/pytorch_1659484808560/work/torch/csrc/utils/tensor_new.cpp:201.)
  label = torch.LongTensor([item[1] for item in batch])
/mnt/data08/shared/jkaczmarzyk/mtl/CLAM/utils/utils.py:37: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at  /opt/conda/conda-bld/pytorch_1659484808560/work/torch/csrc/utils/tensor_new.cpp:201.)
  label = torch.LongTensor([item[1] for item in batch])
/mnt/data08/shared/jkaczmarzyk/mtl/CLAM/utils/utils.py:37: UserWarning: Creating a tensor from a list of numpy.ndarrays is extremely slow. Please consider converting the list to a single numpy.ndarray with numpy.array() before converting to a tensor. (Triggered internally at  /opt/conda/conda-bld/pytorch_1659484808560/work/torch/csrc/utils/tensor_new.cpp:201.)
  label = torch.LongTensor([item[1] for item in batch])
Traceback (most recent call last):
  File "/mnt/data08/shared/jkaczmarzyk/mtl/CLAM/create_heatmaps.py", line 371, in <module>
    compute_from_patches(wsi_object=wsi_object, clam_pred=Y_hats[0], model=model, feature_extractor=feature_extractor, batch_size=exp_args.batch_size, **wsi_kwargs, 
  File "/mnt/data08/shared/jkaczmarzyk/mtl/CLAM/vis_utils/heatmap_utils.py", line 77, in compute_from_patches
    A[score_idx] = score2percentile(A[score_idx], ref_scores)
ValueError: could not broadcast input array from shape (195,) into shape (1,)
@kaczmarj
Copy link
Author

i got it working, but i do not know if my solution is valid. i squeezed the dimensions of both arrays in score2percentile

def score2percentile(score, ref):
    percentile = percentileofscore(ref.squeeze(), score.squeeze())
    return percentile

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

2 participants