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 085a5c5 commit 9c75152
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/inat_inferrer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 9c75152

Please sign in to comment.