Doodleverse / doodleverse_utils

A set of common Doodleverse tools and utilities
MIT License
4 stars 3 forks source link

Bug with est_label_multiclass and est_label_binary #28

Closed 2320sharon closed 1 year ago

2320sharon commented 1 year ago

There is a bug that only uses the the first channel (aka the red channel) to create a label vector. (tf.expand_dims(image[:,:,0], 0) should be tf.expand_dims(image[:,:,:3], 0) so that if the imagery has 3 or more channels all three channels are used.

I've tried this solution with 4 band imagery with resunet models, but I haven't had any luck with any of the segformer models.

def est_label_multiclass(image,Mc,MODEL,TESTTIMEAUG,NCLASSES,TARGET_SIZE):

    est_label = np.zeros((TARGET_SIZE[0], TARGET_SIZE[1], NCLASSES))

    for counter, model in enumerate(Mc):
        # heatmap = make_gradcam_heatmap(tf.expand_dims(image, 0) , model)
        try:
            if MODEL=='segformer':
                est_label = model(tf.expand_dims(image, 0)).logits
            else:
                est_label = tf.squeeze(model(tf.expand_dims(image, 0)))
        except:
            if MODEL=='segformer':
                est_label = model(tf.expand_dims(image[:,:,0], 0)).logits
            else:
                est_label = tf.squeeze(model(tf.expand_dims(image[:,:,0], 0)))  # the bug
                # est_label = tf.squeeze(model(tf.expand_dims(image[:,:,:3], 0)))  # the fix
2320sharon commented 1 year ago

I found a fix for this and I'm working on it

2320sharon commented 1 year ago

So this works for some models but for model sat_MNDWI_4class_7352850 in coastseg it fails..

It feels like each of the models expects a different sized input....

Input 0 of layer "conv2d" is incompatible with the layer: expected axis -1 of input shape to have value 1, but received input with shape (1, 512, 512, 3)

2320sharon commented 1 year ago

This same error occurs for sat_NDWI_4class_7352859, but not sat_5band_4class_7344606

dbuscombe-usgs commented 1 year ago

yes mndwi and ndwi models should be using (1,512,512,1) sized tensors. they are only 1 band data. I'll need to pay attention to all cases when updating doodleverse-utils. All cases are 1-band (mndwi, ndwi), 3-band, and >3 bands

2320sharon commented 1 year ago

Haha you answered the question I was just about to ask. Thanks

2320sharon commented 1 year ago

We could check the name of the model maybe?

dbuscombe-usgs commented 1 year ago

I think we decided recently to ignore the ndwi and mndwi models for now, but when I update doodleverse-utils (it'll be tomorrow now), I will try to include those cases in my testing suite. this testing suite is LOOONG overdue

dbuscombe-usgs commented 1 year ago

for coastseg and seg2map, at least for now, we'll be working with RGB imagery only. Later we should add 1-band and 5-band models to coastseg.

2320sharon commented 1 year ago

Gotcha. We can come up with a plan with what to do for coastseg tommorrow. Great work!

dbuscombe-usgs commented 1 year ago

I belive this bug is now fixed with the latest release