Then Tensor does have  a .detach() 81 method. Make sure you call it on a Tensor.
Also you use both img and seg_pred in your code. Make sure to do the .detach().cpu().numpy() (the .clone() is not necessary in this case I think, if you get an error from numpy saying that you try to modify a read-only array, then add it back) to each of them if you need a numpy array from them.