中的图像文件保存问题从google colaboratory到google drive。文件下载的解决方案是可用的,但从谷歌colab在驱动器中保存文件看不到太多。
我正在处理图像文件,并希望将处理后的图像保存在谷歌驱动器中,而不是下载到谷歌驱动器中。PTL库的解决方案命令img.save("/content/drive/MyDrive/aa/xyz.jpeg")
就像魔术一样工作。在整个代码片段下面。
from PIL import Image
import os
from pathlib import Path
path = r"/content/drive/MyDrive/aa/train"
os.chdir(path)
file_path = f"/content/drive/MyDrive/aa/train/xyz.jpeg" # Image file path
## image cropping and saving
img = Image.open(file_path)
img = img.resize((250,250), Image.ANTIALIAS)
img.save("/content/drive/MyDrive/aa/xyz.jpeg") # Image saving to another directory
所以你可以很容易地从谷歌驱动器读取图像,并从谷歌colab将图像保存到谷歌驱动器。