答案 0 :(得分:7)
试试这个。
from io import BytesIO
uploaded = files.upload()
im = Image.open(BytesIO(uploaded['test.png']))
这是因为upload()命令不保存文件。它将内容存储在上传的字典中。
或者您可以使用此功能上传文件。它将上传并保存它们。
def upload_files():
from google.colab import files
uploaded = files.upload()
for k, v in uploaded.items():
open(k, 'wb').write(v)
return list(uploaded.keys())
答案 1 :(得分:2)
导入库:
from google.colab import files
from IPython.display import Image
上传文件:
uploaded = files.upload()
加载图像:
Image("foo.png", width=600)