2.2.3. Roof Shape Classifier

The Roof Shape Classifier is a module built upon the Generic Image Classifier module. It’s purpose is to classify the roof shape of a building. The roof classifier takes a list of satellite images as the input and will classify the roof type into one of three categories: gabled, hipped, and flat.

Table 2.2.1 Roof prototypes
../../../_images/flat.jpg

Fig. 2.2.1 Flat

../../../_images/gable.jpg

Fig. 2.2.2 Gabled

../../../_images/hip.jpg

Fig. 2.2.3 Hipped

Note

  1. The Roof shape classifier will only identify one roof type per image. As a consequence, the image you provide should only contain the building whose roof type is to be determined.

  2. Many roof shapes found these days are classified as complex. The categories hipped, flat, and gabled were chosen as these are the classifications used in Hazus.

Warning

The classifier takes an image as the input and will always produce a prediction. Since the classifier is trained to classify only a specific category of images, its prediction is meaningful only if the input image belongs to the category the model is trained for.

2.2.3.1. Use the module

Suppose you had a number of images in a folder named image_examples/Roof.

../../../_images/76.png

Fig. 2.2.4 image_examples/Roof/gabled/76.png Gabled

../../../_images/54.png

Fig. 2.2.5 image_examples/Roof/hipped/54.png Hipped

../../../_images/94.png

Fig. 2.2.6 image_examples/Roof/flat/94.png Flat

The following is a python script you would create to use the RoofClassifier to predict the roof shapes for these images:

# import the module
from brails.modules import RoofClassifier

# initialize a roof classifier
roofModel = RoofClassifier()

# define the paths of images in a list
imgs = ['image_examples/Roof/gabled/76.png',
        'image_examples/Roof/hipped/54.png',
        'image_examples/Roof/flat/94.png']

# use the model to predict
predictions = roofModel.predict(imgs)

The predictions obtained when the script runs will look like following:

Image :  image_examples/Roof/gabled/76.png     Class : gabled (83.21%)
Image :  image_examples/Roof/hipped/54.png     Class : hipped (100.0%)
Image :  image_examples/Roof/flat/94.png       Class : flat (97.68%)
Results written in file roofType_preds.csv

Note

  1. The reference to a pretrained model is in a file shipped with BRAILS and the first time you use this module, it will download that model from the internet to your local computer. This will allow you to use it directly without training your own model.

  2. The current pretrained model was trained with 6,000 labeled images utilizing ResNet50. To perform the training a number of buildings with the roof classifications desired were identified utilizing OpenStreetMaps, including 2,000 ‘flat’, ‘gabled’, and ‘hipped’, respectively. Satellite images for those buildings were obtained using Google Maps, and these images were placed into one of three folders as discussed in Generic Image Classifier module. Prior to training the model, the images in the folders were reviewed to ensure they contained an image of a roof and were of the correct roof shape. The noise in this dataset is negligible.

  3. As mentioned in the introduction, SimCenter is constantly updating these trained models. The simplest way to get the latest model is to update your BRAILS installation. This can be done by issuing the following in a terminal/powershell window:

    pip install -U BRAILS --upgrade
    
  4. The images used in the example can be downloaded from Zenodo.

2.2.3.2. Retrain the model

You can retrain the existing model with your own data. To do so, you would place each of your labeled images (images of type .png) into one three seperate folders.

my_roof_shapes
│── flat
│       └── *.png
│── hipped
|      └── *.png
└── gabled
       └── *.png

Then you would create a python script as shown below and run finally run that script to train the model.

# Load images from a folder
roofModel.loadData('my_roof_shapes')

# Re-train it for only 1 epoch for this demo. You can increase it.
roofModel.retrain(initial_epochs=1)

# Test the re-trained model
predictions = roofModel.predict(imgs)

# Save the re-trained model
roofModel.save('myCoolNewRoofModelv0.1')

To use your newly trained model with the Roof Shape classifier, you would include in the RoofClassifier’s constructor the name of the trained model as shown in the following script.

# import the module
from brails.modules import RoofClassifier

# initialize a roof classifier
roofModel = RoofClassifier('myCoolNewRoofModelv0.1')

# define the paths of images in a list
imgs = ['image_examples/Roof/gabled/76.png',
        'image_examples/Roof/hipped/54.png',
        'image_examples/Roof/flat/94.png']

# use the model to predict
predictions = roofModel.predict(imgs)