Back to DrivenData | Blog

Adding bands -take 2

So, folks I need help here. I want to verify if I’m doing this thing right.

We have four bands that we are given , I want to do band-difference and get NDVI and use that as an additional band for training. So, here is where I’m at, and not sure if I have it working.

I’m using - How to Use Deep Learning, PyTorch Lightning, and the Planetary Computer to Predict Cloud Cover in Satellite Imagery - DrivenData Labs code to test it.

In the ClodDataset class, I modified __getitem(…)

    def __getitem__(self, idx: int):
        # Loads an n-channel image from a chip-level dataframe
        img =[idx]
        band_arrs = []
        for band in self.bands:
            with[f"{band}_path"]) as b:
                band_arr ="float32")
        #--- add Allow division by zero
        np.seterr(divide='ignore', invalid='ignore')

        # --Calculate NDVI
        ndvi = (band_arrs[3].astype("float32") - band_arrs[2].astype("float32")) / (band_arrs[3].astype("float32") + band_arrs[2].astype("float32")).astype("float32") 

        x_arr = np.stack(band_arrs, axis=-1)

Then, in the CloudModel, I changed the number of bands

def _prepare_model(self):
        # Instantiate U-Net model
        unet_model = smp.UnetPlusPlus(
        if self.gpu:

        return unet_model

Am I on the right track ? Is it the right way to do add bands from the existing 4 bands ?