web-dev-qa-db-ja.com

Keras:TypeError:__ call __()が予期しないキーワード引数 'name'を取得しました

DeepCellをkerasで動作させようとしています。 keras 2を実行していますが、DeepCellを実行できるようにkeras1のUIDコードを追加しました。それ以外は、依存関係とソフトウェアファイルをダウンロードしたところ、次のエラーが発生します。

トレースバック:

  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/ ガイドを使用しています。私が抱えていた他のほとんどの問題と同様に、依存関係のバージョンが原因である可能性があると思いますが、完全にはわかりません。どんな助けでも大歓迎です、助けのために他の情報が必要であるならば、私に知らせてください。

3
Alexander Mertz

DeepCell(少なくともこのバージョン)は完全に互換性がありません Keras2

したがって、Keras 2では、初期化子ヘッダーが(大幅に)変更され、DeepCellコードエラーを修正するには、次のいずれかを行います。

  • Keras1に切り替えます
  • DeepCellコードをKeras 2互換性があるように変更します。しかし、私はcnn_functions.py:1012が変更する唯一の場所になります
1
CristiFati