File size: 5,688 Bytes
06b1271
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5573119
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import os
import tensorflow as tf

class_labels = ['The Agra Fort', 'Ajanta Caves', 'Alai Darwaza', 'Amarnath Temple', 'The Amber Fort', 'Basilica of Bom Jesus', 'Brihadisvara Temple', 'Charar-e-Sharief shrine', 'Charminar', 'Chhatrapati Shivaji Terminus', 'Chota Imambara', 'Dal Lake', 'The Elephanta Caves', 'Ellora Caves', 'Fatehpur Sikri', 'Gateway of India', 'Ghats in Varanasi', 'Gol Gumbaz', 'Golden Temple', 'Group of Monuments at Mahabalipuram', 'Hampi', 'Hawa Mahal', "Humayun's Tomb", 'The India gate', 'Iron Pillar', 'Jagannath Temple, Puri', 'Jageshwar', 'Jama Masjid', 'Jamali Kamali Tomb', 'Jantar Mantar, Jaipur', 'Jantar Mantar, New Delhi', 'Kedarnath Temple', 'Khajuraho Temple', 'Konark Sun Temple', 'Mahabodhi Temple', 'Meenakshi Temple', 'Nalanda mahavihara', 'Parliament House, New Delhi', 'Qutb Minar', 'Qutb Minar Complex', 'Ram Mandir', 'Rani ki Vav', 'Rashtrapati Bhavan', 'The Red Fort', 'Sanchi', 'Supreme Court of India', 'Swaminarayan Akshardham (Delhi)', 'Taj Hotels', 'The Lotus Temple', 'The Mysore Palace', 'The Statue of Unity', 'The Taj Mahal', 'Vaishno Devi Temple', 'Venkateswara Temple, Tirumala', 'Victoria Memorial, Kolkata', 'Vivekananda Rock Memorial']

import gdown
import os
import tensorflow as tf

# URL with the file ID
#v3 - https://drive.google.com/file/d/1psuUF80mDO3EZkx2Rl9F5EkqbVHSxFqI/view?usp=sharing
#v4 - https://drive.google.com/file/d/10weM6bZ9R8xVl0KxKig9WRzss4OpIa7f/view?usp=sharing
#v5 - https://drive.google.com/file/d/1PXixJsrUaVcHEEC-jDlv4tHT2qrCrf5c/view?usp=sharing
file_id = '1PXixJsrUaVcHEEC-jDlv4tHT2qrCrf5c'  # Replace with your file ID
url = f'https://drive.google.com/uc?id={file_id}'

# Output path to save the model
output = 'LandmarkClassifierV5.h5'  # Replace with your model file name

# Download the file if it doesn't exist
if not os.path.exists(output):
    gdown.download(url, output, quiet=False)

# Load your model
def load_model():
    # Replace with code to load your actual model
    loaded_model = tf.keras.models.load_model(output)
    return loaded_model

model = load_model()

# Print model summary to verify
model.summary()

# Predict on a new image
from tensorflow.keras.preprocessing import image
import numpy as np

import requests
import numpy as np
from PIL import Image
from io import BytesIO
import matplotlib.pyplot as plt

def identify_landmark(img):
    # Preprocess the image
    img = img.resize((224, 224))
    img_array = image.img_to_array(img)
    img_array = np.expand_dims(img_array, axis=0)
    img_array /= 255.0

    # Get predictions
    predictions = model.predict(img_array)

    # Get the index of the class with the highest probability
    predicted_class_index = np.argmax(predictions[0])

    # Get the probability of the predicted class
    predicted_probability = predictions[0][predicted_class_index]

    # Map the predicted class index to the class label
    predicted_class_label = class_labels[predicted_class_index]
    
    return predicted_class_label,predicted_probability


# def identify_landmark(img):
#     img1 = img.copy()

#     # Preprocess the image
#     img = img.resize((224, 224))
#     img_array = image.img_to_array(img)
#     img_array = np.expand_dims(img_array, axis=0)
#     img_array /= 255.0

#     # Get predictions
#     predictions = model.predict(img_array)

#     # Get the index of the class with the highest probability
#     predicted_class_index = np.argmax(predictions[0])

#     # Map the predicted class index to the class label
#     return class_labels[predicted_class_index]


# def generate_landmark_path(img_path):
#     img = image.load_img(img_path, target_size=(224, 224))
#     img1 = img.copy()

#     # Preprocess the image
#     img = img.resize((224, 224))
#     img_array = image.img_to_array(img)
#     img_array = np.expand_dims(img_array, axis=0)
#     img_array /= 255.0

#     # Get predictions
#     predictions = model.predict(img_array)

#     # Get the index of the class with the highest probability
#     predicted_class_index = np.argmax(predictions[0])

#     # Map the predicted class index to the class label
#     plt.imshow(img1)
#     plt.axis("off")
#     plt.title(class_labels[predicted_class_index])
#     plt.show()
#     return wikipedia.summary(class_labels[predicted_class_index])


# def generate_landmark_url(img_url):
#     try:
#         # Download the image from the URL
#         response = requests.get(img_url)
#         response.raise_for_status()  # Check if the request was successful

#         # Open the image
#         img = Image.open(BytesIO(response.content))
#         img1 = img.copy()

#         # Preprocess the image
#         img = img.resize((224, 224))
#         img_array = image.img_to_array(img)
#         img_array = np.expand_dims(img_array, axis=0)
#         img_array /= 255.0

#         # Get predictions
#         predictions = model.predict(img_array)

#         # Get the index of the class with the highest probability
#         predicted_class_index = np.argmax(predictions[0])

#         # Map the predicted class index to the class label
#         plt.imshow(img1)
#         plt.axis("off")
#         plt.title(class_labels[predicted_class_index])
#         plt.show()

#         return wikipedia.summary(class_labels[predicted_class_index])

#     except requests.exceptions.RequestException as e:
#         print(f"Error downloading the image: {e}")
#         return "Invalid image URL."
#     except IOError as e:
#         print(f"Error opening the image: {e}")
#         return "Invalid image file."
#     except Exception as e:
#         print(f"An error occurred: {e}")
#         return "An error occurred while processing the image."