Fixed it using 	torch::Tensor det = torch::rand({ 1,512,512 });
instead of torch::Tensor det = torch::rand({ 512, 512 });
also added torch::NoGradGuard no_grad_guard;  line right after for extra measure.