总结下遇到的各种bug

遇见bug就很烦

    • 1.安装protobuf:
    • 2.python parse_args() 报错 xxx.py: error: the following arguments are required: xxx
    • 3.tf.logging.set_verbosity (tf.logging.INFO)
    • 4.VOC数据集
    • 5.安装.whl文件
    • 6.21个项目 chap7
    • 7.21个项目 chap8 main.py
    • 8.21个项目 chap8 main.py
    • 9.21个项目 chap8 main.py
    • 10.scipy.misc库函数问题
    • 11.tensorflow.python.framework.errors_impl.NotFoundError: Failed to create a NewWriteableFile: ./tfrecords
    • 12.run the eval_ssd_network.py
    • 13.TypeError: Can not convert a tuple into a Tensor or Operation.
    • 14.一般CUDA安装失败都是由于其中Visual Studio(VS) Intergration无法安装导致的:
    • 15.ModuleNotFoundError: No module named 'nets.yolo4'
    • 16.ValueError: invalid literal for int() with base 10: '45.70000076293945'
    • 17.keras报错:ValueError: Cannot create group in read only mode.
    • 18.ValueError: not enough values to unpack (expected 3, got 2)
    • To be continued...

1.安装protobuf:

1)https://github.com/protocolbuffers/protobuf/releases下载
2)源码安装:
下载,然后python setup.py install
2.protoc --python_out=/data/home/ ./DataService.proto
对.proto 运行生成 .py文件

2.python parse_args() 报错 xxx.py: error: the following arguments are required: xxx

报错形如:
usage: test_1.py [-h] aaa
test_1.py: error: the following arguments are required: aaa

原因:
args分为可选参数和必选参数。–指定可选参数,不加–指定的是必选参数。

上述报错的原因是:定义参数aaa时,没有采用 – 的方式,导致相应的参数为必须手动指定的参数。此时即使通过default设置默认参数,也还是会报错

报错的代码:
parser.add_argument(“aaa”, type=str, default=‘bbb’, help=‘ccc’)

正确的代码:
parser.add_argument("–aaa", type=str, default=‘bbb’, help=‘ccc’) # 加–,此时可以使用默认值bbb

3.tf.logging.set_verbosity (tf.logging.INFO)

作用:将 TensorFlow 日志信息输出到屏幕
TensorFlow有五个不同级别的日志信息。其严重性为调试DEBUG<信息INFO<警告WARN<错误ERROR<致命FATAL。当你配置日志记录在任何级别,TensorFlow将输出与该级别相对应的所有日志消息以及更高程度严重性的所有级别的日志信息。
例如,如果设置错误的日志记录级别,将得到包含错误和致命消息的日志输出,并且如果设置了调试级别,则将从所有五个级别获取日志消息。
默认情况下,TENSFlow在WARN的日志记录级别进行配置,但是在跟踪模型训练时,需要将级别调整为INFO

4.VOC数据集

VOC2007 D:\python\code\deeplearning\Deep-Learning-21-Examples-master\chapter_5\research\object_detection\voc

5.安装.whl文件

在.whl文件夹下 pip install 文件名

6.21个项目 chap7

TypeError: Value passed to parameter ‘paddings’ has DataType float32 not in list of allowed values:
#x_padded = tf.pad(x, [[0, 0], [kernel / 2, kernel / 2], [kernel / 2, kernel / 2], [0, 0]], mode=mode) 这种写法报错,替换为下一行
x_padded = tf.pad(x,[[0, 0], [np.int(kernel / 2), np.int(kernel / 2)], [np.int(kernel / 2), np.int(kernel / 2)],[0, 0]], mode=mode)

7.21个项目 chap8 main.py

absl.flags._exceptions.IllegalFlagValueError: flag --train_size=inf: Expect argument to be a string or int, found
#flags.DEFINE_integer(“train_size”, np.inf, “The size of train images [np.inf]”) 替换为下一行
flags.DEFINE_float(“train_size”, np.inf, “The size of train images [np.inf]”)

8.21个项目 chap8 main.py

ValueError: cannot reshape array of size 9912406 into shape (60000,28,28,1)
MNIST文件下载后是.gz格式,需要解压

9.21个项目 chap8 main.py

PermissionError: [Errno 13] Permission denied: './data\mnist\train-images-idx3-ubyte’错误
把文件夹里面的内容复制出来,放到外层,直接读取

10.scipy.misc库函数问题

module ‘scipy.misc’ has no attribute ‘imsave’ 或者’imread’
使用imageio模块代替scipy.misc 模块
scipy.misc.imsave(path, image) 替换为下一行
imageio.imsave(path, image)

保存文件的这种形式已被删除
scipy.misc.toimage(img_array).save(img_name)
scipy.misc.toimage(image_array).save(‘cifar10_data/raw/%d.jpg’ % i)
#采用这种方式
cv2.imwrite(img_name,img_array)

AttributeError: module ‘scipy.misc’ has no attribute ‘imresize’
from scipy import misc
scaled_temp = misc.imresize(cropped_temp, (image_size, image_size), interp=‘bilinear’)
替换为下面的代码
from skimage.transform import resize
scaled_temp = resize(cropped_temp,output_shape=(image_size, image_size))

11.tensorflow.python.framework.errors_impl.NotFoundError: Failed to create a NewWriteableFile: ./tfrecords

处理方法:在相应文件夹下提前手动创建文件“tfrecords”

12.run the eval_ssd_network.py

TypeError: _variable_v2_call() got an unexpected keyword argument ‘collections’
code in ./tf_extended/metrics.py Line 51.
“return variables.Variable” =>> “return variables.VariableV1”

13.TypeError: Can not convert a tuple into a Tensor or Operation.

解决方法为在eval_ssd_network.py文件中添加下面一个函数:
def flatten(x):
result = []
for el in x:
if isinstance(el, tuple):
result.extend(flatten(el))
else:
result.append(el)
return result
然后修改两行代码
将 eval_op=list(names_to_updates.values())
改为 eval_op=flatten(list(names_to_updates.values()))
注意:共有两行!

14.一般CUDA安装失败都是由于其中Visual Studio(VS) Intergration无法安装导致的:

可以通过自定义的方式取消Visual Studio Intergration进行安装

15.ModuleNotFoundError: No module named ‘nets.yolo4’

把nets文件夹随便改个名字就行了

16.ValueError: invalid literal for int() with base 10: ‘45.70000076293945’

报错语句:b = (int(xmlbox.find(‘xmin’).text), int(xmlbox.find(‘ymin’).text), int(xmlbox.find(‘xmax’).text), int(xmlbox.find(‘ymax’).text))
原因:字符串 str 转换成整形 int 中,只能包含数字,不能有其他的。要是想保留原数字,可使用 float 。
修改后好了:
b = (float(xmlbox.find(‘xmin’).text), float(xmlbox.find(‘ymin’).text), float(xmlbox.find(‘xmax’).text), float(xmlbox.find(‘ymax’).text))

或另一种情况:
原代码:int(‘55063.000000’)
改为:int(float(‘55063.000000’))

17.keras报错:ValueError: Cannot create group in read only mode.

tensorflow和keras版本不匹配

18.ValueError: not enough values to unpack (expected 3, got 2)

原因:cv2.findContours的opencv旧版本返回3个值,新版本返回2个值
原代码:_,contours, hierarchy = cv2.findContours(img_gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
改为: contours, hierarchy = cv2.findContours(img_gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)

To be continued…

你可能感兴趣的:(Bug总结,tensorflow)