Keras:TypeError:__ call __()得到了一个意外的关键字参数'name'

时间:2017-07-13 15:02:08

标签: python keras theano

我试图让DeepCell与keras合作。我正在运行keras 2,但我在keras 1的UID代码中添加了让DeepCell运行。除了我刚刚下载的依赖项和软件文件,我收到以下错误。

回溯:

  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'

我正试图运行的代码:

"""
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)

我正在使用https://covertlab.github.io/DeepCell/starting/指南。我认为它可能与依赖项的版本有关,因为我遇到的大多数其他问题都是,但我不完全确定。任何帮助将不胜感激,是否需要任何其他信息来帮助,让我知道。

1 个答案:

答案 0 :(得分:1)

DeepCell (至少此版本)与 keras 2 不完全兼容

因此,在 keras 2 中,初始化程序标题已更改(大幅度),而 DeepCell 代码并未反映出来。为了解决您的错误,请执行以下操作之一:

  • 切换到 keras 1
  • DeepCell 代码修改为 keras 2 兼容。但我严重怀疑 cnn_functions.py:1012 是唯一可以修改的地方