niobures commited on
Commit
e963743
·
verified ·
1 Parent(s): f564d76

GeoCLIP (code, colab, models)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +3 -0
  2. GeoCLIP. Clip-Inspired Alignment between Locations and Images for Effective Worldwide Geo-localization.pdf +3 -0
  3. GeoClip. Geometry-Aware Clipping for Differentially Private SGD.pdf +3 -0
  4. Supplementary for 'GeoCLIP. Clip-Inspired Alignment between Locations and Images for Effective Worldwide Geo-localization'.pdf +3 -0
  5. code/geo-clip [cem-sirin] +6 -17.zip +3 -0
  6. code/geo-clip [selenasun1618] +16 -1.zip +3 -0
  7. code/geo-clip.zip +3 -0
  8. colab/GeoCLIP_Demo.ipynb +0 -0
  9. models/geo-clip/fine_tuned_image_encoder_mlp_weights_08-29-02_48.pth +3 -0
  10. models/geo-clip/fine_tuned_location_encoder_weights_08-29-02_48.pth +3 -0
  11. models/geo-clip/fine_tuned_logit_scale_weights_08-29-02_48.pth +3 -0
  12. models/geo-clip/image_encoder_mlp_weights.pth +3 -0
  13. models/geo-clip/location_encoder_weights.pth +3 -0
  14. models/geo-clip/logit_scale_weights.pth +3 -0
  15. models/geo-clip/source.txt +1 -0
  16. models/geoCLIP-tiny-resisc45/.gitattributes +35 -0
  17. models/geoCLIP-tiny-resisc45/README.md +29 -0
  18. models/geoCLIP-tiny-resisc45/loss_curve_20251008_025207.png +0 -0
  19. models/geoCLIP-tiny-resisc45/meta.json +7 -0
  20. models/geoCLIP-tiny-resisc45/retrieval_bar_20251008_025208.png +0 -0
  21. models/geoCLIP-tiny-resisc45/source.txt +1 -0
  22. models/geoCLIP-tiny-resisc45/tiny_geoclip_tinyset.pt +3 -0
  23. models/geoclip-large-patch14/.gitattributes +35 -0
  24. models/geoclip-large-patch14/README.md +120 -0
  25. models/geoclip-large-patch14/config.json +94 -0
  26. models/geoclip-large-patch14/gps_gallery/coordinates_100K.bin +3 -0
  27. models/geoclip-large-patch14/gps_gallery/coordinates_100K.csv +0 -0
  28. models/geoclip-large-patch14/gps_gallery/coordinates_100K.json +0 -0
  29. models/geoclip-large-patch14/onnx/location_model.onnx +3 -0
  30. models/geoclip-large-patch14/onnx/location_model_bnb4.onnx +3 -0
  31. models/geoclip-large-patch14/onnx/location_model_fp16.onnx +3 -0
  32. models/geoclip-large-patch14/onnx/location_model_int8.onnx +3 -0
  33. models/geoclip-large-patch14/onnx/location_model_q4.onnx +3 -0
  34. models/geoclip-large-patch14/onnx/location_model_quantized.onnx +3 -0
  35. models/geoclip-large-patch14/onnx/location_model_uint8.onnx +3 -0
  36. models/geoclip-large-patch14/onnx/vision_model.onnx +3 -0
  37. models/geoclip-large-patch14/onnx/vision_model_bnb4.onnx +3 -0
  38. models/geoclip-large-patch14/onnx/vision_model_fp16.onnx +3 -0
  39. models/geoclip-large-patch14/onnx/vision_model_int8.onnx +3 -0
  40. models/geoclip-large-patch14/onnx/vision_model_q4.onnx +3 -0
  41. models/geoclip-large-patch14/onnx/vision_model_quantized.onnx +3 -0
  42. models/geoclip-large-patch14/onnx/vision_model_uint8.onnx +3 -0
  43. models/geoclip-large-patch14/preprocessor_config.json +19 -0
  44. models/geoclip-large-patch14/quantize_config.json +189 -0
  45. models/geoclip-large-patch14/source.txt +1 -0
  46. models/geoclip-location-encoder/.gitattributes +35 -0
  47. models/geoclip-location-encoder/README.md +9 -0
  48. models/geoclip-location-encoder/config.json +11 -0
  49. models/geoclip-location-encoder/model.py +133 -0
  50. models/geoclip-location-encoder/model.safetensors +3 -0
.gitattributes CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ GeoCLIP.[[:space:]]Clip-Inspired[[:space:]]Alignment[[:space:]]between[[:space:]]Locations[[:space:]]and[[:space:]]Images[[:space:]]for[[:space:]]Effective[[:space:]]Worldwide[[:space:]]Geo-localization.pdf filter=lfs diff=lfs merge=lfs -text
37
+ GeoClip.[[:space:]]Geometry-Aware[[:space:]]Clipping[[:space:]]for[[:space:]]Differentially[[:space:]]Private[[:space:]]SGD.pdf filter=lfs diff=lfs merge=lfs -text
38
+ Supplementary[[:space:]]for[[:space:]]'GeoCLIP.[[:space:]]Clip-Inspired[[:space:]]Alignment[[:space:]]between[[:space:]]Locations[[:space:]]and[[:space:]]Images[[:space:]]for[[:space:]]Effective[[:space:]]Worldwide[[:space:]]Geo-localization'.pdf filter=lfs diff=lfs merge=lfs -text
GeoCLIP. Clip-Inspired Alignment between Locations and Images for Effective Worldwide Geo-localization.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:527fd1adeaa863c270a0c9872844ddecedb0ddeb722db73d8a9fe1bc5f8256a8
3
+ size 3248321
GeoClip. Geometry-Aware Clipping for Differentially Private SGD.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7d0d754ea9b5cb2c8977f66b7cda5f2e218fa47956c52a116d5551aa8759b46f
3
+ size 524315
Supplementary for 'GeoCLIP. Clip-Inspired Alignment between Locations and Images for Effective Worldwide Geo-localization'.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:20feb304ad99150b8a4a73dd262f7b171191da1ba93a77452e51ae9a411e6ebc
3
+ size 7881434
code/geo-clip [cem-sirin] +6 -17.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e389616b38d51da3bda1c74b1096e477e2cc4995b1fa3c34fe245618fb0c4d74
3
+ size 85449819
code/geo-clip [selenasun1618] +16 -1.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:db8569bdea467a25983c9f5db7481e949feae3a5f6d4164d44b60646ef102cd9
3
+ size 5909705230
code/geo-clip.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d3558bfb9b9af0d66b39c77f9e334194541a526556ef6375d4a53580dfc8c5ce
3
+ size 86482350
colab/GeoCLIP_Demo.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
models/geo-clip/fine_tuned_image_encoder_mlp_weights_08-29-02_48.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:affbfd638cb4eca4f02c4f907b966be5bc8b415f20f13ef0eb27c4d0ced4d97c
3
+ size 3939800
models/geo-clip/fine_tuned_location_encoder_weights_08-29-02_48.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4d7bcb338186bbb9f0b17e42264f35cc605bca4ed3ff378e423ad268004d2772
3
+ size 37809053
models/geo-clip/fine_tuned_logit_scale_weights_08-29-02_48.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b48105180ed9d6d75557abb0529e816df9229a82517749e47783140a052707ab
3
+ size 1483
models/geo-clip/image_encoder_mlp_weights.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5342c391eec961796d04d02f2bd670bfa97b34ce32c656d0e0676581103c2c14
3
+ size 3938907
models/geo-clip/location_encoder_weights.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:94b80ae3af89fca78539e129dd2929d321247f5ceeeb0a31bc2c31041a253394
3
+ size 37806041
models/geo-clip/logit_scale_weights.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9568e2e09dd19083082bf285b2c0c126867e40dbd275a8ee8c621888b861904e
3
+ size 759
models/geo-clip/source.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ https://github.com/selenasun1618/geo-clip
models/geoCLIP-tiny-resisc45/.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
models/geoCLIP-tiny-resisc45/README.md ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+ library_name: transformers
4
+ tags:
5
+ - clip
6
+ - satellite
7
+ - geolocation
8
+ - resisc45
9
+ ---
10
+
11
+ # 🌍 GeoCLIP – Tiny CLIP Trained on RESISC45 (Satellite Scenes)
12
+
13
+ Fine-tuned Tiny CLIP (≈ 19 M params) from scratch on **RESISC45** satellite scenes.
14
+ Pairs: *(image, "A satellite image of {label}")*
15
+
16
+ ## Training Summary
17
+ | Parameter | Value |
18
+ |:--|--:|
19
+ | Steps | 300 (tiny subset) |
20
+ | Optimizer | AdamW (3e-4 lr) |
21
+ | Loss ↓ | 1.49 (final) |
22
+ | Retrieval Top-5 ↑ | ≈ 15 % |
23
+
24
+ ## Visuals
25
+ ![Loss curve](loss_curve_20251008_025207.png)
26
+ ![Retrieval bar](retrieval_bar_20251008_025208.png)
27
+
28
+ ---
29
+ Generated 2025-10-08 02:58 UTC
models/geoCLIP-tiny-resisc45/loss_curve_20251008_025207.png ADDED
models/geoCLIP-tiny-resisc45/meta.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "draft": "edt-transformers-project-draft2",
3
+ "created_at": "2025-10-07T23:56:58.826549+00:00",
4
+ "subset_size": 512,
5
+ "steps": 300,
6
+ "batch": 32
7
+ }
models/geoCLIP-tiny-resisc45/retrieval_bar_20251008_025208.png ADDED
models/geoCLIP-tiny-resisc45/source.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ https://huggingface.co/paph3285/geoCLIP-tiny-resisc45
models/geoCLIP-tiny-resisc45/tiny_geoclip_tinyset.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9c72ebc3780ccde8039a1262dbd828a20bd0e60d44e69de1ed52334dd91e463f
3
+ size 77504316
models/geoclip-large-patch14/.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
models/geoclip-large-patch14/README.md ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ library_name: transformers.js
4
+ ---
5
+
6
+ https://github.com/VicenteVivan/geo-clip with ONNX weights to be compatible with Transformers.js.
7
+
8
+ ## Usage (Transformers.js)
9
+
10
+ If you haven't already, you can install the [Transformers.js](https://huggingface.co/docs/transformers.js) JavaScript library from [NPM](https://www.npmjs.com/package/@xenova/transformers) using:
11
+ ```bash
12
+ npm i @xenova/transformers
13
+ ```
14
+
15
+ **Example:** Perform worldwide image geolocalization.
16
+ ```js
17
+ import { AutoModel, AutoProcessor, RawImage, Tensor, dot, softmax } from '@xenova/transformers';
18
+
19
+ // Load vision and location models
20
+ const model_id = 'Xenova/geoclip-large-patch14';
21
+ const vision_model = await AutoModel.from_pretrained(model_id, {
22
+ model_file_name: 'vision_model',
23
+ });
24
+ const location_model = await AutoModel.from_pretrained(model_id, {
25
+ model_file_name: 'location_model',
26
+ quantized: false,
27
+ });
28
+
29
+ // Load image processor
30
+ const processor = await AutoProcessor.from_pretrained('openai/clip-vit-large-patch14');
31
+
32
+ // Read and preprocess image
33
+ const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/moraine-lake.png';
34
+ const image = await RawImage.fromURL(url);
35
+ const vision_inputs = await processor(image);
36
+
37
+ // Compute image embeddings
38
+ const { image_embeds } = await vision_model(vision_inputs);
39
+ const norm_image_embeds = image_embeds.normalize().data;
40
+
41
+ // Define a list of candidate GPS coordinates
42
+ // https://github.com/VicenteVivan/geo-clip/blob/main/geoclip/model/gps_gallery/coordinates_100K.csv
43
+ const coordinate_data = 'https://huggingface.co/Xenova/geoclip-large-patch14/resolve/main/gps_gallery/coordinates_100K.json';
44
+ const gps_data = await (await fetch(coordinate_data)).json();
45
+
46
+ // Compute location embeddings and compare to image embeddings
47
+ const coordinate_batch_size = 512;
48
+ const exp_logit_scale = Math.exp(3.681034803390503); // Used for scaling logits
49
+ const scores = [];
50
+ for (let i = 0; i < gps_data.length; i += coordinate_batch_size) {
51
+ const chunk = gps_data.slice(i, i + coordinate_batch_size);
52
+
53
+ const { location_embeds } = await location_model({
54
+ location: new Tensor('float32', chunk.flat(), [chunk.length, 2])
55
+ });
56
+
57
+ const norm_location_embeds = location_embeds.normalize().tolist();
58
+ for (const embed of norm_location_embeds) {
59
+ const score = exp_logit_scale * dot(norm_image_embeds, embed);
60
+ scores.push(score);
61
+ }
62
+ }
63
+
64
+ // Get top predictions
65
+ const top_k = 50;
66
+ const results = softmax(scores)
67
+ .map((x, i) => [x, i])
68
+ .sort((a, b) => b[0] - a[0])
69
+ .slice(0, top_k)
70
+ .map(([score, index]) => ({ index, gps: gps_data[index], score }));
71
+
72
+ console.log('=======================');
73
+ console.log('Top 5 GPS Predictions 📍');
74
+ console.log('=======================');
75
+ for (let i = 0; i < 5; ++i) {
76
+ console.log(results[i]);
77
+ }
78
+ console.log('=======================');
79
+ ```
80
+
81
+ Outputs:
82
+ ```
83
+ =======================
84
+ Top 5 GPS Predictions 📍
85
+ =======================
86
+ {
87
+ index: 75129,
88
+ gps: [ 51.327447, -116.183509 ],
89
+ score: 0.06895832493631944
90
+ }
91
+ {
92
+ index: 5158,
93
+ gps: [ 51.326401, -116.18263 ],
94
+ score: 0.06843383108770337
95
+ }
96
+ {
97
+ index: 77752,
98
+ gps: [ 51.328198, -116.180934 ],
99
+ score: 0.06652924543010541
100
+ }
101
+ {
102
+ index: 32529,
103
+ gps: [ 51.327809, -116.180334 ],
104
+ score: 0.065981075526145
105
+ }
106
+ {
107
+ index: 461,
108
+ gps: [ 51.322353, -116.18557 ],
109
+ score: 0.06476605375767822
110
+ }
111
+ =======================
112
+ ```
113
+
114
+ As seen on the map, this is indeed the location of [Moraine Lake](https://en.wikipedia.org/wiki/Moraine_Lake) in Canada.
115
+
116
+ ![image/png](https://cdn-uploads.huggingface.co/production/uploads/61b253b7ac5ecaae3d1efe0c/ThtHHkOmXEll2tyGV85GY.png)
117
+
118
+ ---
119
+
120
+ Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).
models/geoclip-large-patch14/config.json ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "geoclip",
3
+ "projection_dim": 768,
4
+ "location_config": {
5
+ "sigma": [1, 16, 256],
6
+ "n": 3,
7
+ "input_size": 2,
8
+ "encoded_size": 256
9
+ },
10
+ "location_config_dict": {},
11
+ "torch_dtype": "float32",
12
+ "transformers_version": null,
13
+ "vision_config": {
14
+ "_name_or_path": "",
15
+ "add_cross_attention": false,
16
+ "architectures": null,
17
+ "attention_dropout": 0.0,
18
+ "bad_words_ids": null,
19
+ "bos_token_id": null,
20
+ "chunk_size_feed_forward": 0,
21
+ "cross_attention_hidden_size": null,
22
+ "decoder_start_token_id": null,
23
+ "diversity_penalty": 0.0,
24
+ "do_sample": false,
25
+ "dropout": 0.0,
26
+ "early_stopping": false,
27
+ "encoder_no_repeat_ngram_size": 0,
28
+ "eos_token_id": null,
29
+ "finetuning_task": null,
30
+ "forced_bos_token_id": null,
31
+ "forced_eos_token_id": null,
32
+ "hidden_act": "quick_gelu",
33
+ "hidden_size": 1024,
34
+ "id2label": {
35
+ "0": "LABEL_0",
36
+ "1": "LABEL_1"
37
+ },
38
+ "image_size": 224,
39
+ "initializer_factor": 1.0,
40
+ "initializer_range": 0.02,
41
+ "intermediate_size": 4096,
42
+ "is_decoder": false,
43
+ "is_encoder_decoder": false,
44
+ "label2id": {
45
+ "LABEL_0": 0,
46
+ "LABEL_1": 1
47
+ },
48
+ "layer_norm_eps": 1e-05,
49
+ "length_penalty": 1.0,
50
+ "max_length": 20,
51
+ "min_length": 0,
52
+ "model_type": "clip_vision_model",
53
+ "no_repeat_ngram_size": 0,
54
+ "num_attention_heads": 16,
55
+ "num_beam_groups": 1,
56
+ "num_beams": 1,
57
+ "num_hidden_layers": 24,
58
+ "num_return_sequences": 1,
59
+ "output_attentions": false,
60
+ "output_hidden_states": false,
61
+ "output_scores": false,
62
+ "pad_token_id": null,
63
+ "patch_size": 14,
64
+ "prefix": null,
65
+ "problem_type": null,
66
+ "projection_dim" : 768,
67
+ "pruned_heads": {},
68
+ "remove_invalid_values": false,
69
+ "repetition_penalty": 1.0,
70
+ "return_dict": true,
71
+ "return_dict_in_generate": false,
72
+ "sep_token_id": null,
73
+ "task_specific_params": null,
74
+ "temperature": 1.0,
75
+ "tie_encoder_decoder": false,
76
+ "tie_word_embeddings": true,
77
+ "tokenizer_class": null,
78
+ "top_k": 50,
79
+ "top_p": 1.0,
80
+ "torch_dtype": null,
81
+ "torchscript": false,
82
+ "transformers_version": "4.16.0.dev0",
83
+ "use_bfloat16": false
84
+ },
85
+ "vision_config_dict": {
86
+ "hidden_size": 1024,
87
+ "intermediate_size": 4096,
88
+ "num_attention_heads": 16,
89
+ "num_hidden_layers": 24,
90
+ "patch_size": 14,
91
+ "projection_dim": 768
92
+ },
93
+ "logit_scale": 3.681034803390503
94
+ }
models/geoclip-large-patch14/gps_gallery/coordinates_100K.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:428bce04a09f854bbd4c09b97b7cabccda9cc9d2debc073145e10ccab228979f
3
+ size 800000
models/geoclip-large-patch14/gps_gallery/coordinates_100K.csv ADDED
The diff for this file is too large to render. See raw diff
 
models/geoclip-large-patch14/gps_gallery/coordinates_100K.json ADDED
The diff for this file is too large to render. See raw diff
 
models/geoclip-large-patch14/onnx/location_model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b6f75032491fd06e9d37d4d0353e5904c96edd49ee2858358644829a408a0269
3
+ size 37808863
models/geoclip-large-patch14/onnx/location_model_bnb4.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1d5d2aace73c62dedba19a13557ebe0940e6b310845ec26e05346ac3ffa83a8d
3
+ size 37804052
models/geoclip-large-patch14/onnx/location_model_fp16.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:33a69e22b6b91331327f01621ed93c1e022de98e5df9b2303771f48b15cbb645
3
+ size 18914915
models/geoclip-large-patch14/onnx/location_model_int8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c605968905a634392587673203a75e87b912e61dcb6b8a63d6c94998d7a295f2
3
+ size 9515134
models/geoclip-large-patch14/onnx/location_model_q4.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d931f22d5db007a65cff24f69c725b7278a8b866cba1e14a70ee05107f7c1662
3
+ size 37818536
models/geoclip-large-patch14/onnx/location_model_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c605968905a634392587673203a75e87b912e61dcb6b8a63d6c94998d7a295f2
3
+ size 9515134
models/geoclip-large-patch14/onnx/location_model_uint8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cd8c60f5d945f7f1f7de595990137837844f82a2d2491287da898ed82841e419
3
+ size 9515146
models/geoclip-large-patch14/onnx/vision_model.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be5e445d71789363360e94657263e077ebbc21111526209707c31ff61c2acfaa
3
+ size 1220407251
models/geoclip-large-patch14/onnx/vision_model_bnb4.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b87bc1ac7987b8f4fe74a7582b050eb15862d41b973117ea7be15daf176f3028
3
+ size 179636432
models/geoclip-large-patch14/onnx/vision_model_fp16.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8b6d557e7e927adfe4fd3524987ccbfac88e5a4282e9c0d815b2aef5af4c86db
3
+ size 610739002
models/geoclip-large-patch14/onnx/vision_model_int8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ce2a0aa90833e4b6c67a2e06464acce0d70183ae3b8443ac13e4f9d14853023a
3
+ size 306961304
models/geoclip-large-patch14/onnx/vision_model_q4.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:56ab09986e2645d40d1f1699cb26440f515df27babd4c283f0851b18eeffc310
3
+ size 198558769
models/geoclip-large-patch14/onnx/vision_model_quantized.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e1507d402874d8b408f46b7dff5076e834fd9fcb3330d7af0727b34632119f4
3
+ size 306961380
models/geoclip-large-patch14/onnx/vision_model_uint8.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5e1507d402874d8b408f46b7dff5076e834fd9fcb3330d7af0727b34632119f4
3
+ size 306961380
models/geoclip-large-patch14/preprocessor_config.json ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "crop_size": 224,
3
+ "do_center_crop": true,
4
+ "do_normalize": true,
5
+ "do_resize": true,
6
+ "feature_extractor_type": "CLIPFeatureExtractor",
7
+ "image_mean": [
8
+ 0.48145466,
9
+ 0.4578275,
10
+ 0.40821073
11
+ ],
12
+ "image_std": [
13
+ 0.26862954,
14
+ 0.26130258,
15
+ 0.27577711
16
+ ],
17
+ "resample": 3,
18
+ "size": 224
19
+ }
models/geoclip-large-patch14/quantize_config.json ADDED
@@ -0,0 +1,189 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "fp16": {},
3
+ "q8": {
4
+ "per_model_config": {
5
+ "vision_model": {
6
+ "op_types": [
7
+ "Add",
8
+ "Cast",
9
+ "Concat",
10
+ "Constant",
11
+ "ConstantOfShape",
12
+ "Conv",
13
+ "Div",
14
+ "Equal",
15
+ "Expand",
16
+ "Gather",
17
+ "Gemm",
18
+ "MatMul",
19
+ "Mul",
20
+ "Pow",
21
+ "ReduceMean",
22
+ "Relu",
23
+ "Reshape",
24
+ "Shape",
25
+ "Sigmoid",
26
+ "Slice",
27
+ "Softmax",
28
+ "Sqrt",
29
+ "Sub",
30
+ "Transpose",
31
+ "Unsqueeze",
32
+ "Where"
33
+ ],
34
+ "weight_type": "QUInt8"
35
+ },
36
+ "location_model": {
37
+ "op_types": [
38
+ "Add",
39
+ "Asin",
40
+ "Cast",
41
+ "Concat",
42
+ "Constant",
43
+ "ConstantOfShape",
44
+ "Cos",
45
+ "Div",
46
+ "Gather",
47
+ "Gemm",
48
+ "MatMul",
49
+ "Mul",
50
+ "Pow",
51
+ "Relu",
52
+ "Shape",
53
+ "Sin",
54
+ "Unsqueeze"
55
+ ],
56
+ "weight_type": "QInt8"
57
+ }
58
+ },
59
+ "per_channel": false,
60
+ "reduce_range": false
61
+ },
62
+ "int8": {
63
+ "per_model_config": {
64
+ "vision_model": {
65
+ "op_types": [
66
+ "Add",
67
+ "Cast",
68
+ "Concat",
69
+ "Constant",
70
+ "ConstantOfShape",
71
+ "Conv",
72
+ "Div",
73
+ "Equal",
74
+ "Expand",
75
+ "Gather",
76
+ "Gemm",
77
+ "MatMul",
78
+ "Mul",
79
+ "Pow",
80
+ "ReduceMean",
81
+ "Relu",
82
+ "Reshape",
83
+ "Shape",
84
+ "Sigmoid",
85
+ "Slice",
86
+ "Softmax",
87
+ "Sqrt",
88
+ "Sub",
89
+ "Transpose",
90
+ "Unsqueeze",
91
+ "Where"
92
+ ],
93
+ "weight_type": "QInt8"
94
+ },
95
+ "location_model": {
96
+ "op_types": [
97
+ "Add",
98
+ "Asin",
99
+ "Cast",
100
+ "Concat",
101
+ "Constant",
102
+ "ConstantOfShape",
103
+ "Cos",
104
+ "Div",
105
+ "Gather",
106
+ "Gemm",
107
+ "MatMul",
108
+ "Mul",
109
+ "Pow",
110
+ "Relu",
111
+ "Shape",
112
+ "Sin",
113
+ "Unsqueeze"
114
+ ],
115
+ "weight_type": "QInt8"
116
+ }
117
+ },
118
+ "per_channel": false,
119
+ "reduce_range": false
120
+ },
121
+ "uint8": {
122
+ "per_model_config": {
123
+ "vision_model": {
124
+ "op_types": [
125
+ "Add",
126
+ "Cast",
127
+ "Concat",
128
+ "Constant",
129
+ "ConstantOfShape",
130
+ "Conv",
131
+ "Div",
132
+ "Equal",
133
+ "Expand",
134
+ "Gather",
135
+ "Gemm",
136
+ "MatMul",
137
+ "Mul",
138
+ "Pow",
139
+ "ReduceMean",
140
+ "Relu",
141
+ "Reshape",
142
+ "Shape",
143
+ "Sigmoid",
144
+ "Slice",
145
+ "Softmax",
146
+ "Sqrt",
147
+ "Sub",
148
+ "Transpose",
149
+ "Unsqueeze",
150
+ "Where"
151
+ ],
152
+ "weight_type": "QUInt8"
153
+ },
154
+ "location_model": {
155
+ "op_types": [
156
+ "Add",
157
+ "Asin",
158
+ "Cast",
159
+ "Concat",
160
+ "Constant",
161
+ "ConstantOfShape",
162
+ "Cos",
163
+ "Div",
164
+ "Gather",
165
+ "Gemm",
166
+ "MatMul",
167
+ "Mul",
168
+ "Pow",
169
+ "Relu",
170
+ "Shape",
171
+ "Sin",
172
+ "Unsqueeze"
173
+ ],
174
+ "weight_type": "QUInt8"
175
+ }
176
+ },
177
+ "per_channel": false,
178
+ "reduce_range": false
179
+ },
180
+ "q4": {
181
+ "block_size": 32,
182
+ "is_symmetric": true,
183
+ "accuracy_level": null
184
+ },
185
+ "bnb4": {
186
+ "block_size": 64,
187
+ "quant_type": 1
188
+ }
189
+ }
models/geoclip-large-patch14/source.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ https://huggingface.co/Xenova/geoclip-large-patch14
models/geoclip-location-encoder/.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
models/geoclip-location-encoder/README.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - model_hub_mixin
4
+ - pytorch_model_hub_mixin
5
+ ---
6
+
7
+ This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:
8
+ - Library: [More Information Needed]
9
+ - Docs: [More Information Needed]
models/geoclip-location-encoder/config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "dim": 512,
3
+ "encoded_size": 256,
4
+ "input_size": 2,
5
+ "sigma": [
6
+ 1,
7
+ 16,
8
+ 256
9
+ ],
10
+ "transformers_version": "4.45.2"
11
+ }
models/geoclip-location-encoder/model.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+ from typing import Optional
4
+ from torch import Tensor
5
+ import numpy as np
6
+ from huggingface_hub import PyTorchModelHubMixin
7
+
8
+ # Constants
9
+ A1 = 1.340264
10
+ A2 = -0.081106
11
+ A3 = 0.000893
12
+ A4 = 0.003796
13
+ SF = 66.50336
14
+
15
+ @torch.jit.script
16
+ def gaussian_encoding(
17
+ v: Tensor,
18
+ b: Tensor) -> Tensor:
19
+ r"""Computes :math:`\gamma(\mathbf{v}) = (\cos{2 \pi \mathbf{B} \mathbf{v}} , \sin{2 \pi \mathbf{B} \mathbf{v}})`
20
+
21
+ Args:
22
+ v (Tensor): input tensor of shape :math:`(N, *, \text{input_size})`
23
+ b (Tensor): projection matrix of shape :math:`(\text{encoded_layer_size}, \text{input_size})`
24
+
25
+ Returns:
26
+ Tensor: mapped tensor of shape :math:`(N, *, 2 \cdot \text{encoded_layer_size})`
27
+
28
+ See :class:`~rff.layers.GaussianEncoding` for more details.
29
+ """
30
+ vp = 2 * np.pi * v @ b.T
31
+ return torch.cat((torch.cos(vp), torch.sin(vp)), dim=-1)
32
+
33
+
34
+ def sample_b(sigma: float, size: tuple) -> Tensor:
35
+ r"""Matrix of size :attr:`size` sampled from from :math:`\mathcal{N}(0, \sigma^2)`
36
+
37
+ Args:
38
+ sigma (float): standard deviation
39
+ size (tuple): size of the matrix sampled
40
+
41
+ See :class:`~rff.layers.GaussianEncoding` for more details
42
+ """
43
+ return torch.randn(size) * sigma
44
+
45
+ class GaussianEncoding(nn.Module):
46
+ """Layer for mapping coordinates using random Fourier features"""
47
+
48
+ def __init__(self, sigma: Optional[float] = None,
49
+ input_size: Optional[float] = None,
50
+ encoded_size: Optional[float] = None,
51
+ b: Optional[Tensor] = None):
52
+ r"""
53
+ Args:
54
+ sigma (Optional[float]): standard deviation
55
+ input_size (Optional[float]): the number of input dimensions
56
+ encoded_size (Optional[float]): the number of dimensions the `b` matrix maps to
57
+ b (Optional[Tensor], optional): Optionally specify a :attr:`b` matrix already sampled
58
+ Raises:
59
+ ValueError:
60
+ If :attr:`b` is provided and one of :attr:`sigma`, :attr:`input_size`,
61
+ or :attr:`encoded_size` is provided. If :attr:`b` is not provided and one of
62
+ :attr:`sigma`, :attr:`input_size`, or :attr:`encoded_size` is not provided.
63
+ """
64
+ super().__init__()
65
+ if b is None:
66
+ if sigma is None or input_size is None or encoded_size is None:
67
+ raise ValueError(
68
+ 'Arguments "sigma," "input_size," and "encoded_size" are required.')
69
+
70
+ b = sample_b(sigma, (encoded_size, input_size))
71
+ elif sigma is not None or input_size is not None or encoded_size is not None:
72
+ raise ValueError('Only specify the "b" argument when using it.')
73
+ self.b = nn.parameter.Parameter(b, requires_grad=False)
74
+
75
+ def forward(self, v: Tensor) -> Tensor:
76
+ r"""Computes :math:`\gamma(\mathbf{v}) = (\cos{2 \pi \mathbf{B} \mathbf{v}} , \sin{2 \pi \mathbf{B} \mathbf{v}})`
77
+
78
+ Args:
79
+ v (Tensor): input tensor of shape :math:`(N, *, \text{input_size})`
80
+
81
+ Returns:
82
+ Tensor: Tensor mapping using random fourier features of shape :math:`(N, *, 2 \cdot \text{encoded_size})`
83
+ """
84
+ return gaussian_encoding(v, self.b)
85
+
86
+ def equal_earth_projection(L):
87
+ latitude = L[:, 0]
88
+ longitude = L[:, 1]
89
+ latitude_rad = torch.deg2rad(latitude)
90
+ longitude_rad = torch.deg2rad(longitude)
91
+ sin_theta = (torch.sqrt(torch.tensor(3.0)) / 2) * torch.sin(latitude_rad)
92
+ theta = torch.asin(sin_theta)
93
+ denominator = 3 * (9 * A4 * theta**8 + 7 * A3 * theta**6 + 3 * A2 * theta**2 + A1)
94
+ x = (2 * torch.sqrt(torch.tensor(3.0)) * longitude_rad * torch.cos(theta)) / denominator
95
+ y = A4 * theta**9 + A3 * theta**7 + A2 * theta**3 + A1 * theta
96
+ return (torch.stack((x, y), dim=1) * SF) / 180
97
+
98
+ class LocationEncoderCapsule(nn.Module):
99
+ def __init__(self, sigma):
100
+ super(LocationEncoderCapsule, self).__init__()
101
+ rff_encoding = GaussianEncoding(sigma=sigma, input_size=2, encoded_size=256)
102
+ self.km = sigma
103
+ self.capsule = nn.Sequential(rff_encoding,
104
+ nn.Linear(512, 1024),
105
+ nn.ReLU(),
106
+ nn.Linear(1024, 1024),
107
+ nn.ReLU(),
108
+ nn.Linear(1024, 1024),
109
+ nn.ReLU())
110
+ self.head = nn.Sequential(nn.Linear(1024, 512))
111
+
112
+ def forward(self, x):
113
+ x = self.capsule(x)
114
+ x = self.head(x)
115
+ return x
116
+
117
+ class LocationEncoder(nn.Module, PyTorchModelHubMixin):
118
+ def __init__(self):
119
+ super(LocationEncoder, self).__init__()
120
+ self.sigma = [2**0, 2**4, 2**8]
121
+ self.n = len(self.sigma)
122
+
123
+ for i, s in enumerate(self.sigma):
124
+ self.add_module('LocEnc' + str(i), LocationEncoderCapsule(sigma=s))
125
+
126
+ def forward(self, location):
127
+ location = equal_earth_projection(location)
128
+ location_features = torch.zeros(location.shape[0], 512).to(location.device)
129
+
130
+ for i in range(self.n):
131
+ location_features += self._modules['LocEnc' + str(i)](location)
132
+
133
+ return location_features
models/geoclip-location-encoder/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:02b8fc91b9857c6db2bd7f8808df2f34a25d2e279d4b5ae7447510d31bf75913
3
+ size 37800376