From the error message, it seems to me that you tensor (image) got destroyed after returning to the main function, the reason is that when doing copy, the address is unknown. I am not 100% percent sure, please double check. And, please provide an example if possible, I can further look into it.