Introduction
This post shows how to perform landmark image classification in Python using a Europe landmarks classifier from TensorFlow Hub.
You will load a pre-trained TensorFlow Hub landmark classification model, preprocess an image to the right size, and run fast inference to predict the landmark name.
The workflow includes reading a CSV label map, preparing the input image, executing the model, and converting the numeric prediction into a human-readable class.
This approach delivers a practical image classification Python tutorial that you can adapt to your own datasets and inputs.
If you need scalable inference, you can batch images, cache the model, and wrap the pipeline into a simple function for production use.
With a few lines of code, you get reliable TensorFlow image recognition for European landmarks with strong performance and minimal setup.
The link for the video tutorial is here : https://youtu.be/IJ5Z9Awzxr4&list=UULFTiWJJhaH6BviSWKLJUM9sg
These are the test images for classification
Landmark Classification Pipeline in Python
The following single code block covers imports, model loading from TensorFlow Hub, label mapping from a CSV file, image preprocessing to the required 321×321 shape, prediction, and ID-to-name decoding.
Every Python command includes a one-line explanation starting with ###
for easy learning and copy-paste.
#google models : #https://tfhub.dev/google/collections/landmarks/1 #inside you can choose Continent (Europe , Africa , etc .....) ### Import core numerical operations for arrays and tensors. import numpy as np ### Import pandas to read and manage the CSV label map. import pandas as pd ### Import PIL for image loading and resizing. import PIL ### Import TensorFlow for tensors, models, and inference. import tensorflow as tf ### Import TensorFlow Hub to load the pre-trained landmarks classifier. import tensorflow_hub as hub ### Store the TensorFlow Hub URL for the Europe landmarks classifier model. # copy the url from the web page : https://tfhub.dev/google/collections/landmarks/1 modelUrl = "https://tfhub.dev/google/on_device_vision/classifier/landmarks_classifier_europe_V1/1" ### Provide the local path to the label map CSV that maps class IDs to landmark names. #download the lables file from the same link # we have about 100,000 classes labels = "C:/Python-Code/ObjectDetection/Landmark-classifier/landmarks_classifier_europe_V1_label_map.csv" ### Define the input tensor shape the model expects: 321x321 RGB. # the model need image in the size of 321,321 imageShape = (321,321,3) ### Build a simple Keras Sequential model that wraps the TF-Hub layer for inference. classifier = tf.keras.Sequential( [ hub.KerasLayer(modelUrl , input_shape=imageShape , output_key="predictions:logits" ) ] ) ### Read the label CSV into a DataFrame to build an ID-to-name dictionary. # build a key and value for the lables df = pd.read_csv(labels) ### (Optional) Inspect the DataFrame to verify the label columns. print(df) ### (Optional) Preview a zip of IDs and names for sanity checks. print(zip(df.id, df.name)) ### Create and print the dictionary that maps class ID to readable landmark name. print(dict(zip(df.id, df.name))) # create a dictionaty ### Persist the dictionary for fast lookups during decoding. labelsDict = dict(zip(df.id, df.name)) ### Load a test image from disk with PIL to run a single prediction. #test an image #============= #image1 = PIL.Image.open("C:/Python-Code/ObjectDetection/Landmark-classifier/EifelTestImage.jpg") #image1 = PIL.Image.open("C:/Python-Code/ObjectDetection/Landmark-classifier/tower.jpg") image1 = PIL.Image.open("C:/Python-Code/ObjectDetection/Landmark-classifier/brandenburger-tor.jpg") ### Resize the image to the model's required 321x321 pixels. image1 = image1.resize((321,321)) ### Print size to confirm the resize worked as expected. print(image1.size) ### Convert the PIL image to a NumPy array for TensorFlow processing. # convert to Numpy Araay image1 = np.array(image1) ### Normalize pixel values to [0,1] to match common model preprocessing. image1 = image1 / 255.0 ### Check the array shape (H, W, C) before adding the batch dimension. print(image1.shape) ### Expand dimensions to add the batch axis: shape becomes (1, 321, 321, 3). # build array of images image1 = image1[np.newaxis] ### Confirm the batched tensor shape for inference. print(image1.shape) ### Run the classifier to obtain logits for all classes. result = classifier.predict(image1) ### Select the index of the highest-scoring class from the output logits. finalResult = np.argmax(result) # get the highest score index ### Map the predicted class index to a human-readable landmark name and print it. print ("The preidiction is : " + labelsDict[finalResult] )
You can find the full code here : https://ko-fi.com/s/4628cb4647
This end-to-end example shows how to load a ready-to-use Europe landmarks classifier from TensorFlow Hub, read a CSV label map, and generate top predictions for a given image.
Because the TensorFlow Hub landmark classification model is pre-trained, you avoid collecting data and training from scratch, which accelerates prototyping and improves time-to-value.
The image is resized to 321×321 pixels and normalized to floating-point values, ensuring compatibility with the model’s expected input.
After inference, the highest-probability class is extracted and decoded to a human-readable label using the dictionary derived from the CSV file, which completes the landmark image classification workflow.
This compact pattern is ideal for demos, internal tools, or educational notebooks where you want reliable TensorFlow image recognition with minimal code.
You can find more tutorials in my blog : https://eranfeit.net/blog/
Connect :
☕ Buy me a coffee — https://ko-fi.com/eranfeit
🖥️ Email : feitgemel@gmail.com
🤝 Fiverr : https://www.fiverr.com/s/mB3Pbb
Enjoy,
Eran