Views
No views yet
pip install transformers torch torchvision pillow requests1from transformers import pipeline
2from PIL import Image
3import requests
4from io import BytesIO
5
6# Load the image classification pipeline
7pipe = pipeline("image-classification", model="Luwayy/disaster_images_model")
8
9# Load an image from a URL
10url = 'https://www.spml.co.in/Images/blog/wdt&c-152776632.jpg'
11response = requests.get(url)
12image = Image.open(BytesIO(response.content))
13
14# Classify the image
15results = pipe(image)
16
17# Print results
18print(results)1[
2 {"label": "Water_Disaster", "score": 0.9184},
3 {"label": "Land_Disaster", "score": 0.0200},
4 {"label": "Non_Damage", "score": 0.0169},
5 {"label": "Human_Damage", "score": 0.0164},
6 {"label": "Fire_Disaster", "score": 0.0143}
7]google/vit-base-patch16-224-in21kViTForImageClassification)Damaged_InfrastructureFire_DisasterHuman_DamageLand_DisasterNon_DamageWater_Disaster[0.5, 0.5, 0.5], Std [0.5, 0.5, 0.5]224x2243e-50.01