Training a an unsupervised regression model using Tensorflow with a custom loss function

30 Views Asked by At

I have trained a model using supervised learning. Now I want to try and improve its results by giving taking the outputs of the trained supervised model and using the input features to improve the results using an unsupervised model with a custom loss function. I have been looking everywhere for an answer to this. I could not find anything that was clear. Any texts I could read to understand better?

input_shape = [2, K * N]
loaded_model = tf.keras.models.load_model("Model")

class CustomUnsupervisedLoss(tf.keras.losses.Loss):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

    def call(self, inputs):
        # Implement your unsupervised loss function here
        h_r = K.get_value(inputs[0, :])
        h_i = K.get_value(inputs[1, :])
        loss = K.mean(K.square(h_r - h_i ), axis=-1)
        return loss


loaded_model.compile(loss=CustomUnsupervisedLoss())
loaded_model.fit(H_split, y=None, epochs=1, batch_size=20, shuffle=True)

I get the following error:

ValueError: Target data is missing. Your model was compiled with loss=<__main__.CustomUnsupervisedLoss object at 0x000001F061A30950>, and therefore expects target data to be provided in fit().

0

There are 0 best solutions below