Spaces:
Runtime error
Runtime error
Lagar
commited on
Commit
•
64c32eb
1
Parent(s):
cbcdc37
add files
Browse files
Sydney_00073_1226915900_eea86783cd_1128_65768710@N00.jpg
ADDED
Tanzania_00019_1292210091_693ea74b7a_1088_15274769@N00.jpg
ADDED
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pandas as pd
|
3 |
+
import matplotlib.pylab as plt
|
4 |
+
import PIL.Image as Image
|
5 |
+
import tensorflow as tf
|
6 |
+
import tensorflow_hub as hub
|
7 |
+
import gradio as gr
|
8 |
+
from einops import rearrange
|
9 |
+
import s2cell
|
10 |
+
from geopy.geocoders import Nominatim
|
11 |
+
|
12 |
+
|
13 |
+
TF_MODEL_URL = 'https://tfhub.dev/google/planet/vision/classifier/planet_v2/1'
|
14 |
+
IMAGE_SHAPE = (299, 299)
|
15 |
+
labels=pd.read_csv('planet_v2_labelmap.csv')
|
16 |
+
classifier = tf.keras.Sequential([hub.KerasLayer(TF_MODEL_URL,
|
17 |
+
input_shape=IMAGE_SHAPE+(3,)
|
18 |
+
)])
|
19 |
+
|
20 |
+
|
21 |
+
def classify_image(image):
|
22 |
+
img = image/255.0
|
23 |
+
img = rearrange(img, 'h w c -> 1 h w c')
|
24 |
+
prediction = classifier.predict(img)
|
25 |
+
s2code = np.argmax(prediction)
|
26 |
+
loc=labels['S2CellId'][s2code]
|
27 |
+
location=s2cell.token_to_lat_lon(loc)
|
28 |
+
geolocator = Nominatim(user_agent="coordinateconverter")
|
29 |
+
address = location
|
30 |
+
location_add = geolocator.reverse(address)
|
31 |
+
return location,location_add
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
title = 'Photo Geolocation'
|
36 |
+
|
37 |
+
description = 'Just upload or drop an image to know where your photo is taken . '
|
38 |
+
|
39 |
+
article ='''PlaNet -Photo Geolocation with Convolutional Neural Networks. A gradio demo app for estimation of the address and coordinates of your photo.
|
40 |
+
<div style='text-align: center;'>PlaNet : <a href='https://tfhub.dev/google/planet/vision/classifier/planet_v2/1' target='_blank'>Github Repo</a> | <a href='https://arxiv.org/pdf/1602.05314v1.pdf' target='_blank'>Paper</a></div>'''
|
41 |
+
|
42 |
+
|
43 |
+
ex1 = 'UnitedKingdom_00019_964966881_426cf82f57_1071_98545448@N00.jpg'
|
44 |
+
ex2 = 'Tanzania_00019_1292210091_693ea74b7a_1088_15274769@N00.jpg'
|
45 |
+
|
46 |
+
iface = gr.Interface(classify_image, inputs=gr.inputs.Image(shape=(299, 299), image_mode="RGB", type="numpy"),
|
47 |
+
outputs=[gr.outputs.Textbox(label='Latitude,Longitude'),gr.outputs.Textbox(label='Address')],examples=[ex1,ex2],
|
48 |
+
live=False,layout="horizontal", interpretation=None,title=title,
|
49 |
+
description=description, article=article)
|
50 |
+
|
51 |
+
iface.launch()
|
planet_v2_labelmap.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
einops
|
3 |
+
s2cell
|
4 |
+
numpy
|
5 |
+
pandas
|
6 |
+
matplotlib.pylab
|
7 |
+
PIL
|
8 |
+
geopy.geocoders
|
9 |
+
tensorflow
|
10 |
+
tensorflow_hub
|