Windows下Tensorflow-slim库使用遇到ImportError: No module named 'nets'问题的解决方法

为了使用预训练的TF-slim模型,下载了github上的TensorFlow/models库,随后运行models\research\slim\nets下的inception_resnet_v2_test.py进行测试,提示ImportError: No module named 'nets'

进行搜索后发现一条相关的issue:ImportError: No module named nets,其中提到如下解决方法:

一是添加环境变量PYTHONPATH,值为slim目录:

Windows下Tensorflow-slim库使用遇到ImportError: No module named 'nets'问题的解决方法_第1张图片

然而该方法只能用于linux系统,Windows下不适用,即使添加环境变量也没起到效果,于是采用下列方法解决问题。

二是运行setup.py文件,将slim中所有的模块加载。

运行命令:

python setup.py build
python setup.py install

提示:

 

error: could not create 'build': 当文件已存在时,无法创建该文件。

原因是git clone下来的代码库中有个BUILD文件,而build和install指令需要新建build文件夹,名字冲突导致问题。暂时不清楚BUILD文件的作用。将该文件移动到其他目录,再运行上述指令,即可成功安装。随后重新运行inception_resnet_v2_test.py文件,结果如下:

 

PS E:\models\research\slim> python .\nets\inception_v2_test.py
C:\Program Files\Python35\lib\site-packages\tensorflow\python\framework\tensor_util.py:539: DeprecationWarning: The binary mode of fromstring is deprecated, as it behaves surprisingly on unicode inputs. Use frombuffer instead
  return np.fromstring(tensor.tensor_content, dtype=dtype).reshape(shape)
..C:\Program Files\Python35\lib\site-packages\tensorflow\python\util\tf_inspect.py:45: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead
  if d.decorator_argspec is not None), _inspect.getargspec(target))
........2018-02-06 17:00:48.190048: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2018-02-06 17:00:49.245086: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1105] Found device 0 with properties:
name: GeForce MX150 major: 6 minor: 1 memoryClockRate(GHz): 1.5315
pciBusID: 0000:01:00.0
totalMemory: 2.00GiB freeMemory: 1.62GiB
2018-02-06 17:00:49.253825: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1195] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce MX150, pci bus id: 0000:01:00.0, compute capability: 6.1)
.\nets\inception_v2_test.py:323: DeprecationWarning: Please use assertEqual instead.
  self.assertEquals(output.shape, (batch_size,))
.2018-02-06 17:00:55.403886: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1195] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce MX150, pci bus id: 0000:01:00.0, compute capability: 6.1)
WARNING:tensorflow:From C:\Program Files\Python35\lib\site-packages\slim-0.1-py3.5.egg\nets\inception_v2.py:519: calling reduce_mean (from tensorflow.python.ops.math_ops) with keep_dims is deprecated and will be removed in a future version.
Instructions for updating:
keep_dims is deprecated, use keepdims instead
..2018-02-06 17:01:01.405810: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1195] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce MX150, pci bus id: 0000:01:00.0, compute capability: 6.1)
...2018-02-06 17:01:06.996933: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1195] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce MX150, pci bus id: 0000:01:00.0, compute capability: 6.1)
.2018-02-06 17:01:09.490864: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1195] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce MX150, pci bus id: 0000:01:00.0, compute capability: 6.1)
.2018-02-06 17:01:10.330319: I C:\tf_jenkins\workspace\rel-win\M\windows-gpu\PY\35\tensorflow\core\common_runtime\gpu\gpu_device.cc:1195] Creating TensorFlow device (/device:GPU:0) -> (device: 0, name: GeForce MX150, pci bus id: 0000:01:00.0, compute capability: 6.1)
..
----------------------------------------------------------------------
Ran 20 tests in 51.844s

OK

参考链接:https://stackoverflow.com/questions/45036496/tensorflow-object-detection-importerror-no-module-named-nets

 

你可能感兴趣的:(Windows下Tensorflow-slim库使用遇到ImportError: No module named 'nets'问题的解决方法)