6

尝试使用以下代码使用 Tensorflow Hub 导入一些模型:

import tensorflow as tf
import tensorflow_hub as hub

elmo_model = hub.Module('https://tfhub.dev/google/elmo/2', trainable=True)

让我的笔记本卡住了。在卡住之前出现的唯一日志行是:

INFO:tensorflow:使用 /tmp/tfhub_modules 缓存模块。

如何解开它并允许我从 Tensorflow Hub 导入模型?

4

1 回答 1

8

这只是关于特权:我无法访问 Tensorflow Hub 存储模型的默认目录(/tmp/tfhub_modules)。

为了解决这个问题,我只需选择一个目录来存储我可以访问的模型:

import os
import tensorflow as tf
import tensorflow_hub as hub

os.environ['TFHUB_CACHE_DIR'] = '/home/user/workspace/tf_cache'
elmo_model = hub.Module('https://tfhub.dev/google/elmo/2', trainable=True)
于 2018-10-23T02:14:02.170 回答