Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvain-morin committed Feb 15, 2024
1 parent 10c4bda commit aadd81b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/inat_inferrer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, config):
self.upload_folder = "static/"
self.TIME_DOWNLOAD = 0
self.TIME_RESIZE = 0
self.TIME_API = 0
self.TIME_TOTAL = 0

def setup_taxonomy(self, config):
Expand Down
10 changes: 7 additions & 3 deletions lib/inat_vision_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def bench_route(self):
form.geomodel.data = "true"
geomodel = form.geomodel.data

print("TIME-EXP: #" + TOTAL_OBS)
print("TIME-EXP: score " + observation_id)
START_TIME_TOTAL = time.time()
image_uuid = "downloaded-obs-" + observation_id
Expand All @@ -102,13 +103,12 @@ def bench_route(self):
END_TIME_TOTAL = time.time()
self.inferrer.TIME_TOTAL = self.inferrer.TIME_TOTAL + (END_TIME_TOTAL - START_TIME_TOTAL)
print("TIME-EXP: TIME_TOTAL "+str(self.inferrer.TIME_TOTAL))
ALL_SCORES = ALL_SCORES + "\n" + str( scores )

result = "TOTAL = " + str(self.inferrer.TIME_TOTAL) + "\n" + \
"DOWNLOAD = " + str(self.inferrer.TIME_DOWNLOAD) + "\n" + \
"API = " + str(self.inferrer.TIME_API) + "\n" + \
"RESIZE = " + str(self.inferrer.TIME_RESIZE) + "\n" + \
"TOTAL_OBS = " + str(TOTAL_OBS) + "\n" + \
ALL_SCORES
"TOTAL_OBS = " + str(TOTAL_OBS)

return result

Expand Down Expand Up @@ -237,11 +237,13 @@ def process_upload(self, form_image_data, image_uuid):

# Fetch the observation metadata and first image using the iNaturalist API
def download_observation(self, observation_id, image_uuid):
START_TIME_API = time.time()
url = "https://api.inaturalist.org/v1/observations/" + observation_id
cache_path = os.path.join(self.upload_folder, image_uuid) + ".jpg"
# fetch observation details using the API
response = urllib.request.urlopen(url)
data = json.loads(response.read())
END_TIME_API = time.time()
if (data is None or data["results"] is None or len ( data["results"] ) == 0 or data["results"][0] is
None or data["results"][0]["photos"] is None or len ( data["results"][0]["photos"] ) == 0 or data["results"][0]["photos"][0] is
None or data["results"][0]["photos"][0]["url"] is None
Expand All @@ -253,7 +255,9 @@ def download_observation(self, observation_id, image_uuid):
urllib.request.urlretrieve(
data["results"][0]["photos"][0]["url"].replace("square", "medium"), cache_path)
END_TIME_DOWNLOAD = time.time()
self.inferrer.TIME_API = self.inferrer.TIME_API + (END_TIME_API - START_TIME_API)
self.inferrer.TIME_DOWNLOAD = self.inferrer.TIME_DOWNLOAD + (END_TIME_DOWNLOAD - START_TIME_DOWNLOAD)
print("TIME-EXP: TIME_API "+str(self.inferrer.TIME_API))
print("TIME-EXP: TIME_DOWNLOAD "+str(self.inferrer.TIME_DOWNLOAD))
latlng = data["results"][0]["location"].split(",")
# return the path to the cached image, coordinates, and iconic taxon
Expand Down

0 comments on commit aadd81b

Please sign in to comment.