Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to use SAM as a loss metric in KERAS #23

Closed
NourO93 opened this issue Jun 22, 2021 · 1 comment
Closed

Trying to use SAM as a loss metric in KERAS #23

NourO93 opened this issue Jun 22, 2021 · 1 comment

Comments

@NourO93
Copy link

NourO93 commented Jun 22, 2021

I am training a CNN to perform single image super resolution, and I want to use SAM as a loss metric. I imported sewar and defined SAM function, and then added it to the loss metrics in the model arguments as so:

def sam(y_true,y_pred):
    print(tf.shape(y_true))
    print(tf.shape(y_pred))
    return sewar.full_ref.sam(y_true,y_pred)



opt=K.optimizers.Adam(learning_rate=0.0001) # Adam optimizer
model.compile(optimizer=opt,loss=perceptual_loss,metrics=[psnr,ssim,K.losses.mean_squared_error, sam])
history = model.fit_generator(generator=train_generator(),
                              steps_per_epoch=np.ceil(float(len(train_list)) / float(batch_size)),
                              epochs=40, #20
                              verbose=1,
                              validation_data=valid_generator(),
                              shuffle=True,
                              validation_steps=np.ceil(float(len(val_list)) / float(batch_size)))

However, I get the following error:

AssertionError: Supplied images have different sizes (None, 32, 32, 3) and (None, 32, 32, 3)

I am confused as to how to solve this, because it seems to me that the sizes are the same. Can someone help me with this?

@andrewekhalel
Copy link
Owner

It seems to me that the problem could be because you pass batch (multiple images) not a single image. Sewar metrics are implemented to support only images with 3 dims. so (32, 32, 3) is supported however (None, 32, 32, 3) has one extra dimension (won't work)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants