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

Model structure #16

Open
electronic-river opened this issue Dec 21, 2023 · 7 comments
Open

Model structure #16

electronic-river opened this issue Dec 21, 2023 · 7 comments
Labels
question Further information is requested

Comments

@electronic-river
Copy link

Hello, I noticed that when running your model for prediction, the resulting output is concatenated with the optical imagery, followed by a lambda operation. In the end, the output shape of the model is (16, 27, 128, 128) instead of (None, 13, 128, 128). Is there any issue with this?
1

@ameraner
Copy link
Owner

Hi :) Those extra concatenate and lambda operations come from here:

if use_cloud_mask:
# the hacky trick with global variables and with lambda functions is needed to avoid errors when
# pickle saving the model. Tensors are not pickable.
# This way, the Lambda function has no special arguments and is "encapsulated"
shape_n = tf.shape(input_opt)
def concatenate_array(x):
global shape_n
return K.concatenate([x, K.zeros(shape=(batch_per_gpu, 1, shape_n[2], shape_n[3]))], axis=1)
x = Concatenate(axis=1)([x, input_opt])
x = Lambda(concatenate_array)(x)

Iirc, I had to add those extra concatenated K.zeros "placeholders" so that the output shape from the model would match with the shape of the target (this was a prerequisite of Keras). The target included an extra layer for the cloud mask, as I needed it to be able to compute the various losses metrics in https://github.com/ameraner/dsen2-cr/blob/main/Code/tools/image_metrics.py (this is also why I'm including the original optical input btw). Since I still need to compute the losses also when predicting (e.g. during the test phase), this is also implemented for the predict step.

The first dimension, 16 for you, should be the batch_per_gpu dimension, defining how many input images you send to the GPU in parallel.

@electronic-river
Copy link
Author

When using the model for prediction, if the input size is 500x1000, and the model's input and output are 128x128, I observed in the source code that the program randomly crops the input size to 128x128 for prediction. If I want to predict on the entire 500x1000 image, what should I do?

@ameraner
Copy link
Owner

The data augmentation and random cropping are deactivated for the prediction step. However, it looks like I was supporting only square crops... so I think, atm you could change the crop_size to 500, and you would get the first half of your image predicted. With a little code modification you should probably be able to tile the input image and get a full predicted image as output.

@electronic-river
Copy link
Author

Hello, sorry to bother you amidst your busy schedule. Due to certain reasons related to the performance, I am currently trying to use your model and its parameters to train my own dataset (consisting of Sentinel-1 and Sentinel-2 images downloaded from Google Earth Engine). I am following your approach to divide the dataset into 256x256 patches. However, during training, I have observed that the output loss becomes NaN. Could you please provide guidance on how to resolve this issue? Thank you.
QQ截图20231226185424

@ameraner
Copy link
Owner

Hmm, that's odd, in my setup the trainings were always stable... did you tune/change the learning rate maybe?

@ameraner ameraner added the question Further information is requested label Dec 28, 2023
@lu-qi0727
Copy link

屏幕截图 2024-07-16 003022
@electronic-river 请问你解决这个问题了吗,但是我用的是原始数据,也出现了这个问题

@ameraner
Copy link
Owner

@lu-qi0727 please use English for comments, thank you!
Translation of your message:

Have you solved this problem? I used the original data and this problem also occurred.

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

No branches or pull requests

3 participants