如何在CNTK序列

时间:2017-09-15 07:44:14

标签: python tensorflow computer-vision cntk

我目前正在使用CNTK重新实现我的TensorFlow Jonathan Longs FCN8-s实现。虽然TensorFlow对我来说非常熟悉,但我还缺乏使用微软CNTK的经验。我阅读了一些CNTK Github教程,但现在我想要用upscore层添加pool4_score。在TensorFlow中,我只使用tf.add(pool4_score, upscore1)但在CNTK中我必须使用Sequentials(正确吗?)所以我的代码看起来像:

with default_options(activation=None, pad=True, bias=True):
    z = Sequential([
        For(range(2), lambda i: [
            Convolution2D((3,3), 64, pad=True, name='conv1_{}'.format(i)),
            Activation(activation=relu, name='relu1_{}'.format(i)),
        ]),
        MaxPooling((2,2), (2,2), name='pool1'),

        For(range(2), lambda i: [
            Convolution2D((3,3), 128, pad=True, name='conv2_{}'.format(i)),
            Activation(activation=relu, name='relu2_{}'.format(i)),
        ]),
        MaxPooling((2,2), (2,2), name='pool2'),

        For(range(3), lambda i: [
            Convolution2D((3,3), 256, pad=True, name='conv3_{}'.format(i)),
            Activation(activation=relu, name='relu3_{}'.format(i)),
        ]),
        MaxPooling((2,2), (2,2), name='pool3'),

        For(range(3), lambda i: [
            Convolution2D((3,3), 512, pad=True, name='conv4_{}'.format(i)),
            Activation(activation=relu, name='relu4_{}'.format(i)),
        ]),
        MaxPooling((2,2), (2,2), name='pool4'),

        For(range(3), lambda i: [
            Convolution2D((3,3), 512, pad=True, name='conv5_{}'.format(i)),
            Activation(activation=relu, name='relu5_{}'.format(i)),
        ]),
        MaxPooling((2,2), (2,2), name='pool5'),

        Convolution2D((7,7), 4096, pad=True, name='fc6'),
        Activation(activation=relu, name='relu6'),
        Dropout(0.5, name='drop6'),

        Convolution2D((1,1), 4096, pad=True, name='fc7'),
        Activation(activation=relu, name='relu7'),
        Dropout(0.5, name='drop7'),

        Convolution2D((1,1), num_classes, pad=True, name='fc8')

        ConvolutionTranspose2D((4,4), num_classes, strides=(1,2), name='upscore1')
        # TODO:
        # conv for pool4_score with (1x512) and 21 classes
        # combine upscore 1 and pool4_score
    ])(input)

我读到有combine方法..但我没有找到如何在顺序中使用它的示例。那么我如何使用CNTK实现tf.add方法?

非常感谢!

1 个答案:

答案 0 :(得分:2)

您可以使用C.plus或library(tidyverse) df %>% nest(start, end) %>% mutate(data = map(data, ~seq(unique(.x$start), unique(.x$end), 1))) %>% unnest(data) # # A tibble: 365 x 2 # idnum data # <int> <date> # 1 17 1993-01-01 # 2 17 1993-01-02 # 3 17 1993-01-03 # 4 17 1993-01-04 # 5 17 1993-01-05 # 6 17 1993-01-06 # 7 17 1993-01-07 # 8 17 1993-01-08 # 9 17 1993-01-09 # 10 17 1993-01-10 # # ... with 355 more rows ,在这种情况下,您需要拆分序列才能到达要添加的图层。

例如以下内容:

+

相当于:

z = Sequential([Convolution2D((3,3), 64, pad=True),
                MaxPooling((2,2), (2,2))])(input)

你现在可以做z1 + z2。