Difficulties implementing a DANN using the ADAPT package for python: Input to reshape is a tensor with 128 values, but the requested shape has 32

I would like to implement a DANN (domain adversarial neural network) by making use of the ADAPT package for python, however, there seems to be an issue regarding the input shape of the task classifier or discriminator.

Below, you can find my code.
As input I am using EEG data meaning that the data has the following shape:

Xs: (254, 60, 257, 1) (meaning: (#trials, #channels, #timepoints, 1))

Xt: (255, 60, 257, 1)

ys: (254,)

yt: (255,)

I want to use EEGNet as encoder (feature extractor) and have also defined the task and discriminator classifier. I have not yet done anything fancy with the optimizers and also have not run a hyperparameter search, as I keep getting the same error when trying to run the code.

channels = Xs.shape[1]
timepoints = Xs.shape[2]

def get_EEGNet_feature_encoder(Chans=channels, Samples=timepoints,
                               dropoutRate=0.3, kernLength=64, F1=6,
                               D=1, F2=6, dropoutType='Dropout'):

    if dropoutType == 'SpatialDropout2D':
        dropoutType = SpatialDropout2D
    elif dropoutType == 'Dropout':
        dropoutType = Dropout
    else:
        raise ValueError('dropoutType must be one of SpatialDropout2D '
                         'or Dropout, passed as a string.')

    model = Sequential()
    model.add(Conv2D(F1, (1, kernLength), padding='valid',
                     input_shape=(Chans, Samples, 1),
                     use_bias=False))
    model.add(BatchNormalization())
    model.add(DepthwiseConv2D((Chans, 1), use_bias=False,
                              depth_multiplier=D,
                              depthwise_constraint=max_norm(1.), padding='valid'))
    model.add(BatchNormalization())
    model.add(Activation('elu'))
    model.add(AveragePooling2D((1, 4)))
    model.add(dropoutType(dropoutRate))

    model.add(SeparableConv2D(F2, (1, 16),
                              use_bias=False, padding='valid'))
    model.add(BatchNormalization())
    model.add(Activation('elu'))
    model.add(AveragePooling2D((1, 8)))
    model.add(dropoutType(dropoutRate))

    model.add(Flatten())

    model.compile(optimizer=SGD(0.01), loss='mse')

    return model

def get_EEGNet_task(input_shape, nb_classes=4, norm_rate=0.25):
    model = Sequential()
    model.add(Input(shape=input_shape))
    model.add(Dense(nb_classes, name='task_dense', kernel_constraint=max_norm(norm_rate), activation='softmax'))
    model.compile(optimizer=SGD(0.01), loss='mse')
    return model

def get_EEGNet_discriminator(input_shape):
    model = Sequential()
    model.add(Input(shape=input_shape))
    model.add(Dense(10, activation='elu'))
    model.add(Dense(1, name='disc_dense', activation='sigmoid'))
    model.compile(optimizer=SGD(0.01), loss='mse')
    return model

encoder = get_EEGNet_feature_encoder()
encoder_output_shape = encoder.output_shape[1:]

model = DANN(encoder=get_EEGNet_feature_encoder(), task=get_EEGNet_task(input_shape=encoder_output_shape),
             discriminator=get_EEGNet_discriminator(input_shape=encoder_output_shape), lambda_=0.01, Xt=Xt, metrics=["acc"],
             optimizer=SGD(0.001), random_state=304)

# Train the model
model.fit(Xs, ys, Xt, epochs=100)

# Evaluate the model
model.score(Xt, yt)

Error message when executing model.fit():

Input to reshape is a tensor with 128 values, but the requested shape has 32
     [[{{node Reshape}}]] [Op:__inference_train_function_3508]

I cannot even say whether the issue is related to the task or discriminator classifier (could also be both). I thought, I had solved the issue by extracting the output shape of the encoder as input shape for the task and discriminator classifier, but obviously not. Removing the flatten layer from the encoder did also not work.

I’d be happy, if someone could help me out here. My question might be easy to solve, however, if you’re doing it yourself, you get blind to the errors you make.

Thanks in advance for any advice!

New contributor

Johanna is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật