Image-to-Text
Transformers
PyTorch
English
Geo-Localization
kevinloeffler commited on
Commit
c9ead0f
·
verified ·
1 Parent(s): 96d4ee7

add example inference code

Browse files
Files changed (1) hide show
  1. README.md +30 -1
README.md CHANGED
@@ -45,7 +45,36 @@ supporting code pipelines.
45
  Example inference:
46
 
47
  ```
48
- # todo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  ```
50
 
51
  [More Information Needed]
 
45
  Example inference:
46
 
47
  ```
48
+ # imports
49
+ import torch
50
+ from PIL import Image
51
+
52
+ from model import LocationDecoder
53
+ from transformers import CLIPProcessor
54
+
55
+ # load custom config (do not use AutoConfig), an example can be found in this repo
56
+ config = { ... }
57
+
58
+ #
59
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
60
+ preprocessor = CLIPProcessor.from_pretrained('openai/clip-vit-large-patch14-336')
61
+ model = LocationDecoder.from_pretrained('OSTswiss/ReGeo', config=config)
62
+
63
+ # Load model for inference
64
+ model.to(device)
65
+ model.eval()
66
+
67
+ # load image
68
+ image_path = 'path/to/your/image.jpg' # can be any size
69
+ image = Image.open(image_path)
70
+ model_input = preprocessor(images=image, return_tensors="pt")
71
+ pixel_values = model_input['pixel_values'].to(device)
72
+
73
+ with torch.no_grad():
74
+ output = model(pixel_values)
75
+ normal_coordinates = output.squeeze().tolist()
76
+ latitude = normal_coordinates[0] * 90
77
+ longitude = normal_coordinates[1] * 180
78
  ```
79
 
80
  [More Information Needed]