'having a very large loss when I am training a regression loss

I want to predict the center of the pupil from an image. so I used a CNN with 3 Dence layer. so the input is an image and the output is a coordinate (X,Y). my model is :

from keras.layers import Layer, Conv2D, MaxPooling2D, UpSampling2D, Dropout,Input ,concatenate, Dense
from keras.models import Model
tf.keras.layers.GlobalAveragePooling2D(
    data_format=None, keepdims=False
)
 
def get_model():
    img = Input(shape=(None, None, 3 ))
    conv1_1 = Conv2D(16, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(img)
    conv1_2 = Conv2D(16, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(conv1_1)
    pool1 = MaxPooling2D((2, 2))(conv1_2)
    
    conv2_1 = Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(pool1)
    conv2_2 = Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(conv2_1)
    
    conv3_1 = Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(conv2_2)
    conv3_2 = Conv2D(64, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(conv3_1)
    pool3 = MaxPooling2D((2, 2))(conv3_2)
        
    conv4_1 = Conv2D(128, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(pool3)
    conv4_2 = Conv2D(128, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(conv4_1)
    pool4 = MaxPooling2D((2, 2))(conv4_2)
    
    conv5_1 = Conv2D(256, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(pool4)
    conv5_2 = Conv2D(256, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(conv5_1)
    conv5_2 = Dropout(0.5)(conv5_2)
    conv5_3 = Conv2D(256, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(conv5_2)
    pool5 = MaxPooling2D((2, 2))(conv5_3)
    
    conv6_1 = Conv2D(512, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(pool5)
    conv6_1 = Dropout(0.5)(conv6_1)
    conv6_2 = Conv2D(512, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(conv6_1)
    pool6 = MaxPooling2D((2, 2))(conv6_2)
    
    conv7_1 = Conv2D(1024, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(pool6)
    pool7 = MaxPooling2D((2, 2))(conv7_1)

    conv8_1 = Conv2D(1024, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(pool7)
    Global_pooling = tf.keras.layers.GlobalAveragePooling2D()(conv8_1)

    x = Dense(500, activation='relu')(Global_pooling)
    x = Dense(256, activation='relu')(x)
    x = Dense(128, activation='relu')(x)
    prediction = Dense(2, activation='linear')(x) 
 
    model = Model(inputs=[img], outputs=[prediction])
    #model.summary()
    return model 

and I got a very large error with "MSE" in training. what is the problem? Is the problem with my data? it's my link in colab: https://colab.research.google.com/drive/12hjlT6JG8IlEXYISKw5zFJE6qBDuuVi1?usp=sharing than you for your help



Solution 1:[1]

(Thanks @amina for the update)

Adding the solution here in the Answer Section though it is present in the comment section for the benefit of the community.

I used " tf.keras.losses.MeanSquaredLogarithmicError() " loss function. It makes the amount of error smaller (because of Log )and you can understand whether training is doing well or not.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TFer2