keras-team / keras-applications

Reference implementations of popular deep learning models.
Other
2k stars 913 forks source link

Supporting ResNet 1by2 variants #115

Open avitex opened 5 years ago

avitex commented 5 years ago

A basic way to implement this would be simply defining ResNet50_1by2 variants like in this commit. However this would break the convention of the provided ImageNet weights (unless they were generated of course). Instead would propose a generic filter_mult arg which would be used like so:

def ResNet50(include_top=True,
             weights='imagenet',
             input_tensor=None,
             input_shape=None,
             pooling=None,
             classes=1000,
             filter_mult=1,
             **kwargs):
    def stack_fn(x, filter_mult):
        x = stack1(x, int(64 * filter_mult), 3, stride1=1, name='conv2')
        x = stack1(x, int(128 * filter_mult), 4, name='conv3')
        x = stack1(x, int(256 * filter_mult), 6, name='conv4')
        x = stack1(x, int(512 * filter_mult), 3, name='conv5')
        return x
    return ResNet(stack_fn, False, True, 'resnet50',
                  include_top, weights,
                  input_tensor, input_shape,
                  pooling, classes, filter_mult,
                  **kwargs)

With any value other than 1, an error would be thrown if weights still specified 'imagenet':

if weights == 'imagenet' and filter_mult != 1:
    # throw error

Happy to submit a PR for this :)

2sang commented 5 years ago

Though it sounds completely fair to have more small variants of the model, I think subclassed models in this project should be restricted to the more widely known ones that people agree with, In my humble opinion. Or, we can have them as a parameterized form in the parent class if the option for the variants benefits the model hugely.

avitex commented 5 years ago

I think subclassed models in this project should be restricted to the more widely known ones that people agree with, In my humble opinion.

I completely agree, it would be a little optimistic to assume every model used ever would be present, and the line has to be drawn somewhere