Keras error ‘Keyword argument not understood:’, ‘subsample’

Total
13
Shares

I am currently trying to make a research paper’s source code work. It’s supposed to be able to detect cells on an image using deep learning. The source code is available here : https://github.com/WeidiXie/cell_counting_v2

I’m using Python 3.9.5 and keras 2.5.0.

I’ve been having some issues trying to make this code work properly, I am getting errors that I’m not sure how to resolve. This happens when I compile train.py :

Traceback (most recent call last):

File "D:FacStage L2Travailtrain.py", line 126, in <module>
train_(base_path)

File "D:FacStage L2Travailtrain.py", line 87, in train_model = buildModel_U_net(input_dim = (256,256,3))

File "D:FacStage L2Travailmodel.py", line 173, in buildModel_U_net
act_ = U_net_base (input_, nb_filter = 64 )

File "D:FacStage L2Travailmodel.py", line 123, in U_net_baseblock1 = _conv_bn_relu_x2(nb_filter,3,3)(input)

File "D:FacStage L2Travailmodel.py", line 57, in fconv_a = Convolution2D(nb_filter, row, col, subsample = subsample,

File "C:UsersCinnaAppDataLocalProgramsPythonPython39libsite-packageskeraslayersconvolutional.py", line 656, in __init__super(Conv2D, self).__init__(

File "C:UsersCinnaAppDataLocalProgramsPythonPython39libsite-packageskeraslayersconvolutional.py", line 125, in __init__
super(Conv, self).__init__(

File "C:UsersCinnaAppDataLocalProgramsPythonPython39libsite-packagestensorflowpythontrainingtrackingbase.py", line 522, in _method_wrapper
result = method(self, *args, **kwargs)

File "C:UsersCinnaAppDataLocalProgramsPythonPython39libsite-packageskerasenginebase_layer.py", line 323, in __init__
generic_utils.validate_kwargs(kwargs, allowed_kwargs)

File "C:UsersCinnaAppDataLocalProgramsPythonPython39libsite-packageskerasutilsgeneric_utils.py", line 1134, in validate_kwargs
raise TypeError(error_message, kwarg)
TypeError: ('Keyword argument not understood:', 'subsample')

From my understanding, there’s an issue with the parameters on line 57 in model.py, they are not recognized ;

conv_a = Convolution2D(nb_filter, row, col, subsample = subsample,
                           init = 'orthogonal', border_mode = 'same',bias = False,
                           W_regularizer = l2(weight_decay),
                           b_regularizer = l2(weight_decay))(input)

I found out if I modified keras configuration’s file base_layer.py and added more "acceptable" parameters in the list on line 312 I wouldn’t get those errors anymore, but it seems weird that this would be the way to go

    allowed_kwargs = {
    'input_dim',
    'input_shape',
    'batch_input_shape',
    'batch_size',
    'weights',
    'activity_regularizer',
    #'subsample',
    #'init',
    #'border_mode',
    #'bias',
    #'W_regularizer',
    #'b_regularizer',
    'autocast',
    'implementation',
}

I’d prefer to only modify the source code on the project and not kera’s, I just don’t understand how. There’s got to be a reason these keywords aren’t in the configuration file, but how am I supposed to make it work then ?

Thanks,


Solution

I think the problem is because of version mismatch of Keras. Convolution2D is a deprecated function in Keras 2.5.0 and it has been replaced by Conv2D and the subsample argument has been replaced by stride. You need to either install an older version of Keras like 1.2.2 or modify the model.py code to make it compatible with new Keras.

For more information you may check:

Leave a Reply

Your email address will not be published. Required fields are marked *