GeoCLIP Documentation

repository·main·Indexed 18 days ago

https://github.com/vicentevivan/geo-clip

A CLIP-inspired model for aligning images with geographical locations. GeoCLIP provides tools for worldwide image geolocalization via the GeoCLIP class and GPS coordinate embedding generation via the LocationEncoder for use in geo-aware neural architectures.

Tokens
616
Snippets
3
Records
3
Agent score
14%

What's inside GeoCLIP

  1. Install GeoCLIP

    main

    You can install the GeoCLIP module using pip or by installing directly from the source code.

    # Via pip
    pip install geoclip
    
    # Or from source
    git clone https://github.com/VicenteVivan/geo-clip
    cd geo-clip
    python setup.py install
  2. Perform Worldwide Image Geolocalization with GeoCLIP

    main

    Use the GeoCLIP class to predict GPS coordinates from an image. The predict method returns the top $k$ predicted GPS coordinates (latitude and longitude) and their corresponding probabilities.

    import torch
    from geoclip import GeoCLIP
    
    model = GeoCLIP()
    
    image_path = "image.png"
    
    # Returns top k GPS predictions and probabilities
    top_pred_gps, top_pred_prob = model.predict(image_path, top_k=5)
    
    print("Top 5 GPS Predictions")
    print("=====================")
    for i in range(5):
        lat, lon = top_pred_gps[i]
        print(f"Prediction {i+1}: ({lat:.6f}, {lon:.6f})")
        print(f"Probability: {top_pred_prob[i]:.6f}")
        print("")
  3. Generate Worldwide GPS Embeddings with LocationEncoder

    main

    The LocationEncoder can be used to transform GPS coordinates (latitude and longitude) into semantically rich embeddings. These embeddings can be used to assist geo-aware neural architectures, such as concatenating them with visual features for improved multi-class classification.

    import torch
    from geoclip import LocationEncoder
    
    gps_encoder = LocationEncoder()
    
    # Input data as a tensor of [latitude, longitude]
    gps_data = torch.Tensor([[40.7128, -74.0060], [34.0522, -118.2437]])  # NYC and LA
    
    # Returns embeddings of shape (N, 512)
    gps_embeddings = gps_encoder(gps_data)
    print(gps_embeddings.shape) # (2, 512)