This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow import keras | |
# Define the parameters of the model | |
model = keras.Sequential([ | |
keras.layers.Flatten(input_shape=(1, nBands)), | |
keras.layers.Dense(14, activation='relu'), | |
keras.layers.Dense(2, activation='softmax')]) | |
# Define the accuracy metrics and parameters | |
model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Normalise the data | |
xTrain = xTrain / 255.0 | |
xTest = xTest / 255.0 | |
featuresHyderabad = featuresHyderabad / 255.0 | |
# Reshape the data | |
xTrain = xTrain.reshape((xTrain.shape[0], 1, xTrain.shape[1])) | |
xTest = xTest.reshape((xTest.shape[0], 1, xTest.shape[1])) | |
featuresHyderabad = featuresHyderabad.reshape((featuresHyderabad.shape[0], 1, featuresHyderabad.shape[1])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.model_selection import train_test_split | |
xTrain, xTest, yTrain, yTest = train_test_split(featuresBangalore, labelBangalore, test_size=0.4, random_state=42) | |
print(xTrain.shape) | |
print(yTrain.shape) | |
print(xTest.shape) | |
print(yTest.shape) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pyrsgis.convert import changeDimension | |
featuresBangalore = changeDimension(featuresBangalore) | |
labelBangalore = changeDimension (labelBangalore) | |
featuresHyderabad = changeDimension(featuresHyderabad) | |
nBands = featuresBangalore.shape[1] | |
labelBangalore = (labelBangalore == 1).astype(int) | |
print("Bangalore multispectral image shape: ", featuresBangalore.shape) | |
print("Bangalore binary built-up image shape: ", labelBangalore.shape) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Bangalore multispectral image shape: ", featuresBangalore.shape) | |
print("Bangalore binary built-up image shape: ", labelBangalore.shape) | |
print("Hyderabad multispectral image shape: ", featuresHyderabad.shape) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from pyrsgis import raster | |
os.chdir("E:\\yourDirectoryName") | |
mxBangalore = 'l5_Bangalore2011_raw.tif' | |
builtupBangalore = 'l5_Bangalore2011_builtup.tif' | |
mxHyderabad = 'l5_Hyderabad2011_raw.tif' | |
# Read the rasters as array | |
ds1, featuresBangalore = raster.read(mxBangalore, bands='all') |
NewerOlder