Created
September 13, 2023 14:23
-
-
Save Tob-iee/5a12b6783d3043924b78880585c41bfa to your computer and use it in GitHub Desktop.
Match the local copy of the images to the ones in Picsellia and push the predictions of the corresponding images to your experiment evaluation dashboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
eval_image_path = os.path.join(os.getcwd(), eval_set_local_dir) | |
list_eval_image = os.listdir(eval_image_path) | |
for img_path in list_eval_image: | |
eval_image_ = os.path.join(eval_image_path, img_path) | |
print(eval_image_) | |
eval_image = Image.open(eval_image_) | |
with torch.no_grad(): | |
inputs = image_processor(images=eval_image, return_tensors="pt") | |
outputs = model(**inputs) | |
target_sizes = torch.tensor([eval_image.size[::-1]]) | |
results = image_processor.post_process_object_detection(outputs, threshold=0.5, target_sizes=target_sizes)[0] | |
rectangles = [] # ((x, y, w, h), label, confidence) | |
for score, label, box in zip(results["scores"], results["labels"], results["boxes"]): | |
fname = eval_image_.split('/')[-1] | |
asset = picsellia_eval_ds.find_asset(filename=fname) | |
box = [int(i) for i in box.tolist()] | |
x, y, x1, y1 = box | |
label_name_detected = model.config.id2label[label.item()] | |
picsellia_label_object = labels_picsellia[label_name_detected] # label (picsellia one) | |
conf = float(score) | |
rectangles.append((x, y, x1 - x, y1 - y, picsellia_label_object, conf)) | |
experiment.add_evaluation(asset, rectangles=rectangles) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment