From e5ecc712050b1e31755ceb497a7069738005ebc7 Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Thu, 15 Feb 2024 12:03:31 +0100 Subject: [PATCH] Test --- lib/inat_inferrer.py | 4 ++-- lib/inat_vision_api.py | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/inat_inferrer.py b/lib/inat_inferrer.py index 8fa95d8..70143ab 100644 --- a/lib/inat_inferrer.py +++ b/lib/inat_inferrer.py @@ -90,8 +90,8 @@ def prepare_image_for_inference(self, file_path): image = tf.image.resize(image, [299, 299], tf.image.ResizeMethod.NEAREST_NEIGHBOR) result = tf.expand_dims(image, 0) END_TIME_RESIZE = time.time() - TIME_RESIZE = TIME_RESIZE + (END_TIME_RESIZE - START_TIME_RESIZE) - print("TIME-EXP: TIME_RESIZE "+str(TIME_RESIZE)) + self.TIME_RESIZE = self.TIME_RESIZE + (END_TIME_RESIZE - START_TIME_RESIZE) + print("TIME-EXP: TIME_RESIZE "+str(self.TIME_RESIZE)) return result; def vision_predict(self, image, debug=False): diff --git a/lib/inat_vision_api.py b/lib/inat_vision_api.py index e3c4300..fd57477 100644 --- a/lib/inat_vision_api.py +++ b/lib/inat_vision_api.py @@ -83,19 +83,19 @@ def bench_route(self): for i in range(start, start + count): observation_id = str( i ) + form = ImageForm() + form.score_without_geo.data = "true" + form.aggregated.data = "true" + print("TIME-EXP: score " + observation_id) START_TIME_TOTAL = time.time() image_uuid = "downloaded-obs-" + observation_id - START_TIME_DOWNLOAD = time.time() file_path, lat, lng, iconic_taxon_id = self.download_observation( observation_id, image_uuid) - END_TIME_DOWNLOAD = time.time() if file_path is None: print("TIME-EXP: obs not found") else: TOTAL_OBS = TOTAL_OBS + 1 - self.inferrer.TIME_DOWNLOAD = self.inferrer.TIME_DOWNLOAD + (END_TIME_DOWNLOAD - START_TIME_DOWNLOAD) - print("TIME-EXP: TIME_DOWNLOAD "+str(self.inferrer.TIME_DOWNLOAD)) scores = self.score_image(form, file_path, lat, lng, iconic_taxon_id, geomodel) END_TIME_TOTAL = time.time() self.inferrer.TIME_TOTAL = self.inferrer.TIME_TOTAL + (END_TIME_TOTAL - START_TIME_TOTAL) @@ -246,8 +246,12 @@ def download_observation(self, observation_id, image_uuid): return None, None, None # download the first image if it isn't already cached if not os.path.exists(cache_path): + START_TIME_DOWNLOAD = time.time() urllib.request.urlretrieve( data["results"][0]["photos"][0]["url"].replace("square", "medium"), cache_path) + END_TIME_DOWNLOAD = time.time() + self.inferrer.TIME_DOWNLOAD = self.inferrer.TIME_DOWNLOAD + (END_TIME_DOWNLOAD - START_TIME_DOWNLOAD) + 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 return cache_path, latlng[0], latlng[1], data["results"][0]["taxon"]["iconic_taxon_id"]