简体   繁体   中英

How to concatenate two inputs for a Sequential LSTM Keras network?

Concatenation problem for sequential LSTM network

I've tried to use the Concatenate functions to combine two input arrays axis, but I get the following error, anyone know how to concatenate that arrays? maybe in more steps of concatenations?

cc1 = Concatenate([inp1, inp2],axis=2) 
TypeError: init () got multiple values for argument 'axis'

Output Logs

b'Hello, TensorFlow!'
42
Using TensorFlow backend.

features_set

(1200, 60) 

features_set3

(1, 1200, 60)

C:\\ProgramData\\Anaconda3\\lib\\sitepackages\\sklearn\\utils\\validation.py:595: DataConversionWarning: Data with input dtype int64 was converted to float64 by MinMaxScaler.warnings.warn(msg, DataConversionWarning)

features_set2

(1200, 60)

features_set4

(1, 1200, 60)

shapeINP1

(?, 1, 1200, 60)

shapeINP2

(?, 1, 1200, 60)

Traceback (most recent call last):
File "C:\Users\User\Documents\priv\progpy\prog10-t12.py", line 81, in

cc1 = Concatenate([inp1, inp2],axis=2) 

TypeError: __init__() got multiple values for argument 'axis'

Scope The program here below takes prices of the stocks, then takes the future prices as labels to train the keras net to predict the label prices. I was tring to add to the prices input a new input, the new input to add is the volume input, both will be concatenated to predict the future stock label prices.

Program

import re
import urllib
import json
import matplotlib.pyplot as plt  
import numpy as np  
import pandas as pd
from sklearn.preprocessing import MinMaxScaler 
from keras.models import Sequential  
from keras.layers import Dense  
from keras.layers import LSTM  
from keras.layers import Dropout  
import numpy 
import numpy as np
from keras.models import Model
from keras.layers import Add
from keras.layers import Concatenate
from keras.layers import Dense, concatenate, Input
from keras.layers import LSTM
from keras.utils import np_utils
import keras.layers

apple_training_complete = pd.read_csv(r'\Apps\aapltr.csv')
apple_training_processed = apple_training_complete.iloc[:, 5:6].values
scaler = MinMaxScaler(feature_range = (0, 1))
apple_training_scaled = scaler.fit_transform(apple_training_processed)

features_set = []  
labels = []
labels2 = []

for i in range(60, 1260):  
    features_set.append(apple_training_scaled[i-60:i, 0])
    labels.append(apple_training_scaled[i, 0])

features_set3 = [] 

labels2 = []
features_set, labels = np.array(features_set), np.array(labels) 
features_set = np.reshape(features_set, (features_set.shape[0], features_set.shape[1]))

print("features_set")
print(features_set.shape)
features_set3.append(features_set)
features_set3 = np.array(features_set3)
features_set3 = np.reshape(features_set3, (features_set3.shape[0],  features_set3.shape[1], features_set3.shape[2]))

print("features_set3")
print(features_set3.shape)


apple_training_complete2 = pd.read_csv(r'\Apps\aapltr.csv')
apple_training_processed2 = apple_training_complete2.iloc[:, 6:7].values
apple_training_scaled2 = scaler.fit_transform(apple_training_processed2)

features_set2 = []

for i in range(60, 1260):
    features_set2.append(apple_training_scaled2[i-60:i,0])
    labels2.append(apple_training_scaled[i, 0])

features_set2, labels2 = np.array(features_set2), np.array(labels2) 
features_set2 = np.reshape(features_set2, (features_set2.shape[0], features_set2.shape[1]))
print("features_set2")
print(features_set2.shape)

features_set4 = []

features_set4.append(features_set2)
features_set4 = np.array(features_set4)

features_set4 = np.reshape(features_set4, (features_set4.shape[0], features_set4.shape[1], features_set4.shape[2]))
print("features_set4")
print(features_set4.shape)

inp1 = Input(features_set3.shape)

inp2 = Input(features_set4.shape)

print("  shapeINP1 ")

print(inp1.shape)

print("  shapeINP2 ")

print(inp2.shape)

cc1 = Concatenate([inp1, inp2],axis=2)

output = Dense(30, activation='relu')(cc1)

model = Model(inputs=[inp1, inp2], outputs=output)

model.summary()

Actual Result cc1 = Concatenate([inp1, inp2],axis=2) TypeError: init () got multiple values for argument 'axis'

Expected Result is to use the concatenated inputs to train a LSTM sequential

inp1 = Input(features_set3.shape)
inp2 = Input(features_set4.shape)
cc1 = Concatenate([inp1, inp2],axis=0)
model = Sequential()  
model.add(LSTM(units=50, return_sequences=True, input_shape=(inp1, inp2, 1)))

I've alread tried this second version but without results input_merged = Concatenate([inp1, inp2])(axis=1)

lstm = LSTM(40)(input_merged)

this second version of the code give the this error

  prog10-t12.py", line 81, 
   input_merged = Concatenate([inp1, inp2])(axis=1)

TypeError: call () missing 1 required positional argument: 'inputs'**

Concatenate不是一个函数,它是一个层,所以它应该像这样使用:

cc1 = Concatenate(axis=2)([inp1, inp2])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM