【问题标题】:Add Caffe to Datalab Instance将 Caffe 添加到 Datalab 实例
【发布时间】:2019-01-10 02:13:34
【问题描述】:

我正在尝试运行一个使用 Caffe 的 Jupyter 笔记本。 Caffe 不包含在 datalab 中。我正在尝试从 Jupyter 笔记本中安装该库(按照 datalab 文档中的建议),但遇到了问题。

我是datalab的新手,一般都是新手。任何建议将不胜感激。

datalab 文档建议 3 strategies 用于添加不是already included 的python 库。我专注于这些策略中的前两个。

我的数据云实例的平台是:

platform.platform() 'Linux-4.4.111+-x86_64-with-debian-stretch-sid'

下面我将列出我尝试过的各种方法以及我收到的错误消息。 对于第一个策略,我在同一个笔记本的一个单元格中尝试了这些东西。

(尝试 1)

!pip install caffe
#results in the error:
#Collecting caffe
#  Could not find a version that satisfies the requirement caffe (from 
#versions: )
#No matching distribution found for caffe

!pip install caffe-cpu
#results in the same error as above

我研究发现caffe不能用pip安装,所以我试了一下:

(尝试 2)

!apt-get install caffe
#results in the error:
#Reading package lists... Done
#Building dependency tree       
#Reading state information... Done
#E: Unable to locate package caffe

!apt-get install caffe-cpu
#results in the same error as above

基于另一个stackoverflow question,我为 caffe 和 caffe-cpu 尝试了以下操作:

(尝试 3)

%bash
echo 'Y' | apt-get update
echo 'Y' | apt-get install caffe-cpu
#This results in output with a lot of warnings, but ends with the error:
#E: Unable to locate package caffe-cpu
#Stack Overflow prevented me from posting the entire thing, thinking it was spam

(尝试 4)

根据文档中推荐的second strategy,我尝试在单独的笔记本中运行此代码:

%%bash
echo "pip install caffe" >> /content/datalab/.config/startup.sh
cat /content/datalab/.config/startup.sh
#This resulted in the error:
#bash: /usr/local/lib/libtinfo.so.5: no version information available (required by bash)

我跑的时候得到了同样的结果:

%%bash
echo "apt-get install caffe" >> /content/datalab/.config/startup.sh
cat /content/datalab/.config/startup.sh

【问题讨论】:

    标签: google-cloud-platform caffe google-cloud-datalab


    【解决方案1】:

    我尝试安装 caffe-cpu,但在 datalab 实例中,文件/etc/apt/sources.list 似乎没有安装它所需的存储库。为了解决这个问题,我在创建的笔记本中使用了以下命令:

    !echo "deb http://deb.debian.org/debian stretch main\n\
    deb-src http://deb.debian.org/debian stretch main\n\
    deb http://deb.debian.org/debian-security/ stretch/updates main\n\
    deb-src http://deb.debian.org/debian-security/ stretch/updates main\n\
    deb http://deb.debian.org/debian stretch-updates main\n\
    deb-src http://deb.debian.org/debian stretch-updates main" >> /etc/apt/sources.list
    

    这将添加包含 caffe-cpu 包的必要 debian/stretch 存储库。

    注意:奇怪的是,我不需要将-e 标志添加到echo 命令以正确读取换行符,您可以通过执行!cat /etc/apt/sources.list 检查文件是否已正确更新。

    完成后,运行以下命令:

    !apt-get update && apt-get install caffe-cpu -y --allow-unauthenticated
    

    命令完成后,caffe-cpu 包将安装在您的 VM 中。

    【讨论】:

    • 非常感谢,琼。 debian 拉伸和安全文件似乎已成功附加到 sources.list 文件。但是(我在 Python 2 和 3 笔记本中的新实例上对此进行了测试),我似乎遇到了同样的问题。我尝试使用... caffe = __import__("caffe-cpu") ...导入 caffe 以说明连字符,但仍然收到错误“No module named 'caffe-cpu'”。
    • 我认为问题在于 caffe 模块的位置不在 python 路径中。在导入之前尝试添加此行:sys.path.insert(0,'/usr/lib/python3/dist-packages')。最后,运行!python3 -c "import sys;sys.path.insert(0,'/usr/lib/python3/dist-packages');import caffe" 确实导入了模块。
    • 这确实可以开始导入,但是在加载时出现错误:
    • ImportError: /usr/lib/python3/dist-packages/numpy/random/mtrand.cpython-35m-x86_64-linux-gnu.so: undefined symbol: PyFPE_jbuf 在阅读有关此错误时,它解决这个问题似乎有点复杂。我不想这么说,琼,但我开始考虑这个项目的替代方法,根本不涉及 Caffe,所以请不要花费太多精力:)。但是,如果您清楚这里发生了什么,我很乐意尝试您的任何建议。再次感谢您的帮助。
    • 这是我发现的唯一可以帮助的东西,this documentation 使用自定义 Docker 映像来构建数据实验室实例。我无法在我这边测试它,但它可以工作。想法是修改Dockerfile.in 文件并添加行RUN apt updateRUN apt install caffe-cpu -y,然后按照文档中的说明运行其余命令。
    猜你喜欢
    • 1970-01-01
    • 2015-06-12
    • 2018-05-21
    • 1970-01-01
    • 2012-07-17
    • 2022-01-22
    • 2013-11-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多