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

[BUG] Dictionary attribute error when using the new sf.mil.get_mil_tile_predictions function #348

Open
sz3029 opened this issue Jan 17, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@sz3029
Copy link

sz3029 commented Jan 17, 2024

Description

Thank you for the recent update of v2.3. I was trying to use the new function sf.mil.get_mil_tile_predictions() for CLAM model, but had encountered an error

To Reproduce

The code I used was:

...
clam_config = mil_config(
        model = 'clam_sb',
        trainer = 'fastai', # default, preferred
        lr=1e-4,
        epochs = 100,
        bag_size = 512,
        batch_size = 64,
        model_size = "small" # default to small
    )

sf.mil.get_mil_tile_predictions(
    weights=os.path.join(
            "/projects/slideflow_ML/CLAM", 
            "CLAM_D1_training",
            backbone_model,
            magnification,
            'mil',
            "00000-"+
            "_".join(
                ["CLAM_D1_training",
                magnification,
                backbone_model,
                normalization_type,
                ]
            ),
        ),
    outcomes="status",
    config=clam_config,
    dataset=dataset_test,
    bags=os.path.join(
            "/home/CLAM/TEST_HOLDOUT",
            magnification,
            "clamfeatures",
            backbone_model,
            normalization_type,
        ),
)

But it produced the following error:

File ~/.conda/envs/slideflow2-2/lib/python3.9/site-packages/slideflow/mil/eval.py:531, in get_mil_tile_predictions(weights, dataset, bags, config, outcomes, dest, uq)
    527 for i, (bag, slide) in track(enumerate(zip(bags, slides)),
    528                         description="Generating tile predictions",
    529                         total=len(bags)):
    530     if is_clam:
--> 531         pred_out = _predict_mil_tiles(model, bag, use_first_out=True, uq=uq)
    532     else:
    533         pred_out = _predict_mil_tiles(
    534             model,
    535             bag,
   (...)
    538             uq=uq
    539         )

File ~/.conda/envs/slideflow2-2/lib/python3.9/site-packages/slideflow/mil/eval.py:1130, in _predict_mil_tiles(model, bag, use_lens, device, apply_softmax, use_first_out, attention, attention_pooling, uq)
   1128     y_pred = y_pred.cpu().numpy()
   1129 if y_att is not None:
-> 1130     y_att = y_att.cpu().numpy()
   1131 if uncertainty is not None:
   1132     uncertainty = uncertainty.cpu().numpy()

AttributeError: 'dict' object has no attribute 'cpu'

It looks like the returned y_att is not a tensor object.

Expected behavior

Output: pandas dataframe of tile-level predictions

Environment (from the output of sf.about()):

  • Slideflow Version: 2.3.1
  • OS (e.g., Ubuntu): linux
  • How you installed Slideflow (pip, source): pip
  • Python version: 3.9.13
  • Backend: cucim, torch
  • CUDA version: 11.3
  • GPU models and configuration: Tesla V100-SXM2-32GB
@sz3029 sz3029 added the bug Something isn't working label Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant