当我导入tensorflow.contrib.slim
时遇到了这个问题import tensorflow.contrib.slim as slim
回溯是:
Traceback (most recent call last):
File "finetune-sintel.py", line 22, in <module>
from model_pwcnet import ModelPWCNet, _DEFAULT_PWCNET_FINETUNE_OPTIONS
File "/home/sxl/ext4-2T-3/code/tfoptflow-master/tfoptflow/model_pwcnet.py", line 21, in <module>
from model_base import ModelBase
File "/home/sxl/ext4-2T-3/code/tfoptflow-master/tfoptflow/model_base.py", line 15, in <module>
import tensorflow.contrib.slim as slim
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/contrib/__init__.py", line 22, in <module>
from tensorflow.contrib import bayesflow
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/contrib/bayesflow/__init__.py", line 24, in <module>
from tensorflow.contrib.bayesflow.python.ops import entropy
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/contrib/bayesflow/python/ops/entropy.py", line 23, in <module>
from tensorflow.contrib.bayesflow.python.ops.entropy_impl import *
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/contrib/bayesflow/python/ops/entropy_impl.py", line 30, in <module>
from tensorflow.contrib.bayesflow.python.ops import variational_inference
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/contrib/bayesflow/python/ops/variational_inference.py", line 26, in <module>
from tensorflow.contrib.bayesflow.python.ops.variational_inference_impl import *
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/contrib/bayesflow/python/ops/variational_inference_impl.py", line 29, in <module>
from tensorflow.contrib.bayesflow.python.ops import stochastic_graph_impl as sg
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/contrib/bayesflow/python/ops/stochastic_graph_impl.py", line 28, in <module>
from tensorflow.contrib.bayesflow.python.ops import stochastic_tensor_impl
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/contrib/bayesflow/python/ops/stochastic_tensor_impl.py", line 51, in <module>
from tensorflow.contrib.distributions.python.ops import distribution
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/contrib/distributions/__init__.py", line 91, in <module>
from tensorflow.contrib.distributions.python.ops.bernoulli import *
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/contrib/distributions/python/ops/bernoulli.py", line 21, in <module>
from tensorflow.contrib.distributions.python.ops import distribution
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/contrib/distributions/python/ops/distribution.py", line 29, in <module>
from tensorflow.contrib import framework as contrib_framework
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/contrib/framework/__init__.py", line 81, in <module>
from tensorflow.contrib.framework.python.ops import *
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/__init__.py", line 26, in <module>
from tensorflow.contrib.framework.python.ops.variables import *
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/variables.py", line 26, in <module>
from tensorflow.contrib.framework.python.ops import gen_variable_ops
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/gen_variable_ops.py", line 40, in <module>
_ops.RegisterShape("ZeroInitializer")(None)
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1697, in __call__
self._op_type)
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/site-packages/tensorflow/python/framework/registry.py", line 67, in register
stack = traceback.extract_stack()
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/traceback.py", line 211, in extract_stack
stack = StackSummary.extract(walk_stack(f), limit=limit)
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/traceback.py", line 364, in extract
f.line
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/traceback.py", line 286, in line
self._line = linecache.getline(self.filename, self.lineno).strip()
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/linecache.py", line 16, in getline
lines = getlines(filename, module_globals)
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/linecache.py", line 47, in getlines
return updatecache(filename, module_globals)
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/linecache.py", line 137, in updatecache
lines = fp.readlines()
File "/home/sxl/anaconda3/envs/tfpy36/lib/python3.6/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 4307: invalid continuation byte
答案 0 :(得分:0)
为Tensorflow 1
和Tensorflow 2
提供解决方案。
将Tensorflow 1
的较旧版本升级到1.14
和1.15-rc0
之类的稳定版本将解决您的问题。
Tensorflow 1:
要安装:
pip install tensorflow==1.15
导入:
import tensorflow.contrib.slim as slim
Tensorflow 2:
由于在Tensorflow 2中,slim
已移至其他存储库,因此您需要单独安装并导入,如下所示。
要安装:
pip install --upgrade tf_slim
导入:
import tf_slim as slim