【问题标题】:ImportError run python project from Google Drive in Google ColabImportError 在 Google Colab 中从 Google Drive 运行 python 项目
【发布时间】:2018-08-31 14:21:23
【问题描述】:

我使用 Google Colab 将我的 Google 云端硬盘(关注 https://medium.com/deep-learning-turkey/google-colab-free-gpu-tutorial-e113627b9f5d 的帖子)

!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}

!mkdir -p drive
!google-drive-ocamlfuse drive

然后我将Tensorflow nmt 放入drive/colab/ (drive 是google drive 根目录。

我在 Colab Cell 中运行命令

!python  drive/colab/nmt/nmt.py\
    --attention=scaled_luong \
    --src=src --tgt=tgt \
    --vocab_prefix=drive/colab/data/vi-vi/vocab  \
    --train_prefix=drive/colab/data/vi-vi/small_train \
    --dev_prefix=drive/colab/data/vi-vi/val  \
    --test_prefix=drive/colab/data/vi-vi/test \
    --out_dir=drive/colab/data/vi-vi/nmt_attention_model \
    --num_train_steps=12000 \
    --steps_per_stats=100 \
    --num_layers=2 \
    --num_units=128 \
    --dropout=0.2 \
    --metrics=bleu

有错误

/usr/local/lib/python3.6/dist-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Traceback (most recent call last):
  File "drive/colab/nmt/nmt.py", line 31, in <module>
    from . import inference
ImportError: cannot import name 'inference'

我该怎么办?

【问题讨论】:

    标签: tensorflow python-import google-colaboratory


    【解决方案1】:

    发生这种情况是因为您在 nmt.py 中使用了相对导入,并且您的当前目录与 nmt.py 所在的目录不同。并且由于那个python无法找到文件。您可以通过将目录更改为 mnt 来修复它

    %cd drive/colab/nmt/
    

    然后运行你的命令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-14
      • 2020-03-20
      • 2013-06-03
      • 2020-09-23
      • 2021-04-30
      • 2020-12-01
      • 1970-01-01
      相关资源
      最近更新 更多