<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Samar-blog

      導航

      P16.土堆說卷積(可選看)

      16.1torch.nn.functional.conv2d的參數(shù)(官網(wǎng))

      點擊查看代碼
      input:input tensor of shape (minibatch,in_channels,iH,iW)
      weight:filters of shape (out_channels,in_channelsgroups,kH,kW)
      bias:optional bias tensor of shape (out_channels). Default: `None`
      stride:the stride of the convolving kernel. Can be a single number or a tuple (sH, sW). Default: 1
      padding:implicit paddings on both sides of the input. Can be a string {‘valid’, ‘same’}, single number or a tuple (padH, padW).Default: 0 `padding='valid'` is the same as no padding. `padding='same'` pads the input so the output has the same shape as the input. However, this mode doesn’t support any stride values other than 1.
      

      16.2卷積原理

      1

      16.3根據(jù)以上圖片的tensor,寫入pycharm

      代碼如下:

      點擊查看代碼
      import torch
      
      #根據(jù)圖片上的輸入圖像和卷積核
      input = torch.tensor([[1,2,0,3,1],
                            [0,1,2,3,1],
                            [1,2,1,0,0],
                            [5,2,3,1,1],
                            [2,1,0,1,1]])
      kernel = torch.tensor([[1,2,1],
                             [0,1,0],
                             [2,1,0]])
      
      #打印input和kernel的尺寸
      print(input.shape)
      print(kernel.shape)
      

      運行結(jié)果如下:

      點擊查看代碼
      D:\anaconda3\envs\pytorch\python.exe D:/DeepLearning/Learn_torch/P16_nnConv.py
      torch.Size([5, 5])
      torch.Size([3, 3])
      
      進程已結(jié)束,退出代碼0
      
      很明顯,他的尺寸輸出只有兩個參數(shù),他不符合torch.nn.functional.conv2d的參數(shù)input – input tensor of shape (minibatch,in_channels,iH,iW)中對于input和kernel的四個參數(shù)的要求

      16.4torch.reshape函數(shù)&torch.shape函數(shù)

      1.PyTorch中的torch.reshape函數(shù)

      (1)官方文檔介紹:
      torch.reshape(input, shape) → Tensor
      Returns a tensor with the same data and number of elements as input, but with the specified shape. When possible, the returned tensor will be a view of input. Otherwise, it will be a copy. Contiguous inputs and inputs with compatible strides can be reshaped without copying, but you should not depend on the copying vs. viewing behavior.

      (2)翻譯為大白話:
      在PyTorch中,torch.reshape函數(shù)是用來改變張量(Tensor)的形狀(shape)的工具。這個函數(shù)不改變張量中的數(shù)據(jù)和元素數(shù)量,只是重新排列這些元素的形狀。當可能的時候,torch.reshape會返回原始張量的一個視圖(view),這意味著新的張量和原始張量共享相同的數(shù)據(jù),但是展示的形狀不同。如果不能返回一個視圖,那么它會返回一個數(shù)據(jù)的拷貝。

      2.PyTorch中的torch.shape函數(shù)

      在PyTorch中,處理圖像數(shù)據(jù)的張量默認遵循NCHW(或稱為channels_first)的格式,即:
      N: Number of images in the batch (批次中的圖像數(shù)量)
      C: Channels per image (每張圖像的通道數(shù))
      H: Height of each image (每張圖像的高度)
      W: Width of each image (每張圖像的寬度)

      3.應用conv2d

      代碼如下:

      點擊查看代碼
      import torch
      import torch.nn.functional as F
      #根據(jù)圖片上的輸入圖像和卷積核
      input = torch.tensor([[1,2,0,3,1],
                            [0,1,2,3,1],
                            [1,2,1,0,0],
                            [5,2,3,1,1],
                            [2,1,0,1,1]])
      kernel = torch.tensor([[1,2,1],
                             [0,1,0],
                             [2,1,0]])
      
      #修改尺寸:batch_size為1,channel為1,寬和高保持原來的:
      input = torch.reshape(input,(1,1,5,5))
      kernel = torch.reshape(kernel,(1,1,3,3))
      
      #打印input和kernel的尺寸
      print(input.shape)
      print(kernel.shape)
      
      #應用conv2d
      #import torch.nn.functional as F
      output = F.conv2d(input,kernel,stride=1)
      print(output)
      
      輸出結(jié)果如下:
      點擊查看代碼
      #輸出結(jié)果如下:
      D:\anaconda3\envs\pytorch\python.exe D:/DeepLearning/Learn_torch/P16_nnConv.py
      torch.Size([1, 1, 5, 5])
      torch.Size([1, 1, 3, 3])
      tensor([[[[10, 12, 12],
                [18, 16, 16],
                [13,  9,  3]]]])
      
      進程已結(jié)束,退出代碼0
      
      和圖片上我們自己計算的結(jié)果一模一樣,輸出結(jié)果為tensor類型的3*3矩陣

      4.修改stride參數(shù)

      代碼如下:

      點擊查看代碼
      #應用conv2d(其他代碼同上)
      #import torch.nn.functional as F
      output2 = F.conv2d(input,kernel,stride=2)
      print(output2)
      
      輸出結(jié)果如下:
      點擊查看代碼
      #輸出結(jié)果如下:
      tensor([[[[10, 12],
                [13,  3]]]])
      
      輸出結(jié)果為tensor類型的2*2矩陣

      5.padding

      【padding=1表示原input圖像,上下左右各添加一個空白行(列),值為0】

      代碼如下:

      點擊查看代碼
      #應用conv2d(其他代碼同上)
      #import torch.nn.functional as F
      #增加padding參數(shù)
      output3 = F.conv2d(input,kernel,stride=1,padding=1)
      print(output3)
      

      輸出結(jié)果如下:

      點擊查看代碼
      #輸出結(jié)果如下:
      tensor([[[[ 1,  3,  4, 10,  8],
                [ 5, 10, 12, 12,  6],
                [ 7, 18, 16, 16,  8],
                [11, 13,  9,  3,  4],
                [14, 13,  9,  7,  4]]]])
      
      輸出結(jié)果為tensor類型的5*5矩陣,明顯尺寸變大
      如圖,原始圖像因為padding=1的設(shè)置,變成了7*7的矩陣:

      2

      posted on 2025-11-04 20:53  風居住的街道DYL  閱讀(6)  評論(0)    收藏  舉報

      主站蜘蛛池模板: 欧美成人精品三级在线观看| 亚洲成av一区二区三区| 无码av免费毛片一区二区 | 日韩中文字幕亚洲精品一| 成全影视大全在线观看| 久章草在线毛片视频播放| 亚洲国产高清av网站| 免费无码黄网站在线观看| 亚洲日本一区二区三区在线播放 | 亚洲国产精品久久无人区| 蜜桃无码一区二区三区| 亚洲中文字幕日产无码成人片| 无码一区中文字幕| 亚洲AV成人片不卡无码| 久久天天躁狠狠躁夜夜av不卡| 青草热在线观看精品视频| 久久精品女人的天堂av| 国产精品疯狂输出jk草莓视频| 公喝错春药让我高潮| 国产女同一区二区在线| 免费无码AV一区二区波多野结衣| 亚洲精品久久久久玩吗| 久久国内精品一区二区三区| 中文字幕第一页国产精品| 亚洲av影院一区二区三区| 亚洲中文字幕在线二页| 国色天香中文字幕在线视频| 日韩中文字幕有码av| 波多野结衣乳喷高潮视频| 国精品午夜福利视频不卡| 日韩有码中文字幕一区二区| 在线免费不卡视频| 免费人成网站免费看视频| 色婷婷欧美在线播放内射| 亚洲熟女乱色综合一区 | 欧美成年黄网站色视频| 国产高清国产精品国产专区| 一区二区三区av天堂| 怡红院一区二区三区在线| 国产精品∧v在线观看| 中国帅小伙gaysextubevideo|