1.pytest 使用介绍
pytest是一个非常成熟的全功能的Python测试框架
编写规则
编写pytest测试样例非常简单,只需要按照下面的规则:
测试文件以test_开头(以_test结尾也可以)
测试类以Test开头,并且不能带有 init 方法
测试函数以test_开头
断言使用基本的assert即可
fixture的scope参数
scope参数有四种,分别是’function’,‘module’,‘class’,‘session’,默认为function。
function:每个test都运行,默认是function的scope
class:每个class的所有test只运行一次
module:每个module的所有test只运行一次
session:每个session只运行一次
如何执行
- pytest # run all tests below current dir
- pytest test_mod.py # run tests in module file test_mod.py
- pytest somepath # run all tests below somepath like ./tests/
- pytest -k stringexpr # only run tests with names that match the
the “string expression”, e.g. “MyClass and not method”
will select TestMyClass.test_something
but not TestMyClass.test_method_simple - pytest test_mod.py::test_func # only run tests that match the “node ID”,
e.g “test_mod.py::test_func” will be selected
only run test_func in test_mod.py
ResNet-18
这里的18指定带权重的18层,包括卷积层和全联接层,不包括池化层和BN层。
图片归一化

图像归一化最常见的就是最大最小值归一化方法,公式如下:


基于OpenCV实现图像最大最小值归一化的代码演示如下:

基于OpenCV实现图像最大最小值归一化的代码演示如下:
原图像素值输出

归一化之后像素值:

解释
原图与归一化之后的运行结果完全一致,说明归一化不会改变图像本身的信息存储,但是通过打印出来的像素值可以发现,取值范围从0~255已经转化为0~1之间了,这个对于后续的神经网络或者卷积神经网络处理有很大的好处,tensorflow官方给出mnist数据集,全部采用了归一化之后的结果作为输入图像数据来演示神经网络与卷积神经网络。
对图像进行归一化的两种形式
- img = image/255.0
- img = image/127.5 - 1
这两种对图像处理方式都是进行归一化,
1、归一化的范围为【0,1】
还原:img * 255.0
2、范围为【-1,1】
还原:(img + 1.) * 127.5
**感悟:**仅文章一句话,却让我看了一天~
本文介绍pytest测试框架的使用方法及图像归一化的处理技巧。pytest支持灵活的测试用例编写规则,并介绍了fixture的作用域配置。同时,详细解释了图像归一化的原理与实现方法,展示了归一化前后像素值的变化及其对神经网络的影响。
2043

被折叠的 条评论
为什么被折叠?



