Python如何将图像保存到本地PC?

pasnefire1972

New member
嗨,能否请您告诉我如何将处理后的图像保存到本地PC硬盘?我正在使用Google Colab中的Python。而且我的代码可运行,可以转换图片。它以以下方式结束:output = run_style_transfer(cnn,cnn_normalization_mean,cnn_normalization_std,content_img,style_img,input_img)plt.figure()imshow(output,title='Output Image')plt.ioff()plt.show()
 

ulcunypon1976

New member
你已经接近成功了,这里是一个可行的例子:from google.colab import files#save any file on the colab workspaceplt.savefig("abc.png")#then download the saved file to your local systemfiles.download("abc.png")check out this example (but it's with a text file):Google Colaboratorycolab.research.google.com
 

onozsigeart1981

New member
从google.colab导入文件#保存任何文件到colab工作区plt.savefig(“abc.png”)#然后将保存的文件下载到本地文件系统文件。download(“abc.png”)查看此示例(但它是一个文本文件):遗憾的是,这并不起作用它说NameError:名称'文件'未定义
 
clone_img = output.clone()from torchvision.utils import save_image,clone_img.shapeimg1 = clone_img[0] save_image(img1, '/root/out.png')files.download("/root/out.png")。
 
顶部