Regressing eyes to floats: RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 'other'

Hi,

I think this error is from the metrics part.
Error_rate call accuracy which is =

def accuracy(input:Tensor, targs:Tensor)->Rank0Tensor:
    "Compute accuracy with `targs` when `input` is bs * n_classes."
    n = targs.shape[0]
    input = input.argmax(dim=-1).view(n,-1)
    targs = targs.view(n,-1)
    return (input==targs).float().mean() 

try to create your own accuracy function:

def my_accuracy(input:Tensor, targs:Tensor)->Rank0Tensor:
    "Compute accuracy with `targs` when `input` is bs * n_classes."
    n = targs.shape[0]
    input = input.argmax(dim=-1).view(n,-1)
    targs = targs.view(n,-1)
    return (input==targs).float().mean()#Error from here. Try to correct the conversion for your case

def my_error_rate(input:Tensor, targs:Tensor)->Rank0Tensor:
    "1 - `accuracy`"
    return 1 - my_accuracy(input, targs)

learn = create_cnn(data, models.resnet50,metrics=my_error_rate)

You can check this:

1 Like