UNCG-DAISY / BuildingFootprints

extract building footprints from NOAA ERI
MIT License
1 stars 1 forks source link

Upload Florence data images for predicting accuracy. #19

Open manishshah1698 opened 2 years ago

manishshah1698 commented 2 years ago

Working on Updated_Semantic_segmentation_using_U_Net.ipynb file to perform visual testing with Florence hurricane images. Checking on code to modify so it takes test folder which contains Florence image.

ebgoldstein commented 2 years ago

there are two ways to do this more simply:

Option 1 is you load all the images into a stack, and then call model.predict to operate on that stack:

#define test directory
test_dir = '../directory/of/images'

#set image size for the model:
imsize = [ XXX,YYY]

#load images
test_images = []

for img in os.listdir(test_dir):
    #pull the name of the image
    test_images.append(img)
    #pull the image
    img = os.path.join(test_dir, img)
    img = tf.keras.preprocessing.image.load_img(img,target_size = imsize)
    img = tf.keras.preprocessing.image.img_to_array(img)
    img = img/255
    img = np.expand_dims(img,axis=0)
    test_images.append(img)

#make predictions 
test_images = np.vstack(test_images)
pred_mask = model.predict(test_images)

option two is you just pass images one at a time.. so you would need a loop for this statement:

#define the image
image_path = '../path/of/image'

#set image size for the model:
imsize = [ XXX,YYY]

#pull the image
img = tf.keras.preprocessing.image.load_img(image_path,target_size = imsize)
img = tf.keras.preprocessing.image.img_to_array(img)
 img = img/255
img = np.expand_dims(img,axis=0)
#make pred
pred = model.predict(img)
ebgoldstein commented 2 years ago

@manishshah1698 - actually, i think this code will work if you remove the img = img/255 line.. the unet has a rescale layer.. so no need to do it before the image is passed into the network