Skip to content

invalid index of a 0-dim tensor #18

Description

@MartinHHF

When I am running the code, here is an error for the program.

exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 141, in
train(epoch)
File "", line 95, in train
error, _ = model.calculate_classification_error(data, bag_label)
File "/home/huafeng/AttentionDeepMIL-master/model.py", line 60, in calculate_classification_error
error = 1. - Y_hat.eq(Y).cpu().float().mean().data[0]
IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number

And I have tried to change .data[0] into .data or .item(), but neither worked, could anyone give me some suggestions?

Pytorch version:1.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions