Thanks a lot for your time and helping … excuse me if i have two models one of them i should remove the last layer or classification layer and the other model need to implement it as those line
modelB =  ResNet50()
modelB.layers.pop()
modelB = Model(inputs=model.inputs, outputs=model.layers[-2].output)

then the ensemble should be like that
class Identity(nn.Module):
    def __init__(self):
        super().__init__()

    def forward(self, x):
        return x

class MyEnsemble(nn.Module):
    def __init__(self, modelA, modelB):
        super(MyEnsemble, self).__init__()
        self.modelA = modelA
        self.modelB = modelB
        # Remove last linear layer
        self.modelA.fc = nn.Identity()
             
    def forward(self, x):
        x1 = self.modelA(x.clone())  # clone to make sure x is not changed by inplace methods
        x1 = x1.view(x1.size(0), -1)
        x2 = self.modelB(x)
        x2 = x2.view(x2.size(0), -1)
        x = torch.cat((x1, x2), dim=1)
       
        return x

# Create models and load state_dicts    
modelA= model1()
# Load state dicts
PATH1 = 'model1.pth'
modelA.load_state_dict(torch.load(PATH1))
modelB =  ResNet50()
modelB.layers.pop()
modelB = Model(inputs=model.inputs, outputs=model.layers[-2].output)

model = MyEnsemble(modelA, modelB)