问题描述
我的Jupyter Notebook具有以下代码,可将图像上传到Colab:
My Jupyter Notebook has the following code to upload an image to Colab:
from google.colab import files
uploaded = files.upload()
我被提示输入文件.哪个被上传.
I get prompted for the file. Which gets uploaded.
我使用以下方法验证文件上传是否成功:
I verify that the file upload was successful using:
!ls
我看到它在那里.
我使用以下命令检查当前工作目录:
I check the current working directory using:
import os
os.getcwd()
它告诉我它是/content
and it tells me that it is /content
现在,以下任何呼叫...
now, any of the following calls...
cv2.imread(img_path, 1)
cv2.imread(img_path, 0)
cv2.imread(img_path)
无法加载文件.
无论我使用的是文件名还是完整路径,它们也都会失败.
they also fail whether i'm using just the file name or the full path.
有什么想法吗?
推荐答案
使用此功能上传文件.也会保存它们.
Use this function to upload files. It will SAVE them as well.
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())
更新
现在(2018年9月),左窗格具有文件"选项卡,可让您轻松浏览文件和上传文件.您也可以通过双击文件名进行下载.
Update
Now (sep 2018), the left pane has a "Files" tab that let you browse files and upload files easily. You can also download by just double click the file names.
这篇关于在Google Colab中加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!