Python代码或CNN架构特性上的错误,我不理解

2024-05-29 06:17:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Python和CNN的新手

我在这个Github repository中找到了以下代码:

### ----define U-net architecture--------------
def get_unet(img_shape = None):

        dim_ordering = 'tf'
        inputs = Input(shape = img_shape)
        concat_axis = -1
        ### the size of convolutional kernels is defined here    
        conv1 = Convolution2D(64, 5, 5, activation='relu', border_mode='same', dim_ordering=dim_ordering, name='conv1_1')(inputs)
        conv1 = Convolution2D(64, 5, 5, activation='relu', border_mode='same', dim_ordering=dim_ordering)(conv1)
        pool1 = MaxPooling2D(pool_size=(2, 2), dim_ordering=dim_ordering)(conv1)
        conv2 = Convolution2D(96, 3, 3, activation='relu', border_mode='same', dim_ordering=dim_ordering)(pool1)

        # The rest omitted by brevity

我不明白这句话:

conv1 = Convolution2D(64, 5, 5, activation='relu', border_mode='same', dim_ordering=dim_ordering)(conv1)

为什么conv1等于Convolution2D([...])(conv1)

他们在行乞时使用conv1,在判决的最后使用conv1。这是个错误吗


Tags: imgsizemodeactivationcnnrelusameinputs
2条回答

您认为这是一个错误的原因是,到目前为止,您在Keras中使用了所谓的顺序API

这里使用的是函数式API。后者意味着比顺序API具有更大的灵活性

您可以在此处阅读有关函数API及其适用性的更多信息:https://www.tensorflow.org/guide/keras/functional

这不是一个错误,你甚至可以写

input = ...
net = Conv2d(...)(input)
net = Conv2d(...)(net)
net = Pool(...)(net)
...

相关问题 更多 >

    热门问题