<jupyter_start><jupyter_text>Calculate detection result error (mAP) from YOLO object detection results---Last Updated 8 April 2020   --*Update as of 1 June 2021--Darkflow builds are no longer being updated and only support Tensorflow 1.x builds. As a result, this notebook and others associated with darkflow in this repo are left in their state from 8 April 2020. Functions may become deprecated or lose functionality. For updated mAP and AR with Tensorflow models, refer to [Tensorflow notebooks](https://github.com/aubricot/computer_vision_with_eol_images/blob/master/object_detection_for_image_cropping/lepidoptera/lepidoptera_train_tf2_ssd_rcnn.ipynb). For object detection with YOLO v4 in it's native state and calculation of performance metrics, see [Object Detection for Image Tagging Notebooks](https://github.com/aubricot/computer_vision_with_eol_images/tree/master/object_detection_for_image_tagging)*--   Use exported detection result coordinates from YOLO via darkflow to calculate detection error using mean Average Precision (mAP) and Intersection over Union (IoU).Code modified from the [mAP GitHub repo](https://github.com/Cartucho/mAPcreate-the-ground-truth-files).<jupyter_code># Mount google drive to import/export files
from google.colab import drive
drive.mount('/content/drive', force_remount=True)<jupyter_output><empty_output><jupyter_text>Convert test image detection results (jsons) and annotation files (xmls) to text files---<jupyter_code># Install the mAP repository to calculate error from detection results
import os
%cd drive/My Drive/fall19_smithsonian_informatics/train
if not os.path.exists("eval"):
  !mkdir eval
  %cd eval
  !git clone https://github.com/Cartucho/mAP
  %cd ../
# Move yolo detection results (jsons exported from training_yolo.ipynb) to detection-results/
%cd drive/My Drive/fall19_smithsonian_informatics/train
!mv test_images/out/* eval/mAP/input/detection-results/
!rm -rf test_images/out
# Copy image annotations (xmls formatted with ground truth bounding boxes) to ground-truth/
%cd drive/My Drive/fall19_smithsonian_informatics/train
!cp test_ann/* eval/mAP/input/ground-truth/
# Convert jsons to format needed for mAP calc
%cd eval/mAP/scripts/extra
!python convert_dr_darkflow_json.py
# Convert xmls to format needed for mAP calc
%cd eval/mAP/scripts/extra
!python convert_gt_xml.py
# Remove sample images in input/images-optional
# cd to mAP
%cd ../../
!rm -rf input/images-optional/*<jupyter_output><empty_output><jupyter_text>Calculate mAP for test images---<jupyter_code># Calculate mAP for detection results
# Output will be in mAP/results
%cd eval/mAP
!python main.py<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08292682926829269, 'fraction_numerical': 0.00900562851782364, 'mean_word_length': 5.615384615384615, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '499233', 'license': 'MIT', 'n_tokens_mistral': 834, 'n_tokens_neox': 783, 'n_words': 265, 'path': 'object_detection_for_image_cropping/archive/calculate_error_mAP.ipynb', 'repo_name': 'aubricot/computer_vision_with_eol_images', 'size': '2665'}