Multi-Output Models

  • Build models that predict more than one output by designing multiple outputs in the last layer.pythonCopy codefrom tensorflow.keras.models import Model from tensorflow.keras.layers import Dense, Input input_layer = Input(shape=(20,)) x = Dense(128, activation='relu')(input_layer) # Output 1 output1 = Dense(10, activation='softmax', name='output_1')(x) # Output 2 output2 = Dense(1, activation='linear', name='output_2')(x) model = Model(inputs=input_layer, outputs=[output1, output2]) model.compile(optimizer='adam', loss=['categorical_crossentropy', 'mse'], metrics=['accuracy', 'mae'])
  • This setup is useful for multi-task learning where you have a combination of classification and regression tasks.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *