Keras: TypeError: __call__() got an unexpected keyword argument 'name'
Keras: TypeError: __call__() got an unexpected keyword argument 'name'
我正在尝试让 DeepCell 与 keras 一起工作。我是 运行ning 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/ 指南。我认为它可能与依赖项的版本有关,就像我遇到的大多数其他问题一样,但我不完全确定。任何帮助将不胜感激,是否需要任何其他信息来帮助,让我知道。
DeepCell(至少是这个版本)不完全兼容 Keras 2 .
[GitHub]: CovertLab/DeepCell - (master) DeepCell/keras_version/cnn_functions.py:
第 971 行(__init__ 的一部分):
d = 1, init='glorot_uniform', activation='linear', weights=None,
第 982 行:
self.init = initializations.get(init)
第 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):
因此,在 Keras 2 中,初始值设定项 headers 发生了(彻底)更改,并且 DeepCell 代码未反映那。为了修复您的错误,可以:
- 切换到 Keras 1
- 修改 DeepCell 代码以 Keras 2 兼容。但我严重怀疑 cnn_functions.py:1012 将是唯一修改
的地方
我正在尝试让 DeepCell 与 keras 一起工作。我是 运行ning 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/ 指南。我认为它可能与依赖项的版本有关,就像我遇到的大多数其他问题一样,但我不完全确定。任何帮助将不胜感激,是否需要任何其他信息来帮助,让我知道。
DeepCell(至少是这个版本)不完全兼容 Keras 2 .
[GitHub]: CovertLab/DeepCell - (master) DeepCell/keras_version/cnn_functions.py:
第 971 行(__init__ 的一部分):
d = 1, init='glorot_uniform', activation='linear', weights=None,
第 982 行:
self.init = initializations.get(init)
第 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):
因此,在 Keras 2 中,初始值设定项 headers 发生了(彻底)更改,并且 DeepCell 代码未反映那。为了修复您的错误,可以:
- 切换到 Keras 1
- 修改 DeepCell 代码以 Keras 2 兼容。但我严重怀疑 cnn_functions.py:1012 将是唯一修改 的地方