Keras: TypeError: __call__() got an unexpected keyword argument 'name'
DeepCell (at least this version,) is not fully compatible with Keras 2.
-
[GitHub]: CovertLab/DeepCell - (master) DeepCell/keras_version/cnn_functions.py:
-
Line #971 (part of __init__):
d = 1, init='glorot_uniform', activation='linear', weights=None,
-
Line #982:
self.init = initializations.get(init)
-
Line #1012:
self.W = self.init(self.W_shape, name='{}_W'.format(self.name))
-
-
[GitHub]: keras-team/keras - (keras-1) keras/keras/initializations.py:56:
def glorot_uniform(shape, name=None, dim_ordering='th'):
-
[GitHub]: keras-team/keras - (keras-2) keras/keras/initializers.py:325:
def glorot_uniform(seed=None):
So, in Keras 2 the initializers headers were (drastically) changed, and DeepCell code doesn't reflect that. In order to fix your error, either:
- Switch to Keras 1
- Modify DeepCell code to be Keras 2 compatible. But I seriously doubt that cnn_functions.py:1012 would be the only place to modify
Admin
Updated on September 06, 2022Comments
-
Admin over 1 year
I am attempting to get DeepCell to work with keras. I'm running keras 2, but I added in the UID code from keras 1 to let DeepCell run. other than that I just downloaded the dependencies and software files, and I'm getting the following error.
Traceback:
Traceback (most recent call last): File "/home/birtwistlelab/DeepCell/keras_version/running_template.py",line 65, in <module> cytoplasm_predictions = run_models_on_directory(data_location,cyto_channel_names, cyto_location, model_fn = cyto_fn,list_of_weights = list_of_cyto_weights, image_size_x = image_size_x, image_size_y = image_size_y,win_x = win_cyto, win_y = win_cyto, std = False, split = False) File "/home/birtwistlelab/DeepCell/keras_version/cnn_functions.py", line 1491, in run_models_on_directory model = model_fn(batch_input_shape = batch_input_shape, n_features = n_features, weights_path = list_of_weights[0]) File "/home/birtwistlelab/DeepCell/keras_version/model_zoo.py", line 528, in sparse_bn_feature_net_61x61 model.add(sparse_Convolution2D(64, 3, 3, d = d, init = init, batch_input_shape = batch_input_shape, border_mode='valid', W_regularizer = l2(reg))) File "/home/birtwistlelab/miniconda2/lib/python2.7/site-packages/keras/models.py", line 436, in add layer(x) File "/home/birtwistlelab/miniconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 569, in __call__ self.build(input_shapes[0]) File "/home/birtwistlelab/DeepCell/keras_version/cnn_functions.py", line 1012, in build self.W = self.init(self.W_shape, name='{}_W'.format(self.name)) TypeError: __call__() got an unexpected keyword argument 'name'
Code I am trying to run:
""" Load data """ direc_name = "/home/birtwistlelab/DeepCell/validation_data/HeLa/" data_location = os.path.join(direc_name, 'RawImages') cyto_location = os.path.join(direc_name, 'Cytoplasm') nuclear_location = os.path.join(direc_name, 'Nuclear') mask_location = os.path.join(direc_name, 'Masks') cyto_channel_names = ['phase','farred'] nuclear_channel_names = ['farred'] trained_network_cyto_directory = "/home/birtwistlelab/DeepCell/trained_networks/HeLa/" trained_network_nuclear_directory = "/home/birtwistlelab/DeepCell/trained_networks/Nuclear/" cyto_prefix = "2017-06-21_HeLa_all_61x61_bn_feature_net_61x61_" nuclear_prefix = "2016-07-12_nuclei_all_61x61_bn_feature_net_61x61_" win_cyto = 30 win_nuclear = 30 image_size_x, image_size_y = get_image_sizes(data_location, nuclear_channel_names) image_size_x /= 2 image_size_y /= 2 """ Define model """ list_of_cyto_weights = [] for j in xrange(5): cyto_weights = os.path.join(trained_network_cyto_directory, cyto_prefix + str(j) + ".h5") list_of_cyto_weights += [cyto_weights] list_of_nuclear_weights = [] for j in xrange(5): nuclear_weights = os.path.join(trained_network_nuclear_directory, nuclear_prefix + str(j) + ".h5") list_of_nuclear_weights += [nuclear_weights] print list_of_nuclear_weights """ Run model on directory """ cytoplasm_predictions = run_models_on_directory(data_location, cyto_channel_names, cyto_location, model_fn = cyto_fn,list_of_weights = list_of_cyto_weights, image_size_x = image_size_x, image_size_y = image_size_y,win_x = win_cyto, win_y = win_cyto, std = False, split = False) nuclear_predictions = run_models_on_directory(data_location, nuclear_channel_names, nuclear_location, model_fn = nuclear_fn,list_of_weights = list_of_nuclear_weights, image_size_x = image_size_x, image_size_y = image_size_y,win_x = win_nuclear, win_y = win_nuclear, std = False, split = False) """ Refine segmentation with active contours """ nuclear_masks = segment_nuclei(nuclear_predictions, mask_location = mask_location, threshold = 0.75, area_threshold = 100, solidity_threshold = 0.75, eccentricity_threshold = 0.95) cytoplasm_masks = segment_cytoplasm(cytoplasm_predictions, nuclear_masks = nuclear_masks, mask_location = mask_location, smoothing = 1, num_iters = 120) """ Compute validation metrics (optional) """ direc_val = os.path.join(direc_name, 'Validation') imglist_val = nikon_getfiles(direc_val, 'validation_interior') val_name = os.path.join(direc_val, imglist_val[0]) print val_name val = get_image(val_name) val = val[win_cyto:-win_cyto,win_cyto:-win_cyto] cyto = cytoplasm_masks[0,win_cyto:-win_cyto,win_cyto:-win_cyto] nuc = nuclear_masks[0,win_cyto:-win_cyto,win_cyto:-win_cyto] print val.shape, cyto.shape, nuc.shape dice_jaccard_indices(cyto, val, nuc)
I'm using the https://covertlab.github.io/DeepCell/starting/ guide. I've think it probably has something to due with the versions of the dependencies, as most of the other problems I was having were, but I'm not entirely sure. Any help would be greatly appreciated, is any other information is needed to help, let me know.