验证torch.nn.Conv2d

import os
import cv2
import torch
import numpy as np
import random
import cv2 as cv
from matplotlib import pyplot as plt

def f_VerifyConv2D():
    """
        验证torch.nn.Conv2d, 并将输入数据及权重保存到txt文件中
    """
    x = torch.randn(1, 1, 10, 10)
    x = x.round().float()
    print('================================== 输入数据 ')
    print(x)
    conv_zeros = torch.nn.Conv2d(in_channels=1, out_channels=3, kernel_size=3, stride=1, padding=1, bias=True)
    conv_zeros.weight = torch.nn.Parameter(torch.ones(1, 1, 3, 3))
    conv_zeros.bias = torch.nn.Parameter(torch.ones(1))
    y = conv_zeros(x)
    print('================================== 卷积权重数据 ')
    print(conv_zeros.state_dict())
    print('================================== 卷积输出数据 ')
    print(y)
    # 转成numpy
    print('================================== 保存参数txt ')
    ndarray = x.numpy()
    print(ndarray)
    ndarray = ndarray.reshape(-1).astype(np.int16)
    ndarray[np.where(ndarray < 0)] = np.add(ndarray[np.where(ndarray < 0)], 255)  # 将负数以补码的形式进行存储
    np.savetxt("1.txt", ndarray, fmt='%x', delimiter='\n')

f_VerifyConv2D()

相关推荐

  1. 验证torch.nn.Conv2d

    2024-05-16 10:34:05       27 阅读
  2. 2402d,d变量2

    2024-05-16 10:34:05       57 阅读
  3. CGAL::2D Arrangements-2

    2024-05-16 10:34:05       55 阅读
  4. css 2D转换

    2024-05-16 10:34:05       61 阅读
  5. css 2D转换

    2024-05-16 10:34:05       44 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-16 10:34:05       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-16 10:34:05       106 阅读
  3. 在Django里面运行非项目文件

    2024-05-16 10:34:05       87 阅读
  4. Python语言-面向对象

    2024-05-16 10:34:05       96 阅读

热门阅读

  1. 【OpenCV 基础知识 3】边缘检测

    2024-05-16 10:34:05       32 阅读
  2. AOP统计SQl执行时间

    2024-05-16 10:34:05       25 阅读
  3. 英特尔处理器-----ERMS

    2024-05-16 10:34:05       28 阅读
  4. 科林算法_4 基础算法

    2024-05-16 10:34:05       26 阅读
  5. electron 使用两个页面(额外添加一个html文件)

    2024-05-16 10:34:05       36 阅读
  6. Log4j2滚动策略深度解析:保持日志轻量高效

    2024-05-16 10:34:05       24 阅读
  7. fastapi+vue实现导入Excel表格的功能

    2024-05-16 10:34:05       41 阅读
  8. 编译gdb:在x86虚拟机上,加载分析arm程序及崩溃

    2024-05-16 10:34:05       37 阅读
  9. 贪吃蛇(C++)

    2024-05-16 10:34:05       38 阅读