Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Keras中,合并辅助输入是否保留排序顺序_Keras - Fatal编程技术网

在Keras中,合并辅助输入是否保留排序顺序

在Keras中,合并辅助输入是否保留排序顺序,keras,Keras,在一个模型体系结构中,主数据具有应用于早期级别的卷积,然后是串联(合并),然后是密集操作,当批量被洗牌时,我们能否依靠串联中的适当排序 作为一个例子,考虑一组在一周中不同的日子拍摄的照片。在该架构中,首先对照片进行卷积,然后进行展平操作。展平后,将周中的单个参数day_连接到展平张量,然后密集运算得到最终输出 我担心的是,示例照片与星期几之间的关联将丢失。这是否会自动处理模型(输入=[photoconvdata,dowdata],…)语句?Td;lr是,否则多输入模型将适用于卷积。 有人可能会在

在一个模型体系结构中,主数据具有应用于早期级别的卷积,然后是串联(合并),然后是密集操作,当批量被洗牌时,我们能否依靠串联中的适当排序

作为一个例子,考虑一组在一周中不同的日子拍摄的照片。在该架构中,首先对照片进行卷积,然后进行展平操作。展平后,将周中的单个参数day_连接到展平张量,然后密集运算得到最终输出


我担心的是,示例照片与星期几之间的关联将丢失。这是否会自动处理模型(输入=[photoconvdata,dowdata],…)语句?

Td;lr是,否则多输入模型将适用于卷积。 有人可能会在后面的答案中引用代码路径,我将尝试给出一些经验证据

首先,让我们模拟一个3D张量(假设你在照片中使用通道——这很重要)。我们想让大家明白 示例的索引未被触及。所以我们会留下一堆零 在最后一个示例(示例)中。您会注意到,当我们检查输出时,这些零是示例输出的最后一个零

我们测试它的方法是建立并拟合一个模型。每个时代之后 我们将检查连接层的输出。我们应该找到一些迹象表明连接发生在正确的索引上

from keras.model import Model
from keras.layers import Dense, Conv2D, concatenate, Flatten, Input
X = np.zeros((10, 10, 10, 10), dtype=np.int8)
# making the example different
X[:9, :] = np.random.randint(100, 110, (9, 10, 10, 10))

X_ this is your second input (photo_date)
X_ = np.ones((10, 1))

# model
inp = Input((10, 10, 10))
inp2 = Input((1,))
conv  = Conv2D(3, (2, 2))(inp)
flat = Flatten()(conv)
merge = concatenate([flat, inp2])
out = Dense(1, activation='sigmoid')(merge)
model = Model(inputs = [inp, inp2], outputs=[out])

# here is the function we're going to use to checkout the output 
# at the concatenation layer
concat_output = K.function([model.inputs[0], model.inputs[1], 
                        K.learning_phase()], 
                       [model.layers[4].output])

# print the output before training. This is what we expect, 0's are
# in the last position with a 1 concatenated to every index.
concat_output([X, X_, 0])

>>>    [array([[ 113.494606,   54.331547, -290.99573 , ...,   53.661514,
         -289.99292 ,    1.      ],
        [ 114.72675 ,   51.808422, -284.84506 , ...,   48.507256,
         -286.96945 ,    1.      ],
        [ 110.17914 ,   54.97028 , -288.6585  , ...,   51.36793 ,
         -287.4386  ,    1.      ],
        ...,
        [ 111.09259 ,   57.093   , -281.43994 , ...,   49.77134 ,
         -288.38226 ,    1.      ],
        [ 108.35742 ,   45.220837, -284.50668 , ...,   48.4583  ,
         -295.17084 ,    1.      ],
        [   0.      ,    0.      ,    0.      , ...,    0.      ,
            0.      ,    1.      ]], dtype=float32)]
正如所料。但这不是你的问题,你感兴趣的是批处理过程中会发生什么。然后让我们进行批处理和洗牌。我们来看看 每个历元后Op的输出,虽然我们可以预期输出为零(模型的重量将改变),但我们应该看到最后一个示例中的所有值都是相同的

# we train for 2 epoches using this was since we want to investigate 
the model output. after every round without having to deal
with callbacks.
for i in range(2): 
    print(concat_output([X, X_, 0]))
    model.fit([X, X_], y, batch_size=2) # shuffle = True by default

[array([[ 1.0643581e+01,  7.7266968e+01,  4.6593994e+01, ...,
         7.5334999e+01,  4.8712486e+01,  1.0000000e+00],
       [ 1.5145729e+01,  7.3742798e+01,  4.3532047e+01, ...,
         7.3937592e+01,  5.0245125e+01,  1.0000000e+00],
       [ 1.9058825e+01,  7.3847824e+01,  4.9182228e+01, ...,
         7.4079361e+01,  4.4511917e+01,  1.0000000e+00],
       ...,
       [ 1.1023483e+01,  7.0525513e+01,  4.0074528e+01, ...,
         7.4147705e+01,  4.4983501e+01,  1.0000000e+00],
       [ 1.1787775e+01,  7.6140900e+01,  4.5392090e+01, ...,
         7.5364082e+01,  4.5399754e+01,  1.0000000e+00],
       [-4.4723554e-03,  4.4722753e-03, -4.4723558e-03, ...,
         4.4722753e-03, -4.4723558e-03,  1.0000000e+00]], dtype=float32)]
Epoch 1/1
10/10 [==============================] - 0s - loss: 0.3998     
[array([[ 1.0641594e+01,  7.7268997e+01,  4.6592007e+01, ...,
         7.5337029e+01,  4.8710499e+01,  1.0000000e+00],
       [ 1.5143742e+01,  7.3744827e+01,  4.3530060e+01, ...,
         7.3939621e+01,  5.0243137e+01,  1.0000000e+00],
       [ 1.9056837e+01,  7.3849854e+01,  4.9180241e+01, ...,
         7.4081390e+01,  4.4509930e+01,  1.0000000e+00],
       ...,
       [ 1.1021496e+01,  7.0527542e+01,  4.0072540e+01, ...,
         7.4149734e+01,  4.4981514e+01,  1.0000000e+00],
       [ 1.1785788e+01,  7.6142929e+01,  4.5390102e+01, ...,
         7.5366112e+01,  4.5397766e+01,  1.0000000e+00],
       [-6.4606303e-03,  6.4977570e-03, -6.4600804e-03, ...,
         6.4977570e-03, -6.4600804e-03,  1.0000000e+00]], dtype=float32)]
Epoch 1/1
10/10 [==============================] - 0s - loss: 0.3995  
是的,请注意最后一个索引中的值都是相同的,这证明最后一个示例仍然是转换形式 我们输入的0


希望这能让您确信不会将照片时间连接到错误的图像索引。

回答非常详细和仔细,非常有用。