Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Keras转换为Pytorch-conv2d_Keras_Pytorch - Fatal编程技术网

从Keras转换为Pytorch-conv2d

从Keras转换为Pytorch-conv2d,keras,pytorch,Keras,Pytorch,我正在尝试将下面的Keras代码转换为PyTorch tf.keras.Sequential([ Conv2D(128, 1, activation=tf.nn.relu), Conv2D(self.channel_n, 1, activation=None), ]) 当使用self.channels=16创建模型摘要时,我得到以下摘要 Model: "sequential" _____________________

我正在尝试将下面的Keras代码转换为PyTorch

    tf.keras.Sequential([
          Conv2D(128, 1, activation=tf.nn.relu),
          Conv2D(self.channel_n, 1, activation=None),
    ])
当使用self.channels=16创建模型摘要时,我得到以下摘要

Model: "sequential"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d (Conv2D)              (1, 3, 3, 128)            6272      
_________________________________________________________________
conv2d_1 (Conv2D)            (1, 3, 3, 16)             2064      
=================================================================
Total params: 8,336
Trainable params: 8,336
Non-trainable params: 0
一个人如何转变信仰

我尝试过这样做:

import torch
from torch import nn

class CellCA(nn.Module):
    def __init__(self, channels, dim=128):
        super().__init__()
        self.net = nn.Sequential(
            nn.Conv2d(in_channels=channels,out_channels=dim, kernel_size=1),
            nn.ReLU(),
            nn.Conv2d(in_channels=dim, out_channels=channels, kernel_size=1),
        )
    def forward(self, x):
        return self.net(x)

但是,我得到4240个参数,如果您在correcty中配置初始通道(本例中为48个),则上述尝试是正确的