Hello,
I am in the process of converting the TwoStream Inception I3D architecture from Keras to Pytorch. In this process, I am relying onto two implementations. The first one here 7 is the source architecture in Keras, and the second one here 2 is the target conversion.
The target doesn’t fit what I am looking for. I want to prune the basic Pytorch architecture of InceptionI3d a little bit to remove what comes after the AvgPool3D, flatten the outputs of AvgPool3D, and then finish with the classification layer using an equivalent of the Dense layer (in the Keras architecture).
How can I convert this Keras code into Pytorch ?
flow_x = i3d_structure(flow_img_input,
                  channel_axis,
                  include_top,
                  dropout_prob,
                  endpoint_logit,
                  classes,
                  type='flow')

    rgb_x = i3d_structure(rgb_img_input,
                           channel_axis,
                           include_top,
                           dropout_prob,
                           endpoint_logit,
                           classes,
                          type='rgb')
    # create model
    FLOW_stream = Model(input=flow_img_input, output=flow_x, name='flow_stream_i3d_inception')
    RGB_stream = Model(input=rgb_img_input, output=rgb_x, name='rgb_stream_i3d_inception')
# load weights
    if weights in WEIGHTS_NAME:
        if weights == WEIGHTS_NAME[0, 1]:  # rgb_kinetics_only and flow_kinetics_only
            if include_top:
                rgb_weights_url = WEIGHTS_PATH['rgb_kinetics_only']
                rgb_model_name = 'i3d_inception_rgb_kinetics_only.h5'
                flow_weights_url = WEIGHTS_PATH['flow_kinetics_only']
                flow_model_name = 'i3d_inception_flow_kinetics_only.h5'
            else:
                rgb_weights_url = WEIGHTS_PATH_NO_TOP['rgb_kinetics_only']
                rgb_model_name = 'i3d_inception_rgb_kinetics_only_no_top.h5'
                flow_weights_url = WEIGHTS_PATH_NO_TOP['flow_kinetics_only']
                flow_model_name = 'i3d_inception_flow_kinetics_only_no_top.h5'

        elif weights == WEIGHTS_NAME[2, 3]:  # rgb_imagenet_and_kinetics and flow_imagenet_and_kinetics
            if include_top:
                rgb_weights_url = WEIGHTS_PATH['rgb_imagenet_and_kinetics']
                rgb_model_name = 'i3d_inception_rgb_imagenet_and_kinetics.h5'
                flow_weights_url = WEIGHTS_PATH['flow_imagenet_and_kinetics']
                flow_model_name = 'i3d_inception_flow_imagenet_and_kinetics.h5'
            else:
                rgb_weights_url = WEIGHTS_PATH_NO_TOP['rgb_imagenet_and_kinetics']
                rgb_model_name = 'i3d_inception_rgb_imagenet_and_kinetics_no_top.h5'
                flow_weights_url = WEIGHTS_PATH_NO_TOP['flow_imagenet_and_kinetics']
                flow_model_name = 'i3d_inception_flow_imagenet_and_kinetics_no_top.h5'

        downloaded_rgb_weights_path = get_file(rgb_model_name, rgb_weights_url, cache_subdir='models')
        downloaded_flow_weights_path = get_file(flow_model_name, flow_weights_url, cache_subdir='models')
        RGB_stream.load_weights(downloaded_rgb_weights_path)
        FLOW_stream.load_weights(downloaded_flow_weights_path)

        if K.backend() == 'theano':
            layer_utils.convert_all_kernels_in_model(RGB_stream)
            layer_utils.convert_all_kernels_in_model(FLOW_stream)

        if K.image_data_format() == 'channels_first' and K.backend() == 'tensorflow':
            warnings.warn('You are using the TensorFlow backend, yet you '
                          'are using the Theano '
                          'image data format convention '
                          '(`image_data_format="channels_first"`). '
                          'For best performance, set '
                          '`image_data_format="channels_last"` in '
                          'your keras config '
                          'at ~/.keras/keras.json.')

        x = RGB_stream.layers[-1].output
        x = Flatten()(x)

        y = FLOW_stream.layers[-1].output
        y = Flatten()(y)

    elif weights is not None:
        RGB_stream.load_weights(weights[0])
        FLOW_stream.load_weights(weights[1])

        x = RGB_stream.layers[-1].output
        x = Flatten()(x)

        y = FLOW_stream.layers[-1].output
        y = Flatten()(y)

    else: #No Weights
        x = RGB_stream.layers[-1].output
        x = Flatten()(x)

        y = FLOW_stream.layers[-1].output
        y = Flatten()(y)

    global_stream = layers.concatenate([x, y])
    global_stream = Dense(classes, activation='softmax', name='predictions')(global_stream)

    model = Model(input=[rgb_img_input, flow_img_input], output=global_stream, name='TwoStream_I3D')