遇见bug的尝试解决合集

1.Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA

https://stackoverflow.com/questions/41293077/how-to-compile-tensorflow-with-sse4-2-and-avx-instructions?rq=1

import os  
os.environ["TF_CPP_MIN_LOG_LEVEL"]='1' # 这是默认的显示等级,显示所有信息  
os.environ["TF_CPP_MIN_LOG_LEVEL"]='2' # 只显示 warning 和 Error   
os.environ["TF_CPP_MIN_LOG_LEVEL"]='3' # 只显示 Error  

tf默认是在GPU上开发的,CPU中存在的一些指令集如AVX不能为tf所用。

2.Device mapping: no known devices.

 https://stackoverflow.com/questions/42326748/tensorflow-on-gpu-no-known-devices-despite-cudas-devicequery-returning-a-pas

尝试重新安装gpu版本

3.读取词向量文件编码问题

在读取pku50维词向量文件时,使用with codecs.open('news_tensite.w2v200','r','utf-8') as f: 读取会出现:

UnicodeDecodeError: 'utf8' codec can't decode bytes in position 9-10: invalid continuation

with codecs.open('news_tensite.w2v200','r') as f:

import codecs
import numpy as np

with codecs.open('news_tensite.pku.words.w2v50','r','utf-8') as f:
    d={}
    for line in f:
        l=line.split()
        d[l[0]]=np.array(map(float,l[1:]))
    print len(d)
 file -i news_tensite.pku.words.w2v50
news_tensite.pku.words.w2v50: text/plain; charset=utf-8

//不明白。

另外出现了:UnicodeEncodeError: 'decimal' codec can't encode characters in position 0-2: invalid decimal Unicode string。

最终发现是因为https://stackoverflow.com/questions/30156931/unicodeencodeerror-decimal-codec-cant-encode-character-u-x00-in-position-8

设置判断条件: if len(l)==51: 即可。

原文地址:https://www.cnblogs.com/BlueBlueSea/p/11119608.html