Tensor concat आउटपुट इनपुट करने के लिए फ़ीड करने के लिए नए lstm परत

0

सवाल

मैं कोशिश करने के लिए नयी आकृति प्रदान करना और concat कुछ करने के लिए उत्पादन compleate मूल इनपुट का उपयोग करें और यह अगले चरण के अपने मॉडल. आयाम मैच के लिए लगते हैं, लेकिन मैं इस त्रुटि मिलती है:

Concatenate(axis=2)([tensor_input2, out_first_try])
*** ValueError: A `Concatenate` layer requires inputs with matching 
shapes except for the concat axis. Got inputs shapes: [(64, 10, 8), [(), 
(), ()]]

मैं भी प्रयास करें :

tf.concat([tensor_input2, out_first_try], 2)

इस त्रुटि के साथ:

tf.concat([tensor_input2, out_first_try], 2)
*** ValueError: Shape must be rank 3 but is rank 1 for '{{node 
tf.concat/concat}} = ConcatV2[N=2, T=DT_FLOAT, Tidx=DT_INT32] 
(Placeholder, tf.concat/concat/values_1, tf.concat/concat/axis)' with 
input shapes: [64,10,8], [3], [].

कारण एक ही होने लगते हैं लेकिन मैं समझ नहीं कर सकते करने के लिए कैसे के साथ सौदा है कि,

    # tensor_input1 = [64,365,9]
    tensor_input1 = Input(batch_size=batch, shape=(X.shape[1], 
                    X.shape[2]), name='input1')
    # tensor_input2 = [64,10,8]
    tensor_input2 = Input(batch_size=batch, shape=(X2.shape[1], 
                    X2.shape[2]), name='input2')

    extractor = CuDNNLSTM(100, return_sequences=False, 
                 stateful=False, name='LSTM1')(tensor_input2)
    extractor = Dropout(rate = .2)(extractor)
   
    extractor = Dense(100, activation='softsign')(extractor)

    out_1 = Dense(10, activation='linear')(extractor2)

    # add a dimension to out_1 [64,10] to fit tensor_input2 
    out_first_try = tf.expand_dims(out_1, axis=2).shape.as_list()

    # concat in 3d dim the output to the original input
    # tensor_input2 =[64,10,8] 
    # out_first_try, after tf.expend [64,10,1]
    forcast_input  = Concatenate(axis=2)([tensor_input2, 
                     out_first_try])

    # forcast_input expected size [64,10,9]

    # finaly concat tensor_input1, new tensor_input2 side to side
    allin_input = Concatenate(axis=1)([tensor_input1, forcast_input])
    # allin_input  expected size [64,365+10,9]

    extractor2 = CuDNNLSTM(100, return_sequences=False, 
                 stateful=False, name='LSTM1')(allin_input )
    ...
concatenation python tensor tensorflow
2021-11-23 20:12:42
1

सबसे अच्छा जवाब

1

जोड़ना एक tensor एक सूची के साथ काम नहीं करेगा. तो, हो सकता है कुछ इस तरह:

out_first_try = tf.expand_dims(out_1, axis=2)
forcast_input  = Concatenate(axis=2)([tensor_input2, out_first_try])

ध्यान दें कि मैं हटा दिया है shape.as_list() क्योंकि, के रूप में नाम का सुझाव है, यह रिटर्न के आकार के एक tensor एक सूची के रूप में. आप सत्यापित कर सकते हैं कि इस उदाहरण के साथ:

import tensorflow as tf

out_1 = tf.random.normal((5, 10))
out_first_try = tf.expand_dims(out_1, axis=2).shape.as_list()
tf.print(type(out_first_try))
#<class 'list'>
2021-11-23 20:45:51

है कि यह, यह काम अच्छी तरह से, बहुत बहुत धन्यवाद!
Jonathan Roy

अन्य भाषाओं में

यह पृष्ठ अन्य भाषाओं में है

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

इस श्रेणी में लोकप्रिय

लोकप्रिय सवाल इस श्रेणी में