Skip to content

Could Adapt accept multi-shape input? #135

Description

@HoraceLiu1010

I am building a tensorflow model for regression with multi-inpout. the first input is a 50*3 sequence feature, and the other input is a float tensor. The base model:

input_seq = Input(shape=(50, 3)) # the first input
lstm1 = LSTM(64, return_sequences=True)(input_seq)
lstm2 = LSTM(32)(lstm1)
dense1 = Dense(32, activation='relu')(lstm2)
input_float = Input(shape=(1,)) # the second input
dense2 = Dense(16, activation='relu')(input_float)
concatenated = Concatenate()([dense1, dense2])
dense3 = Dense(8, activation='relu')(concatenated)
dense4 = Dense(1)(dense3)
model = Model(inputs=[input_seq, input_float], outputs=dense4)

The base model can be trained. But the model with Adapt can not be trained:

model_DA = DANN(model,
                optimizer=tf.keras.optimizers.Adam(),
                lambda_=1.0)
model_DA.fit([x_seq_train,x_float_train], y_train, [x_seq_tar, x_float_tra], batch_size=32, epochs=20)

AttributeError: 'list' object has no attribute 'shape'

I tried to set encoder/task manually:

input_seq = Input(shape=(50, 3)) # the first input
lstm1 = LSTM(64, return_sequences=True)(input_seq)
lstm2 = LSTM(32)(lstm1)
dense1 = Dense(32, activation='relu')(lstm2)
encoder = Model(inputs=[input_seq], outputs=dense1)
input_float = Input(shape=(1,))  # the second input
encoder_output = Input(shape= encoder.layers[-1].output_shape[1:] ) 
dense2 = Dense(16, activation='relu')(input_float)
concatenated = Concatenate()([dense2, encoder_output])
dense3 = Dense(8, activation='relu')(concatenated)
dense4 = Dense(1)(dense3)
task = Model(inputs=[input_float, encoder_output], outputs=dense4)
model_DA = DANN(encoder, task, lambda_=0.05, random_state=1, optimizer=Adam(learning_rate=0.0002,decay=1e-6))

If I use '[ ]' to set the input:
model_DA.fit([x_train,C_train], y_train, [x_test, C_train], batch_size=32, epochs=20)

AttributeError: 'list' object has no attribute 'shape'

Or if I use '( )' to set the input:
model_DA.fit((x_train,C_train), y_train, (x_test, C_train), batch_size=32, epochs=20)

`ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (2, 148534) + inhomogeneous part.

Please let me know if this error is caused by the coding mistake.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions