In this tutorial, we explore an innovative and practical application of the IBM Open Open source deep-50 source, which shows its ability to quickly classify satellite images for disaster management. Taking advantage of the convolutional neuronal networks (CNN) prior to the detroot, this approach empowers users to quickly analyze satellite images to identify and classify areas affected by disasters, such as floods, forest fires or damage to the earthquake. Using Google Colab, we will walk through a step -by -step process to easily configure the environment, prept images, make inferences and interpret results.
First, we install essential libraries for processing and visualization tasks based on Pytorch.
!pip install torch torchvision matplotlib pillow
We import necessary libraries and load the Resnet-50 model backed by IBM of Pytorch, preparing it for inference tasks.
import torch
import torchvision.models as models
import torchvision.transforms as transforms
from PIL import Image
import requests
from io import BytesIO
import matplotlib.pyplot as plt
model = models.resnet50(pretrained=True)
model.eval()
Now, we define the standard preprocessing pipe for the images, change the size and cut them, turning them into tensioners and normalizing them so that they coincide with the resonnet-50 input requirements.
preprocess = transforms.Compose((
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(
mean=(0.485, 0.456, 0.406),
std=(0.229, 0.224, 0.225)
)
))
Here, we recover a satellite image of a given URL, we preprocess it, we classify it using the pretrained resnet-50 model and visualize the image with its upper prediction. It also prints the five main predictions with associated probabilities.
def classify_satellite_image(url):
response = requests.get(url)
img = Image.open(BytesIO(response.content)).convert('RGB')
input_tensor = preprocess(img)
input_batch = input_tensor.unsqueeze(0)
with torch.no_grad():
output = model(input_batch)
labels_url = "https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt"
labels = requests.get(labels_url).text.split("n")
probabilities = torch.nn.functional.softmax(output(0), dim=0)
top5_prob, top5_catid = torch.topk(probabilities, 5)
plt.imshow(img)
plt.axis('off')
plt.title("Top Prediction: {}".format(labels(top5_catid(0))))
plt.show()
print("Top 5 Predictions:")
for i in range(top5_prob.size(0)):
print(labels(top5_catid(i)), top5_prob(i).item())
Finally, we download a satellite image related to the forest fire, we classify it using the previously previous Resnet-50 model and show it visually along with its five main predictions.
image_url = "https://upload.wikimedia.org/wikipedia/commons/0/05/Burnout_ops_on_Mangum_Fire_McCall_Smokejumpers.jpg"
classify_satellite_image(image_url)
In conclusion, we have successfully exploited the Open IBM Open Source model in Google Colab to efficiently classify satellite images, supporting the critical disaster evaluation and response tasks. The outlined approach demonstrates the practicality and accessibility of advanced automatic learning models and emphasizes how CNN prior to the detainee can be applied creatively to real world challenges. With a minimum configuration, we now have a powerful tool at our disposal.
Here is the Colab notebook. Besides, don't forget to follow us <a target="_blank" href="https://x.com/intent/follow?screen_name=marktechpost” target=”_blank” rel=”noreferrer noopener”>twitter and join our Telegram channel and LINKEDIN GRsplash. Do not forget to join our 85k+ ml of submen.