Error: 'function' object has no attribute 'up'
unnir opened this issue · 3 comments
Trying to use IGOS for CIFAR10 data set.
IGOS(network, sample.reshape(1,3,32,32).cuda().detach(), baseline.detach(), torch.Tensor([clss]), size = 32)
got this error message:
63 :return:
64 """
---> 65 return upscale.up(masks).expand((-1,1,upscale.out_size,upscale.out_size)) # TODO
66
67
AttributeError: 'function' object has no attribute 'up'
any idea how to fix that?
also, how can one understand this code?
indices[indices] = losses > base_losses[indices] + alphas[indices] * t[indices]
I have the same questions here, and I got an error for this line:
indices[indices] = losses > base_losses[indices] + alphas[indices] * t[indices]
Traceback (most recent call last):
File "D:\python\summerResearch\IGOS\IGOS_pp-master\main.py", line 168, in
gen_explanations(model, data_loader, args)
File "D:\python\summerResearch\IGOS\IGOS_pp-master\main.py", line 63, in gen_explanations
masks = method(
File "D:\python\summerResearch\IGOS\IGOS_pp-master\methods.py", line 369, in iGOS_p
alphas = line_search(masks, total_grads, loss_function, alpha)
File "D:\python\summerResearch\IGOS\IGOS_pp-master\methods_helper.py", line 179, in line_search
indices[indices] = losses > base_losses[indices] + alphas[indices] * t[indices]
RuntimeError: unsupported operation: some elements of the input tensor and the written-to tensor refer to a single memory location. Please clone() the tensor before performing the operation.
I changed it as follows without reading the details, it seems working.
But I'm not sure if it's the correct thing to do:
#mycode
temp_indices=indices.clone()
indices[temp_indices] = losses > base_losses[indices] + alphas[indices] * t[indices]
# indices[indices] = losses > base_losses[indices] + alphas[indices] * t[indices]
# Same for this, but for if the alpha values are too low (\alpha_l)
temp_indices = indices.clone()
indices[temp_indices] *= (alphas[indices] >= 0.00001)
# indices[indices] *= (alphas[indices] >= 0.00001)