nicolov / segmentation_keras

DilatedNet in Keras for image segmentation
MIT License
301 stars 92 forks source link

regarding the function definition used in model.py #5

Closed wenouyang closed 7 years ago

wenouyang commented 7 years ago

Hi nicolov,

Thanks for sharing the code. By the way, I see you define the model function as follows:

I am not very clear about the usage of -> Sequential . What does it used for, when do we need to add this when defining a function. Also it seems to me you pass the input parameter as model: Sequential. Is that because we only need to ensure model is of sequential. I think I am not very clear about the parameter passing mechanism here.

def add_softmax(model: Sequential) -> Sequential:
    """ Append the softmax layers to the frontend or frontend + context net. """
    # The softmax layer doesn't work on the (width, height, channel)
    # shape, so we reshape to (width*height, channel) first.
    # https://github.com/fchollet/keras/issues/1169
    _, curr_width, curr_height, curr_channels = model.layers[-1].output_shape

    model.add(Reshape((curr_width * curr_height, curr_channels)))
    model.add(Activation('softmax'))
    # Technically, we need another Reshape here to reshape to 2d, but TF
    # the complains when batch_size > 1. We're just going to reshape in numpy.
    # model.add(Reshape((curr_width, curr_height, curr_channels)))

    return model
nicolov commented 7 years ago

Hi. These are just python 3 - style type annotations as documented here: https://docs.python.org/3/library/typing.html

In other words, you can safely ignore them.

On Sunday, 12 February 2017, wenouyang notifications@github.com wrote:

Hi nicolov,

Thanks for sharing the code. By the way, I see you define the model function as follows:

I am not very clear about the usage of -> Sequential . What does it used for, when do we need to add this when defining a function. Also it seems to me you pass the input parameter as model: Sequential. Is that because we only need to ensure model is of sequential. I think I am not very clear about the parameter passing mechanism here.

def add_softmax(model: Sequential) -> Sequential: """ Append the softmax layers to the frontend or frontend + context net. """

The softmax layer doesn't work on the (width, height, channel)

# shape, so we reshape to (width*height, channel) first.
# https://github.com/fchollet/keras/issues/1169
_, curr_width, curr_height, curr_channels = model.layers[-1].output_shape

model.add(Reshape((curr_width * curr_height, curr_channels)))
model.add(Activation('softmax'))
# Technically, we need another Reshape here to reshape to 2d, but TF
# the complains when batch_size > 1. We're just going to reshape in numpy.
# model.add(Reshape((curr_width, curr_height, curr_channels)))

return model

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nicolov/segmentation_keras/issues/5, or mute the thread https://github.com/notifications/unsubscribe-auth/AKO4B8onOteal4hZwfumWzU8KVhpma0hks5rbfGVgaJpZM4L-POm .