1、IndexError: invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number
torch版本的不同造成的。
解决:将loss.data[0] 改成loss.item()
2、AttributeError: 'module' object has no attribute 'Cmd'
完整报错:
Using TensorFlow backend.
Traceback (most recent call last):
File "../create_pairs_dataset.py", line 3, in <module>
import pose_transform
File "/home/hyw/zp/keras/pose-gan-master/pose_transform.py", line 18, in <module>
from tensorflow.contrib.image import transform as tf_affine_transform
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/tensorflow/contrib/__init__.py", line 37, in <module>
from tensorflow.contrib import cudnn_rnn
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/tensorflow/contrib/cudnn_rnn/__init__.py", line 38, in <module>
from tensorflow.contrib.cudnn_rnn.python.layers import *
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/tensorflow/contrib/cudnn_rnn/python/layers/__init__.py", line 23, in <module>
from tensorflow.contrib.cudnn_rnn.python.layers.cudnn_rnn import *
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/tensorflow/contrib/cudnn_rnn/python/layers/cudnn_rnn.py", line 20, in <module>
from tensorflow.contrib.cudnn_rnn.python.ops import cudnn_rnn_ops
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/tensorflow/contrib/cudnn_rnn/python/ops/cudnn_rnn_ops.py", line 22, in <module>
from tensorflow.contrib.rnn.python.ops import lstm_ops
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/tensorflow/contrib/rnn/__init__.py", line 93, in <module>
from tensorflow.contrib.rnn.python.ops.rnn_cell import *
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/tensorflow/contrib/rnn/python/ops/rnn_cell.py", line 24, in <module>
from tensorflow.contrib.layers.python.layers import layers
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/tensorflow/contrib/layers/__init__.py", line 116, in <module>
from tensorflow.contrib.layers.python.layers import *
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/__init__.py", line 33, in <module>
from tensorflow.contrib.layers.python.layers.target_column import *
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/tensorflow/contrib/layers/python/layers/target_column.py", line 24, in <module>
from tensorflow.contrib.losses.python.losses import loss_ops
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/tensorflow/contrib/losses/__init__.py", line 25, in <module>
from tensorflow.contrib.losses.python import metric_learning
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/tensorflow/contrib/losses/python/metric_learning/__init__.py", line 25, in <module>
from tensorflow.contrib.losses.python.metric_learning.metric_loss_ops import *
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/tensorflow/contrib/losses/python/metric_learning/metric_loss_ops.py", line 34, in <module>
from sklearn import metrics
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/sklearn/metrics/__init__.py", line 7, in <module>
from .ranking import auc
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/sklearn/metrics/ranking.py", line 36, in <module>
from ..preprocessing import label_binarize
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/sklearn/preprocessing/__init__.py", line 6, in <module>
from ._function_transformer import FunctionTransformer
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/sklearn/preprocessing/_function_transformer.py", line 5, in <module>
from ..utils.testing import assert_allclose_dense_sparse
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/sklearn/utils/testing.py", line 751, in <module>
import pytest
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/pytest.py", line 13, in <module>
from _pytest.debugging import pytestPDB as __pytestPDB
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/site-packages/_pytest/debugging.py", line 6, in <module>
import pdb
File "/home/hyw/zp/Anaconda2_pytorch_keras/lib/python2.7/pdb.py", line 59, in <module>
class Pdb(bdb.Bdb, cmd.Cmd):
AttributeError: 'module' object has no attribute 'Cmd'
报错原因分析: cmd.py是python的一个模块,而在我的代码树目录同样自定义了一个同名的模块cmd.py,该自定义的模块中无Cmd属性,python调用自身的cmd.py导致报错
解决办法:将自定义的cmd.py重命名为 cmdd.py,同时删除同目录下产生的 cmd.pyc文件,重新运行代码,问题解决
参考: The kernel has died, and the automatic restart has failed
3、ImportError: No module named keras_contrib.layers.normalization
报错原因: Keras未安装 keras_contrib 包
解决办法: 安装即可: github安装链接 或者用这个链接:keras实现Bi-LSTM+CRF
使用该方式导入:from keras_contrib.layers.normalization.instancenormalization import InstanceNormalization
参考:ImportError: No module named 'keras_contrib'
4、ValueError: Tensor._shape cannot be assigned, use Tensor.set_shape instead.
解决办法:将 o._shape = tf.TensorShape(new_shape) 换为 : o.set_shape = tf.TensorShape(new_shape)
参考: https://github.com/bioinf-jku/TTUR/issues/6
5、ValueError: Shape must be rank 2 but is rank 1 for 'MatMul' (op: 'MatMul') with input shapes: [2048], [2048,1008].
解决办法:使用 : logits = tf.matmul(tf.squeeze(pool3, [1, 2]), w) 代替: logits = tf.matmul(tf.squeeze(pool3), w)
参考:ValueError: Shape must be rank 2 but is rank 1 for 'MatMul' (op: 'MatMul') with input shapes: [2048]
或者: Shape must be rank 2 but is rank 1 for 'MatMul'
6. opencv为4.1版本,img = cv2.imread(img_path),module cv2 has no imread member
分析: 其实代码是没有错误的,,可以直接运行的,就是cscode的插件检测不到模块而已, 主要原因是cv2模块下还有cv2模块,简单的让vscode不报错的方法是在添加包的时候添加
解决办法: from cv2 import cv2
参考:解决vscode报错: Module 'cv2' has no 'imshow' member
7、 img = cv2.imread(img_path) h, w, c = img.shape
Error: h, w, c = img.shape
AttributeError: 'NoneType' object has no attribute 'shape'
分析 :经过检查发现是图像路径中图像不存在
解决办法: 把图像路径填写正确就 OK了
参考: python图像处理问题AttributeError: 'NoneType' object has no attribute 'shape'
8、Ubuntu18.04的系统,使用nvidia-smi就出来详细显卡信息了,但是过了段时间,再使用指令就出现这样的提示:NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.
问题分析:
NVIDIA驱动是在低版本的时候安装,由于系统更新,内核版本升级导致NVIDIA无法应用在高内核版本,所以,说明是内核版本的问题,选择低版本的内核即可。
参考:https://blog.csdn.net/sinat_23619409/article/details/85220561