在keras中更改模型定义内的模型输入的输入形状

时间:2017-05-02 16:40:57

标签: python numpy keras

我目前在解决此问题时遇到问题。

我有一个网络,我用numpy.ndarray形状喂养

(batch_size,40,45,3) 

但我想在每一行上进行1d卷积,然后将每个结果附加到列表中。

这要求我以某种方式提取输入的行,但是如何访问模型定义中的输入数据..

这是目前的情况:

 def row_convolution(input):
    filter_size = 8

    for units in xrange(splits):
        extract = input[units:units+filter_size,:,:]
        for row_of_extract in extract:
            row_of_extract = np.expand_dims(row_of_extract,axis=0)
            temp_list.append((Conv1D(filters = 1, kernel_size = 1, activation='relu' , name = 'conv')(tf.pack(row_of_extract))))
            print len(temp_list)
        sum_temp_list.append(sum(temp_list))
    conv_feature_map.append(sum_temp_list)
    return np.array(conv_feature_map)

def output_of_row_convolution(input_shape):
    return (1, input_shape)

def fws():
    #Input shape: (batch_size,40,45,3)
    #output shape: (1,15,50)
    # number of unit in conv_feature_map = split
    filter_size = 8
    temp_list = []
    sun_temp_list = []
    conv_featur_map = []

    model = Sequential()

    #convolution
    model.add(Lambda(row_convolution,output_shape=output_of_row_convolution,input_shape = (40,45,3)))

    model.compile(loss="categorical_crossentropy", optimizer="SGD" , metrics = [metrics.categorical_accuracy])

    #Pooling


    hist_current = model.fit_generator(train_generator(batch_size),
                        steps_per_epoch=10,
                        epochs = 100000,
                        verbose = 1,
                        validation_data = test_generator(),
                        validation_steps=1,
                        pickle_safe = True,
                        workers = 4)

fws()

0 个答案:

没有答案