Streamlit : TypeError: a bytes-like object is required, not 'Tensor'
I am working on a style transfer task, my model returns a tensor. recently I was saving that image using torchvision.utils
torchvision.utils.save_image(genarated_image, result_path)

now I have passed the same image to streamlit.
def image_input():
content_file = st.sidebar.file_uploader(&quot;Choose a Content Image&quot;, type=[&quot;png&quot;, &quot;jpg&quot;, &quot;jpeg&quot;])
if content_file is not None:
    content = Image.open(content_file)
    content = np.array(content)  # pil to cv
    content = cv2.cvtColor(content, cv2.COLOR_RGB2BGR)
else:
    st.warning(&quot;Upload an Image OR Untick the Upload Button)&quot;)
    st.stop()

WIDTH = st.sidebar.select_slider('QUALITY (May reduce the speed)', list(range(150, 501, 50)), value=200)
content = imutils.resize(content, width=WIDTH)
generated = genarate_image(content)
st.sidebar.image(content, width=300, channels='BGR')
st.image(generated, channels='BGR', clamp=True)

But now streamlit giving me this error.

TypeError: a bytes-like object is required, not 'Tensor'

is there a way to convert tensor into a &quot;bytes-like object&quot; ?

It can be solved by transforming tonsor to PIL Image.
from torchvision import transforms

def trans_tensor_to_pil(tensor_img):
pil_image = transforms.ToPILImage()(tensor_img.squeeze_(0))
return pil_image

