【问题标题】:Keras call unable to be called from inside list?无法从列表中调用 Keras 调用?
【发布时间】:2017-10-07 06:20:21
【问题描述】:

我目前收到一条错误消息,指出我超出了我正在迭代的列表的索引范围,但根本不是这种情况。 当我调用 conv1d(input) 时似乎出现了错误,但这些调用被存储在一个列表中,以避免编写多行代码被复制粘贴。

代码如下:

    list_of_input = [Input(shape = (window_height,total_frames_with_deltas,3)) for i in range(splits)]
    list_of_convolution = [(Conv1D(filters = J, kernel_size = 8)) for i in range(45)]
    conv_output = []
    for inputs in list_of_input:
        s = Lambda(slice)(inputs)
        for index in xrange(len(list_of_convolution)):
            print len(s)
            print type(s)
            print len(list_of_convolution)
            print type(list_of_convolution)
            print index
            print "At index"
            print s[index]
            print "con"
            print list_of_convolution[index]
            print "Some"
            output = list_of_convolution[index](s[index])
            print "utu"
            conv_output.append(output)
            print len(conv_output)
            raw_input("Soes")

这是我得到的错误消息的输出:

45
<type 'list'>
45
<type 'list'>
0
At index
Tensor("lambda_1/strided_slice:0", shape=(?, 8, 3), dtype=float32)
con
<keras.layers.convolutional.Conv1D object at 0x7fef61fa2a90>
Some
utu
1
Soes
45
<type 'list'>
45
<type 'list'>
1
At index
Tensor("lambda_1/strided_slice_1:0", shape=(?, 8, 3), dtype=float32)
con
<keras.layers.convolutional.Conv1D object at 0x7fef61fa2d10>
Some
Traceback (most recent call last):
  File "keras_cnn_phoneme_original_fit_generator.py", line 222, in <module>
    fws()
  File "keras_cnn_phoneme_original_fit_generator.py", line 173, in fws
    output = list_of_convolution[index](s[index])
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 572, in __call__
    previous_mask = _collect_previous_mask(inputs)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 2703, in _collect_previous_mask
    mask = node.output_masks[tensor_index]
IndexError: list index out of range

我做错了什么?

【问题讨论】:

    标签: python keras


    【解决方案1】:

    您的索引错误来自list_of_convolution[index](s[index]) 的调用内部,而不是任何一个索引。尝试分步写出来:

    callable = list_of_convolution[index]
    arg = s[index]
    callable(arg)  # <- this is where the error happens
    

    【讨论】:

    • 那也不可能..它在第一次运行时有效,但在第二次运行时失败。两个参数在两次迭代中都包含相同的功能......
    • 错误在上面对callable 的调用中,而不是在索引中(查看回溯以及它的来源)。这意味着错误是库内部的(可能是您使用它的方式),而不是您上面的代码显示的索引。很抱歉,但我对 Keras 不熟悉,所以除了告诉你错误肯定在调用中之外,我对调试你做错的事情没有多大帮助。
    • 啊,好吧..好吧,这清除了一件事..顺便说一句,我改变了问题。
    猜你喜欢
    • 2019-04-21
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多