-
Notifications
You must be signed in to change notification settings - Fork 1
/
geo_querying.py
executable file
·51 lines (40 loc) · 1.69 KB
/
geo_querying.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/home/chad/anaconda/bin/python
import sys
from pymongo import MongoClient
import numpy as np
class querying:
def __init__(self):
self.client =MongoClient()
def getCollections(self,db):
self.db =self.client[db]
def setupDB(self,db,cols):
self.db =self.client[db]
self.cols = [self.db[col] for col in cols]
# get all coordinates, predictions, and photo urls from the pre-selected collection
def getAllData(self,catfile):
categories = [line.split()[0] for line in open(catfile).readlines()]
data = []
coords = []
photos = []
for col in self.cols:
#docs = col.find({"$and":[{'prediction':{"$ne": 0}},{'prediction': {"$exists":True}}]},timeout=False)
docs = col.find({"$and":[{'prediction':{"$ne": 0}},{'prediction': {"$exists":True}}]})
for doc in docs:
if doc['prediction']:
prediction = [doc['prediction'][category] for category in categories]
coordinates = [doc['latitude'],doc['longitude']]
photo = doc['photo_file_url']
data.append(prediction)
coords.append(coordinates)
photos.append(photo)
npdata = np.asarray(data)
npcoords = np.asarray(coords)
return {'predictions':npdata,'coordinates':npcoords,'photos':photos}
if __name__=="__main__":
db ='geo'
categoriesfile ='../../caffe/models/placesCNN/categoryIndex_places205.csv'
cols =[a.decode('utf-8') for a in sys.argv[1:]]
print cols
a = querying()
a.setupDB(db,cols)
a.getAllData(categoriesfile)