Keras, Tensorflow: Systematic Offset in Predictions

Keras, Tensorflow: Systematic Offset in Predictions



I am working on a regression CNN using Keras/Tensorflow. I have a multi-output feed-forward model that I have trained up with some success. The model takes in a 201x201 grayscale image and returns two regression targets.



Here is an example of an input/target pair:



enter image description here is associated with (z=562.59, a=4.53)



There exists an analytical solution for this problem, so I know it's solvable.



Here is the model architecture:


model_input = keras.Input(shape=input_shape, name='image')
x = model_input
x = Conv2D(32, kernel_size=(3, 3), activation='relu')(x)
x = MaxPooling2D(pool_size = (2,2))(x)
x = Conv2D(32, kernel_size=(3, 3), activation='relu')(x)
x = MaxPooling2D(pool_size = (2,2))(x)
x = Conv2D(32, kernel_size=(3, 3), activation='relu')(x)
x = MaxPooling2D(pool_size = (2,2))(x)
x = Conv2D(16, kernel_size=(3, 3), activation='relu')(x)
x = MaxPooling2D(pool_size = (4,4))(x)
x = Flatten()(x)
model_outputs = list()
out_names = ['z', 'a']
for i in range(2):
out_name = out_names[i]
local_output= x
local_output = Dense(10, activation='relu')(local_output)
local_output = Dropout(0.2)(local_output)
local_output = Dense(units=1, activation='linear', name = out_name)(local_output)
model_outputs.append(local_output)
model = Model(model_input, model_outputs)
model.compile(loss = 'mean_squared_error', optimizer='adam', loss_weights = [1,1])



My targets are on different scales, so I normalized one of them (name 'a') to the range [0,1] for training. Here is how I rescale:


def rescale(min, max, list):
scalar = 1./(max-min)
list = (list-min)*scalar
return list



Where min,max for each parameter are known a priori and are constant.



Here is how I trained:


model.fit('image' : x_train,
'z' : z_train, 'a' : a_train,
batch_size = 32,
epochs=20,
verbose=1,
validation_data = ('image' : x_test,
'z' : z_test, 'a' : a_test))



When I predict for 'a', I get a fairly good accuracy, but with an offset:



enter image description here



This is a fairly easy thing to fix, I just apply a linear fit to the predictions and invert it to rescale:



enter image description here



But I can't think of a reason why this would be happening in the first place. I've used this same model architecture for other problems, and I get that same offset again. Has anyone seen this sort of thing before?



EDIT: This offset occurs in multiple different models of mine, which each predict different parameters but are rescaled/preprocessed in the same way. It happens regardless of how many epochs I train for, with more training resulting in predictions hugging the green line (in the first graph) more closely.



As a temporary work-around, I trained a single-node model to take the input as the original model's prediction and the output as the ground truth. This trained up nicely, and corrects the offset. What's strange though, is that I can apply this rescale model to ANY of the models with this issue, and it corrects the offset equally well.



Essentially: the offset has the same weight for multiple different models, which predict completely different parameters. This makes me think there is something to do with the activation or regularization.





Welcome to Stack Overflow! I believe your code is missing some important details that would allow us to further understand the problem (see Minimal, Complete, and Verifiable example). What code has been used for the training process? Additional details of the data set, and potentially some samples, would be useful as well.
– E_net4 is kind and welcoming
Aug 30 at 15:11





Thanks for your comment! I have edited my post.
– laltman
Aug 30 at 20:20





@laltman the first thing that comes to mind is trying it without the dropout layer, I would also take a look at regularization/preprocessing that you are or aren't doing.
– Josh Rumbut
Aug 30 at 21:27





You may also want to experiment with the optimizer (for instance trying rmsprop), I put this in a comment instead of an answer because it's just "hey maybe twiddle the knobs" instead of carefully considered advice. Shuffling the data if it happens to be sorted is another thought.
– Josh Rumbut
Aug 30 at 21:31






@JoshRumbut thanks. What I'm seeing now does not seem to suggest an undertrain/overtrain issue (edited the OP with more info), I think it's more likely to be related to an activation or regularization.
– laltman
Aug 31 at 3:49






Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế