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数据集,全部采用了归一化之后的结果作为输入图像数据来演示神经网络与卷积神经网络。

对图像进行归一化的两种形式

  1. img = image/255.0
  2. img = image/127.5 - 1

这两种对图像处理方式都是进行归一化,

1、归一化的范围为【0,1】

还原:img * 255.0

2、范围为【-1,1】

还原:(img + 1.) * 127.5

**感悟:**仅文章一句话,却让我看了一天~

相关文章:

  • 2022-12-23
  • 2021-05-13
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
  • 2021-06-21
  • 2021-11-23
  • 2021-07-09
猜你喜欢
  • 2022-12-23
  • 2021-11-01
  • 2022-02-13
  • 2022-01-04
  • 2022-12-23
  • 2021-07-15
相关资源
相似解决方案