reachsumit / deep-unet-for-satellite-image-segmentation

Satellite Imagery Feature Detection with SpaceNet dataset using deep UNet
309 stars 139 forks source link

predict part #24

Open fadili97 opened 4 years ago

fadili97 commented 4 years ago

great work I would like to be enlightned more about this part if you allow, because I couldnt get to understand its role in prediction part. Thanks in advance: `for i in range(7): if i == 0: # reverse first dimension mymat = predict(img[::-1,:,:], model, patch_sz=PATCH_SZ, n_classes=N_CLASSES).transpose([2,0,1])

print(mymat[0][0][0], mymat[3][12][13])

        print("Case 1",img.shape, mymat.shape)
    elif i == 1:    # reverse second dimension
        temp = predict(img[:,::-1,:], model, patch_sz=PATCH_SZ, n_classes=N_CLASSES).transpose([2,0,1])
        #print(temp[0][0][0], temp[3][12][13])
        print("Case 2", temp.shape, mymat.shape)
        mymat = np.mean( np.array([ temp[:,::-1,:], mymat ]), axis=0 )
    elif i == 2:    # transpose(interchange) first and second dimensions
        temp = predict(img.transpose([1,0,2]), model, patch_sz=PATCH_SZ, n_classes=N_CLASSES).transpose([2,0,1])
        #print(temp[0][0][0], temp[3][12][13])
        print("Case 3", temp.shape, mymat.shape)
        mymat = np.mean( np.array([ temp.transpose(0,2,1), mymat ]), axis=0 )
    elif i == 3:
        temp = predict(np.rot90(img, 1), model, patch_sz=PATCH_SZ, n_classes=N_CLASSES)
        #print(temp.transpose([2,0,1])[0][0][0], temp.transpose([2,0,1])[3][12][13])
        print("Case 4", temp.shape, mymat.shape)
        mymat = np.mean( np.array([ np.rot90(temp, -1).transpose([2,0,1]), mymat ]), axis=0 )
    elif i == 4:
        temp = predict(np.rot90(img,2), model, patch_sz=PATCH_SZ, n_classes=N_CLASSES)
        #print(temp.transpose([2,0,1])[0][0][0], temp.transpose([2,0,1])[3][12][13])
        print("Case 5", temp.shape, mymat.shape)
        mymat = np.mean( np.array([ np.rot90(temp,-2).transpose([2,0,1]), mymat ]), axis=0 )
    elif i == 5:
        temp = predict(np.rot90(img,3), model, patch_sz=PATCH_SZ, n_classes=N_CLASSES)
        #print(temp.transpose([2,0,1])[0][0][0], temp.transpose([2,0,1])[3][12][13])
        print("Case 6", temp.shape, mymat.shape)
        mymat = np.mean( np.array([ np.rot90(temp, -3).transpose(2,0,1), mymat ]), axis=0 )
    else:
        temp = predict(img, model, patch_sz=PATCH_SZ, n_classes=N_CLASSES).transpose([2,0,1])
        #print(temp[0][0][0], temp[3][12][13])
        print("Case 7", temp.shape, mymat.shape)
        mymat = np.mean( np.array([ temp, mymat ]), axis=0 )`