I’m not Tom, but think you might be missing a permutation in the img_output. 
OpenCV uses the channels-last memory layout, while your tensor might be in channels-first, so you would need to permute the dimensions before writing it out as the image.