From 9c7515240386f575798d6bb5d5ecb62fa3e0b21a Mon Sep 17 00:00:00 2001 From: sylvain-morin Date: Thu, 15 Feb 2024 15:48:40 +0100 Subject: [PATCH] Test --- lib/inat_inferrer.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/inat_inferrer.py b/lib/inat_inferrer.py index 9f7ad8d..a4e78c3 100644 --- a/lib/inat_inferrer.py +++ b/lib/inat_inferrer.py @@ -88,10 +88,33 @@ def prepare_image_for_inference(self, file_path): image = tf.image.convert_image_dtype(image, tf.float32) image = tf.image.central_crop(image, 0.875) image = tf.image.resize(image, [299, 299], tf.image.ResizeMethod.NEAREST_NEIGHBOR) + + filename = os.path.basename(file_path) + + # Convert the TensorFlow tensor to a NumPy array + resized_image_np = image.numpy() + + # Convert the NumPy array to a PIL Image + pil_image = Image.fromarray(np.uint8(resized_image_np)) + + # Save the PIL Image to a file + + output_file_path = '/home/inaturalist/vision/save/' + filename + pil_image.save(output_file_path) + + + image_bytes = tf.io.encode_jpeg(image) + output_file_path = '/home/inaturalist/vision/save2/' + filename + # Write the bytes to a file + with tf.io.gfile.GFile(output_file_path, 'wb') as f: + f.write(image_bytes.numpy()) + + result = tf.expand_dims(image, 0) END_TIME_RESIZE = time.time() 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):